From ad35a393c182b36734a07ca8059bbc336356dbd6 Mon Sep 17 00:00:00 2001 From: Oliver Heger Date: Mon, 5 Aug 2024 09:56:34 +0200 Subject: [PATCH] feat(bazel): Support multiple registry services For Bazel < 7.2.0, if the `.bazelrc` file lists multiple registries, use all of them to query package metadata. Fixes #8801. Signed-off-by: Oliver Heger --- .../bazel-expected-output-local-registry.yml | 32 +++++++++---------- .../bazel/src/main/kotlin/Bazel.kt | 5 +-- .../bazel/src/main/kotlin/BazelModel.kt | 7 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-local-registry.yml b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-local-registry.yml index f878d5ab86ab6..bea3bf16b6556 100644 --- a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-local-registry.yml +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-expected-output-local-registry.yml @@ -33,25 +33,25 @@ packages: declared_licenses: [] declared_licenses_processed: {} description: "" - homepage_url: "" + homepage_url: "https://gflags.github.io/gflags/" binary_artifact: url: "" hash: value: "" algorithm: "" source_artifact: - url: "" + url: "https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz" hash: - value: "" - algorithm: "" + value: "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf" + algorithm: "SHA-256" vcs: - type: "" - url: "" + type: "Git" + url: "https://github.com/gflags/gflags" revision: "" path: "" vcs_processed: - type: "" - url: "" + type: "Git" + url: "https://github.com/gflags/gflags.git" revision: "" path: "" - id: "Bazel::glog:0.5.0" @@ -59,25 +59,25 @@ packages: declared_licenses: [] declared_licenses_processed: {} description: "" - homepage_url: "" + homepage_url: "https://github.com/google/glog" binary_artifact: url: "" hash: value: "" algorithm: "" source_artifact: - url: "" + url: "https://github.com/google/glog/archive/refs/tags/v0.5.0.tar.gz" hash: - value: "" - algorithm: "" + value: "eede71f28371bf39aa69b45de23b329d37214016e2055269b3b5e7cfd40b59f5" + algorithm: "SHA-256" vcs: - type: "" - url: "" + type: "Git" + url: "https://github.com/google/glog" revision: "" path: "" vcs_processed: - type: "" - url: "" + type: "Git" + url: "https://github.com/google/glog.git" revision: "" path: "" - id: "Bazel::test_module:0.0.1" diff --git a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt index be1e0b09ca7cc..44adb2ab289de 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt @@ -143,10 +143,7 @@ class Bazel( private fun determineRegistry(lockfile: Lockfile, projectDir: File): BazelModuleRegistryService { // Bazel version < 7.2.0. if (lockfile.flags != null) { - val registryUrl = lockfile.registryUrl() - - return LocalBazelModuleRegistryService.createForLocalUrl(registryUrl, projectDir) - ?: RemoteBazelModuleRegistryService.create(registryUrl) + return MultiBazelModuleRegistryService.create(lockfile.registryUrls(), projectDir) } // Bazel version >= 7.2.0. diff --git a/plugins/package-managers/bazel/src/main/kotlin/BazelModel.kt b/plugins/package-managers/bazel/src/main/kotlin/BazelModel.kt index 0b3ea2ef8ebca..da57616fe3028 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/BazelModel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/BazelModel.kt @@ -43,8 +43,11 @@ internal data class Lockfile( } } - // TODO Support multiple registries. - fun registryUrl(): String? = flags?.cmdRegistries?.getOrElse(0) { null } + /** + * Return a collection with the URLs of the service registries defined for this project in case the model for + * Bazel < 7.2.0 is used. + */ + fun registryUrls(): Collection = flags?.cmdRegistries.orEmpty() } @Serializable