cncf/xds

Gazelle: no such package '@com_github_cncf_xds_go//udpa/annotations': BUILD file not found in directory 'udpa/annotations'

Opened this issue · 7 comments

We are using gazelle to generate bazel bindings to the golang code. The version v0.0.0-20240905190251-b4127c9b8d78 fails with:

bazel run //:{redacted}
INFO: Repository org_golang_google_protobuf instantiated at:
...
INFO: repository @org_golang_google_protobuf' used the following cache hits instead of downloading the corresponding file.
 * Hash '39a8bbfadaa3e71f9d7741d67ee60d69db40422dc531708a777259e594d923e3' for https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.33.0.zip
If the definition of 'repository @org_golang_google_protobuf' was updated, verify that the hashes were also updated.
ERROR: /{redacted}/external/com_github_envoyproxy_go_control_plane/envoy/service/auth/v3/BUILD.bazel:3:11: no such package '@com_github_cncf_xds_go//udpa/annotations': BUILD file not found in directory 'udpa/annotations' of external repository @com_github_cncf_xds_go. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_envoyproxy_go_control_plane//envoy/service/auth/v3:auth'
ERROR: Analysis of target '//:{redacted}' failed; build aborted:
INFO: Elapsed time: 2.685s
INFO: 0 processes.
ERROR: Build failed. Not running target
FAILED: Build did NOT complete successfully (87 packages loaded, 4389 targets configured)

The version github.com/cncf/xds/go@v0.0.0-20240318125728-8a4994d93e50 works ok. It's regression in the newer versions.

My hypothesis about the root reason: @keith added in #96 a /go/BUILD file.
The file makes gazelle consider this whole subtree as a proper BAZEL project... so suspends gazelle for generating the proper BUILD files in the sub tree... But they are missing there... i.e. there are no proper BUILD files, e.g. in: https://github.com/cncf/xds/tree/main/go/udpa/annotations.

Can we make it either proper bazel project with gazelle generated BUILD targets...
or rollback the BUILD file in the subtree at all ?

You can currently work around this issue by adding this to your MODULE.bazel:

go_deps.gazelle_override(
    build_file_generation = "on",
    path = "github.com/cncf/xds/go",
)

But I agree: removing go/BUILD would be preferable, because that would make it work out of the box.

cc @keith @mmorel-35 - should #96 be reverted, or should the /go/BUILD file be removed or fixed?

I’d say, don’t revert it. Just remove go/BUILD.

Oh wait. That does require us to change some of the //go:go.* references in MODULE.bazel to //:go/go.*.

@EdSchouten I'd like to apply your workaround, but I'm using WORKSPACE instead of Bzlmod. Is there an equivalent way to alter a dep?

@EdSchouten I'd like to apply your workaround, but I'm using WORKSPACE instead of Bzlmod. Is there an equivalent way to alter a dep?

Search for the go_repository(name = "com_github_cncf_xds_go") and add build_file_generation = "on" to that...?

Ah, thank you!! That totally works