From e4bced940f8ff45bfdf2f8910b0825df8353df8b Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Wed, 2 Oct 2024 10:29:51 +0200 Subject: [PATCH 1/4] chore(bazel): Output the registry's URL with each error message The `MultiBazelModuleRegistryService` tries several Bazel registries one after each other in order to query the `metadata.json` and the `source.json` of a module. If this information cannot be resolved, the server collates all the error messages and outputs them. To facilitate the analysis of the logs, each error message is now prefixed with the URL of the registry that created it. The URL property is now provided by each Bazel registry service. This required making `RemoteBazelModuleRegistryService.kt` a proper class that delegates the module lookups to a Retrofit client. Signed-off-by: Nicolas Nobelis --- .../main/kotlin/BazelModuleRegistryService.kt | 5 +++ .../kotlin/LocalBazelModuleRegistryService.kt | 9 ++-- .../RemoteBazelModuleRegistryService.kt | 35 +++++++--------- .../kotlin/RetrofitRegistryServiceClient.kt | 42 +++++++++++++++++++ .../CompositeBazelModuleRegistryService.kt | 2 + .../kotlin/MultiBazelModuleRegistryService.kt | 22 +++++++--- .../MultiBazelModuleRegistryServiceTest.kt | 13 ++++++ 7 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 clients/bazel-module-registry/src/main/kotlin/RetrofitRegistryServiceClient.kt diff --git a/clients/bazel-module-registry/src/main/kotlin/BazelModuleRegistryService.kt b/clients/bazel-module-registry/src/main/kotlin/BazelModuleRegistryService.kt index 4a43d01933aa..2c61b15b6aa6 100644 --- a/clients/bazel-module-registry/src/main/kotlin/BazelModuleRegistryService.kt +++ b/clients/bazel-module-registry/src/main/kotlin/BazelModuleRegistryService.kt @@ -40,6 +40,11 @@ internal val JSON = Json { * A Bazel registry which is either local or remote. */ interface BazelModuleRegistryService { + /** + * The URLs of this registry service. + */ + val urls: List + /** * Retrieve the metadata for a module. */ diff --git a/clients/bazel-module-registry/src/main/kotlin/LocalBazelModuleRegistryService.kt b/clients/bazel-module-registry/src/main/kotlin/LocalBazelModuleRegistryService.kt index fdf54b881dd2..57fe34b60f6f 100644 --- a/clients/bazel-module-registry/src/main/kotlin/LocalBazelModuleRegistryService.kt +++ b/clients/bazel-module-registry/src/main/kotlin/LocalBazelModuleRegistryService.kt @@ -33,9 +33,10 @@ const val METADATA_JSON = "metadata.json" const val SOURCE_JSON = "source.json" /** - * A Bazel registry which is located on the local file system. + * A Bazel registry for the workspace [directory] which is located on the local file system. It is configured as [url] + * in the '.bazelrc' file. */ -class LocalBazelModuleRegistryService(directory: File) : BazelModuleRegistryService { +class LocalBazelModuleRegistryService(url: String, directory: File) : BazelModuleRegistryService { companion object { /** A prefix for URLs pointing to local files. */ private const val FILE_URL_PREFIX = "file://" @@ -53,7 +54,7 @@ class LocalBazelModuleRegistryService(directory: File) : BazelModuleRegistryServ .replace(WORKSPACE_PLACEHOLDER, projectDir.absolutePath) logger.info { "Creating local Bazel module registry at '$directory'." } - LocalBazelModuleRegistryService(File(directory)) + LocalBazelModuleRegistryService(url, File(directory)) } } @@ -74,6 +75,8 @@ class LocalBazelModuleRegistryService(directory: File) : BazelModuleRegistryServ moduleDirectory = registryFile.resolveSibling(BAZEL_MODULES_DIR) } + override val urls: List = listOf(url) + override suspend fun getModuleMetadata(name: String): ModuleMetadata { val metadataJson = moduleDirectory.resolve(name).resolve(METADATA_JSON) require(metadataJson.isFile) diff --git a/clients/bazel-module-registry/src/main/kotlin/RemoteBazelModuleRegistryService.kt b/clients/bazel-module-registry/src/main/kotlin/RemoteBazelModuleRegistryService.kt index cf197554a5a9..11a2ea56122a 100644 --- a/clients/bazel-module-registry/src/main/kotlin/RemoteBazelModuleRegistryService.kt +++ b/clients/bazel-module-registry/src/main/kotlin/RemoteBazelModuleRegistryService.kt @@ -26,8 +26,6 @@ import org.apache.logging.log4j.kotlin.logger import retrofit2.Retrofit import retrofit2.converter.kotlinx.serialization.asConverterFactory -import retrofit2.http.GET -import retrofit2.http.Path /** * The client uses the Bazel Central Registry by default. @@ -35,10 +33,14 @@ import retrofit2.http.Path const val DEFAULT_URL = "https://bcr.bazel.build" /** - * Interface for a Bazel Module Registry, based on the directory structure of https://bcr.bazel.build/ and the Git - * repository it is based on (https://github.com/bazelbuild/bazel-central-registry/). + * A remote Bazel Module Registry service based on the directory structure of https://bcr.bazel.build/ and the Git + * repository it is based on (https://github.com/bazelbuild/bazel-central-registry/). It uses [client] to send HTTP + * request to the registry at [baseUrl]. */ -interface RemoteBazelModuleRegistryService : BazelModuleRegistryService { +class RemoteBazelModuleRegistryService( + private val client: RetrofitRegistryServiceClient, + baseUrl: String +) : BazelModuleRegistryService { companion object { /** * Create a Bazel Module Registry client instance for communicating with a server running at the given [url], @@ -58,24 +60,15 @@ interface RemoteBazelModuleRegistryService : BazelModuleRegistryService { .addConverterFactory(JSON.asConverterFactory(contentType)) .build() - return retrofit.create(RemoteBazelModuleRegistryService::class.java) + val retrofitClient = retrofit.create(RetrofitRegistryServiceClient::class.java) + return RemoteBazelModuleRegistryService(retrofitClient, baseUrl) } } - /** - * Retrieve the metadata for a module. - * E.g. https://bcr.bazel.build/modules/glog/metadata.json. - */ - @GET("modules/{name}/metadata.json") - override suspend fun getModuleMetadata(@Path("name") name: String): ModuleMetadata + override val urls: List = listOf(baseUrl) - /** - * Retrieve information about the source code for a specific version of a module. - * E.g. https://bcr.bazel.build/modules/glog/0.5.0/source.json. - */ - @GET("modules/{name}/{version}/source.json") - override suspend fun getModuleSourceInfo( - @Path("name") name: String, - @Path("version") version: String - ): ModuleSourceInfo + override suspend fun getModuleMetadata(name: String): ModuleMetadata = client.getModuleMetadata(name) + + override suspend fun getModuleSourceInfo(name: String, version: String): ModuleSourceInfo = + client.getModuleSourceInfo(name, version) } diff --git a/clients/bazel-module-registry/src/main/kotlin/RetrofitRegistryServiceClient.kt b/clients/bazel-module-registry/src/main/kotlin/RetrofitRegistryServiceClient.kt new file mode 100644 index 000000000000..b89e69f0d698 --- /dev/null +++ b/clients/bazel-module-registry/src/main/kotlin/RetrofitRegistryServiceClient.kt @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 The ORT Project Authors (see ) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +package org.ossreviewtoolkit.clients.bazelmoduleregistry + +import retrofit2.http.GET +import retrofit2.http.Path + +/** + * A Retrofit client for remote bazel module registries. + */ +interface RetrofitRegistryServiceClient { + /** + * Retrieve the metadata for a module. + * E.g. https://bcr.bazel.build/modules/glog/metadata.json. + */ + @GET("modules/{name}/metadata.json") + suspend fun getModuleMetadata(@Path("name") name: String): ModuleMetadata + + /** + * Retrieve information about the source code for a specific version of a module. + * E.g. https://bcr.bazel.build/modules/glog/0.5.0/source.json. + */ + @GET("modules/{name}/{version}/source.json") + suspend fun getModuleSourceInfo(@Path("name") name: String, @Path("version") version: String): ModuleSourceInfo +} diff --git a/plugins/package-managers/bazel/src/main/kotlin/CompositeBazelModuleRegistryService.kt b/plugins/package-managers/bazel/src/main/kotlin/CompositeBazelModuleRegistryService.kt index 20232dd028d6..e67b4d9db27f 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/CompositeBazelModuleRegistryService.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/CompositeBazelModuleRegistryService.kt @@ -72,6 +72,8 @@ internal class CompositeBazelModuleRegistryService( } } + override val urls = packagesPerRegistry.keys.flatMap { it.urls } + override suspend fun getModuleMetadata(name: String): ModuleMetadata { val registry = packagesPerRegistry.entries.find { name in it.value } ?: throw IllegalArgumentException("No registry found for package '$name'.") diff --git a/plugins/package-managers/bazel/src/main/kotlin/MultiBazelModuleRegistryService.kt b/plugins/package-managers/bazel/src/main/kotlin/MultiBazelModuleRegistryService.kt index fda9c42a6a5b..4f121faa7f11 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/MultiBazelModuleRegistryService.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/MultiBazelModuleRegistryService.kt @@ -21,6 +21,8 @@ package org.ossreviewtoolkit.plugins.packagemanagers.bazel import java.io.File +import org.apache.logging.log4j.kotlin.logger + import org.ossreviewtoolkit.clients.bazelmoduleregistry.BazelModuleRegistryService import org.ossreviewtoolkit.clients.bazelmoduleregistry.DEFAULT_URL import org.ossreviewtoolkit.clients.bazelmoduleregistry.LocalBazelModuleRegistryService @@ -50,6 +52,8 @@ internal class MultiBazelModuleRegistryService( // Add the default Bazel registry as a fallback. val registryUrls = (urls + DEFAULT_URL).distinctBy { it.removeSuffix("/") } + logger.info { "Creating a multi Bazel module registry:" } + val registryServices = registryUrls.mapTo(mutableListOf()) { url -> LocalBazelModuleRegistryService.create(url, projectDir) ?: RemoteBazelModuleRegistryService.create(url) @@ -61,12 +65,14 @@ internal class MultiBazelModuleRegistryService( /** * Return an exception with a message that combines the messages of all [Throwable]s in this list. */ - private fun List.combinedException(caption: String): Throwable = + private fun List.combinedException(caption: String): Throwable = IllegalArgumentException( - "$caption:\n${joinToString("\n") { it.message.orEmpty() }}" + "$caption:\n${joinToString("\n")}" ) } + override val urls = registryServices.flatMap { it.urls } + override suspend fun getModuleMetadata(name: String): ModuleMetadata = queryRegistryServices( errorMessage = { "Failed to query metadata for package '$name'" }, @@ -88,20 +94,26 @@ internal class MultiBazelModuleRegistryService( errorMessage: () -> String, query: suspend (BazelModuleRegistryService) -> T ): T { - val failures = mutableListOf() + val failures = mutableListOf() tailrec suspend fun queryServices(itServices: Iterator): T? = if (!itServices.hasNext()) { null } else { - val triedResult = runCatching { query(itServices.next()) } + val nextRegistry = itServices.next() + val triedResult = runCatching { query(nextRegistry) } val result = triedResult.getOrNull() // The Elvis operator does not work here because of the tailrec modifier. if (result != null) { result } else { - triedResult.exceptionOrNull()?.let(failures::add) + triedResult.exceptionOrNull()?.let { + failures += "${nextRegistry.urls.joinToString()}: ${ + it.message.orEmpty().ifEmpty { "" } + }" + } + queryServices(itServices) } } diff --git a/plugins/package-managers/bazel/src/test/kotlin/MultiBazelModuleRegistryServiceTest.kt b/plugins/package-managers/bazel/src/test/kotlin/MultiBazelModuleRegistryServiceTest.kt index ec53d158ce2e..17a271aa37f1 100644 --- a/plugins/package-managers/bazel/src/test/kotlin/MultiBazelModuleRegistryServiceTest.kt +++ b/plugins/package-managers/bazel/src/test/kotlin/MultiBazelModuleRegistryServiceTest.kt @@ -137,6 +137,10 @@ private val registryUrls = listOf( private class MockRegistryServices( val registryServices: List ) { + init { + prepareGetUrls() + } + companion object { /** An exception thrown by mock registries to simulate a failure. */ private val testException = Exception("Test exception: Registry invocation failed.") @@ -190,6 +194,15 @@ private class MockRegistryServices( } } + /** + * Prepare the mock registries to return a URL if requested. + */ + fun prepareGetUrls() { + registryServices.forEach { service -> + every { service.urls } returns listOf("") + } + } + /** * Prepare the mock registries to expect a query for module metadata and to fail with a test exception. */ From 0ac906a5c7039903f120a59d93cb04e270b5161f Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Fri, 4 Oct 2024 15:00:41 +0200 Subject: [PATCH 2/4] feat(bazel): Support `github` in the module metadata JSON file This is currently unused (as the whole `Maintainer` class) but it contains information that could be relevant in the future. See [1]. [1]: https://github.com/bazelbuild/bazel-central-registry/blob/main/metadata.schema.json Signed-off-by: Nicolas Nobelis --- clients/bazel-module-registry/src/main/kotlin/Model.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/clients/bazel-module-registry/src/main/kotlin/Model.kt b/clients/bazel-module-registry/src/main/kotlin/Model.kt index 52cbbd9b9a94..fd528ccaee01 100644 --- a/clients/bazel-module-registry/src/main/kotlin/Model.kt +++ b/clients/bazel-module-registry/src/main/kotlin/Model.kt @@ -44,6 +44,7 @@ data class ModuleMetadata( @Serializable data class Maintainer( val email: String? = null, + val github: String? = null, val name: String? = null ) } From 3ad055a7bd67b83a0cac18674af7deca7d219556 Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Fri, 4 Oct 2024 15:18:12 +0200 Subject: [PATCH 3/4] fix(bazel): Disable the wrapper script only for the `--version` call The wrapper script can be relevant by defining e.g. a specific '.bazelrc' depending on the value of an environment variable. This is a fixup for 310470d305eeadc40308b3335ecf4dd66475f88e. Signed-off-by: Nicolas Nobelis --- plugins/package-managers/bazel/src/main/kotlin/Bazel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt index 41c1cfb81d56..7ddc8afdc260 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt @@ -110,9 +110,9 @@ class Bazel( super.run( args = args, workingDir = workingDir, - // Disable the optional wrapper script under `tools/bazel`, to ensure the --version option works. + // Disable the optional wrapper script under `tools/bazel` only for the "--version" call. environment = environment + mapOf( - "BAZELISK_SKIP_WRAPPER" to "true", + "BAZELISK_SKIP_WRAPPER" to "${args[0] == getVersionArguments()}", "USE_BAZEL_FALLBACK_VERSION" to BAZEL_FALLBACK_VERSION ) ) From e4046fe7869343532f22a2db3d37ffe38e01457f Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Fri, 4 Oct 2024 15:26:32 +0200 Subject: [PATCH 4/4] test(bazel): Add a missing test for when there is no lockfile This is a test for 1045f89d527918fc51b4e8f033debd775635eee7. Signed-off-by: Nicolas Nobelis --- .../bazel-expected-output-no-lock-file.yml | 80 +++++++++++++++++++ .../synthetic/bazel-no-lock-file/.bazelrc | 2 + .../bazel-no-lock-file/.bazelversion | 1 + .../synthetic/bazel-no-lock-file/MODULE.bazel | 1 + .../synthetic/bazel-no-lock-file/lib/BUILD | 7 ++ .../bazel-no-lock-file/lib/cookie-jar.cc | 5 ++ .../bazel-no-lock-file/lib/cookie-jar.h | 6 ++ .../synthetic/bazel-no-lock-file/main/BUILD | 11 +++ .../synthetic/bazel-no-lock-file/main/main.cc | 10 +++ .../bazel/src/funTest/kotlin/BazelFunTest.kt | 11 +++ 10 files changed, 134 insertions(+) create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-no-lock-file.yml create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelrc create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelversion create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/MODULE.bazel create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/BUILD create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.cc create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.h create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/BUILD create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/main.cc diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-no-lock-file.yml b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-no-lock-file.yml new file mode 100644 index 000000000000..0b5f7aa72718 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-no-lock-file.yml @@ -0,0 +1,80 @@ +--- +project: + id: "Bazel::plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/MODULE.bazel:" + definition_file_path: "" + declared_licenses: [] + declared_licenses_processed: {} + vcs: + type: "Git" + url: "" + revision: "" + path: "" + vcs_processed: + type: "Git" + url: "" + revision: "" + path: "" + homepage_url: "" + scopes: + - name: "dev" + dependencies: [] + - name: "main" + dependencies: + - id: "Bazel::glog:0.5.0" + linkage: "STATIC" + dependencies: + - id: "Bazel::gflags:2.2.2" + linkage: "STATIC" +packages: +- id: "Bazel::gflags:2.2.2" + purl: "pkg:generic/gflags@2.2.2" + declared_licenses: [] + declared_licenses_processed: {} + description: "" + homepage_url: "https://gflags.github.io/gflags/" + binary_artifact: + url: "" + hash: + value: "" + algorithm: "" + source_artifact: + url: "https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz" + hash: + value: "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf" + algorithm: "SHA-256" + vcs: + type: "Git" + url: "https://github.com/gflags/gflags" + revision: "" + path: "" + vcs_processed: + type: "Git" + url: "https://github.com/gflags/gflags.git" + revision: "" + path: "" +- id: "Bazel::glog:0.5.0" + purl: "pkg:generic/glog@0.5.0" + declared_licenses: [] + declared_licenses_processed: {} + description: "" + homepage_url: "https://github.com/google/glog" + binary_artifact: + url: "" + hash: + value: "" + algorithm: "" + source_artifact: + url: "https://github.com/google/glog/archive/refs/tags/v0.5.0.tar.gz" + hash: + value: "eede71f28371bf39aa69b45de23b329d37214016e2055269b3b5e7cfd40b59f5" + algorithm: "SHA-256" + vcs: + type: "Git" + url: "https://github.com/google/glog" + revision: "" + path: "" + vcs_processed: + type: "Git" + url: "https://github.com/google/glog.git" + revision: "" + path: "" diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelrc b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelrc new file mode 100644 index 000000000000..7d3a276c78b4 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelrc @@ -0,0 +1,2 @@ +common --lockfile_mode=off + diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelversion b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelversion new file mode 100644 index 000000000000..9fe9ff9d996b --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/.bazelversion @@ -0,0 +1 @@ +7.0.1 diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/MODULE.bazel new file mode 100644 index 000000000000..f8970e2bc510 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/MODULE.bazel @@ -0,0 +1 @@ +bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog") diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/BUILD b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/BUILD new file mode 100644 index 000000000000..5790445652ed --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/BUILD @@ -0,0 +1,7 @@ +cc_library( + name = "cookie-jar", + srcs = ["cookie-jar.cc"], + hdrs = ["cookie-jar.h"], + visibility = ["//main:__pkg__", "//test:__pkg__"], +) + diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.cc b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.cc new file mode 100644 index 000000000000..119b4473f8de --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.cc @@ -0,0 +1,5 @@ +#include "lib/cookie-jar.h" + +int grab_cookies() { + return 42; +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.h b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.h new file mode 100644 index 000000000000..e1c18fb7d7ed --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/lib/cookie-jar.h @@ -0,0 +1,6 @@ +#ifndef LIB_COOKIE_JAR_H_ +#define LIB_COOKIE_JAR_H_ + +int grab_cookies(); + +#endif diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/BUILD b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/BUILD new file mode 100644 index 000000000000..6d051d9aad4a --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/BUILD @@ -0,0 +1,11 @@ +cc_binary( + name = "main", + srcs = [ + "main.cc", + ], + deps = [ + "//lib:cookie-jar", + "@com_github_google_glog//:glog", + ], +) + diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/main.cc b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/main.cc new file mode 100644 index 000000000000..ce356335facc --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/main/main.cc @@ -0,0 +1,10 @@ +#include "lib/cookie-jar.h" +#include + +int main(int argc, char* argv[]) { + google::InitGoogleLogging(argv[0]); + + int num_cookies = grab_cookies(); + LOG(INFO) << "Found " << num_cookies << " cookies"; +} + diff --git a/plugins/package-managers/bazel/src/funTest/kotlin/BazelFunTest.kt b/plugins/package-managers/bazel/src/funTest/kotlin/BazelFunTest.kt index 6fe618574b78..de393839fa0f 100644 --- a/plugins/package-managers/bazel/src/funTest/kotlin/BazelFunTest.kt +++ b/plugins/package-managers/bazel/src/funTest/kotlin/BazelFunTest.kt @@ -93,4 +93,15 @@ class BazelFunTest : StringSpec({ result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile) } + + "Dependencies are detected correctly even if no lock file is present and its generation is disabled" { + val definitionFile = getAssetFile("projects/synthetic/bazel-no-lock-file/MODULE.bazel") + val expectedResultFile = getAssetFile( + "projects/synthetic/bazel-expected-output-no-lock-file.yml" + ) + + val result = create("Bazel").resolveSingleProject(definitionFile) + + result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile) + } })