Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gazelle gets confused if directories already contain both BUILD and .pb.go files #1769

Open
EdSchouten opened this issue Mar 31, 2024 · 0 comments

Comments

@EdSchouten
Copy link
Contributor

EdSchouten commented Mar 31, 2024

What version of gazelle are you using?

0.35.0

What version of rules_go are you using?

0.46.0

What version of Bazel are you using?

7.1.1

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

macOS Intel

What did you do?

git clone git@github.com:buildbarn/bb-storage.git
cd bb-storage
bazel run //:gazelle
git status

What did you expect to see?

That the Git checkout remains unmodified.

What did you see instead?

I see that Gazelle prints a whole bunch of warnings having this shape:

gazelle: rule //cmd/bb_copy:bb_copy_lib imports "github.com/buildbarn/bb-storage/pkg/proto/configuration/bb_copy" which matches multiple rules: //pkg/proto/configuration/bb_copy:buildbarn_configuration_bb_copy_go_proto and //pkg/proto/configuration/bb_copy. # gazelle:resolve may be used to disambiguate

I also see that all of my BUILD files for packages containing Protobuf files are altered to no longer depend on the go_proto_library(), but on the existing .pb.go files:

diff --git a/pkg/proto/replicator/BUILD.bazel b/pkg/proto/replicator/BUILD.bazel
index 1f327f4..99e9ed0 100644
--- a/pkg/proto/replicator/BUILD.bazel
+++ b/pkg/proto/replicator/BUILD.bazel
@@ -26,7 +26,19 @@ go_proto_library(
 
 go_library(
     name = "replicator",
-    embed = [":replicator_go_proto"],
+    srcs = [
+        "replicator.pb.go",
+        "replicator_grpc.pb.go",
+    ],
     importpath = "github.com/buildbarn/bb-storage/pkg/proto/replicator",
     visibility = ["//visibility:public"],
+    deps = [
+        "@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:execution",
+        "@org_golang_google_grpc//:go_default_library",
+        "@org_golang_google_grpc//codes",
+        "@org_golang_google_grpc//status",
+        "@org_golang_google_protobuf//reflect/protoreflect",
+        "@org_golang_google_protobuf//runtime/protoimpl",
+        "@org_golang_google_protobuf//types/known/emptypb",
+    ],
 )

Furthermore, all code that depends on these libraries have their dependencies removed.

Oddly enough, if I first remove the BUILD files belonging to the Protobuf files and then run Gazelle, everything works as expected:

rm -f $(find . -name '*.pb.go' | sed -e 's/[^/]*$/BUILD.bazel/')
bazel run //:gazelle
git status

It's really just that if both the BUILD file AND the .pb.go source files are present, that Bazel misbehaves. In my case I want to check in the resulting .pb.go files as well, so that third parties can easily depend on this repository. This did work as expected in previous versions of Bazel/Gazelle (that did not use bzlmod).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant