From 27a86cbf899521d63e512df296133a0a60fc62b7 Mon Sep 17 00:00:00 2001 From: Buzz Lightyear Date: Tue, 8 Oct 2024 16:56:45 -0400 Subject: [PATCH 1/4] Don't hard fail if there's a second request to bazelize the same Go module --- internal/bzlmod/go_deps.bzl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index eaf17f96f..87c00e4ac 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -592,6 +592,7 @@ def _go_deps_impl(module_ctx): ), ) + repos_processed = {} for path, module in module_resolutions.items(): if hasattr(module, "module_name"): # Do not create a go_repository for a Go module provided by a bazel_dep. @@ -602,6 +603,10 @@ def _go_deps_impl(module_ctx): # Do not create a go_repository for a dep shared with the non-isolated instance of # go_deps. continue + if module.repo_name in repos_processed: + continue + + repos_processed[module.repo_name] = True go_repository_args = { "name": module.repo_name, # Compared to the name attribute, the content of this attribute does not go through repo From e36eae9ad3130dd33dd5e46d3c4555eb019a2ff0 Mon Sep 17 00:00:00 2001 From: Buzz-Lightyear Date: Thu, 10 Oct 2024 12:00:05 -0400 Subject: [PATCH 2/4] Failing with a better error message --- internal/bzlmod/go_deps.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index 87c00e4ac..54425b259 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -604,9 +604,9 @@ def _go_deps_impl(module_ctx): # go_deps. continue if module.repo_name in repos_processed: - continue + fail("Go module {prev_path} and {path} will resolve to the same Bazel repo name: {name}. While Go allows modules to only differ in case, this isn't supported in Gazelle (yet). Please ensure you only use one of these modules in your go.mod(s)") - repos_processed[module.repo_name] = True + repos_processed[module.repo_name] = path go_repository_args = { "name": module.repo_name, # Compared to the name attribute, the content of this attribute does not go through repo From 63ee5e2f57537fef1401693a6c8b17f4ad1d7e77 Mon Sep 17 00:00:00 2001 From: Buzz-Lightyear Date: Thu, 10 Oct 2024 15:56:21 -0400 Subject: [PATCH 3/4] Formatting the error string correctly --- internal/bzlmod/go_deps.bzl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index 54425b259..8184dcd23 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -604,7 +604,11 @@ def _go_deps_impl(module_ctx): # go_deps. continue if module.repo_name in repos_processed: - fail("Go module {prev_path} and {path} will resolve to the same Bazel repo name: {name}. While Go allows modules to only differ in case, this isn't supported in Gazelle (yet). Please ensure you only use one of these modules in your go.mod(s)") + fail("Go module {prev_path} and {path} will resolve to the same Bazel repo name: {name}. While Go allows modules to only differ in case, this isn't supported in Gazelle (yet). Please ensure you only use one of these modules in your go.mod(s)".format( + prev_path=repos_processed[module.repo_name], + path=path, + name=module.repo_name + )) repos_processed[module.repo_name] = path go_repository_args = { From 2dd2f39f9f6654d8286be3d942d9c409ffb87f47 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 11 Oct 2024 20:01:42 +0200 Subject: [PATCH 4/4] Fixes for buildifier --- internal/bzlmod/go_deps.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index 8184dcd23..fac95de7a 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -605,9 +605,9 @@ def _go_deps_impl(module_ctx): continue if module.repo_name in repos_processed: fail("Go module {prev_path} and {path} will resolve to the same Bazel repo name: {name}. While Go allows modules to only differ in case, this isn't supported in Gazelle (yet). Please ensure you only use one of these modules in your go.mod(s)".format( - prev_path=repos_processed[module.repo_name], - path=path, - name=module.repo_name + prev_path = repos_processed[module.repo_name], + path = path, + name = module.repo_name, )) repos_processed[module.repo_name] = path