bazel-contrib / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.21k stars 381 forks source link

Can't resolve root module from external module #1862

Closed tokongs closed 3 months ago

tokongs commented 3 months ago

What version of gazelle are you using?

v0.38.0

What version of rules_go are you using?

v0.47.1

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?

Linux x86

What did you do?

Add a gazelle:resolve to resolve a name to a target in the local root module like so:

go_deps.gazelle_override(
  path = "cel.dev/expr",
  build_file_generation = "on",
  directives = ["gazelle:resolve proto google/rpc/status.proto @@//:googleapis_rpc_status"]
)

What did you expect to see?

I expected this to successfully resolve, as @@//... should be visible to external modules.

What did you see instead?

It did not resolve. Inspecting the generated BUILD.bazel file shows that the double @@ was replaced with a single @.

Generated BUILD.bazel:

proto_library(
    name = "expr_proto",
    srcs = [...],
    deps = [
        ...,
        "@//:googleapis_rpc_status"
    ],
)
fmeum commented 3 months ago

@tokongs Could you check whether this is fixed by https://github.com/bazelbuild/bazel-gazelle/pull/1863?

tokongs commented 3 months ago

@fmeum seems to fix the issue! I do get some other errors when overriding gazelle to your commits, but I assume those are unrelated.

ERROR: /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/rules_go~/go/platform/BUILD.bazel: no such target '@@rules_go~//go/platform:o
sx': target 'osx' not declared in package 'go/platform' defined by /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/rules_go~/go/plat
form/BUILD.bazel
ERROR: /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/rules_go~/go/platform/BUILD.bazel: no such target '@@rules_go~//go/platform:q
nx': target 'qnx' not declared in package 'go/platform' defined by /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/rules_go~/go/plat
form/BUILD.bazel
ERROR: /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/gazelle~~go_deps~com_github_prometheus_client_golang/prometheus/BUILD.bazel:3
:11: errors encountered resolving select() keys for @@gazelle~~go_deps~com_github_prometheus_client_golang//prometheus:prometheus
ERROR: /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/gazelle~~go_deps~com_github_mattn_go_colorable/BUILD.bazel:3:11: errors encou
ntered resolving select() keys for @@gazelle~~go_deps~com_github_mattn_go_colorable//:go-colorable
ERROR: /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/gazelle~~go_deps~org_golang_google_grpc/internal/syscall/BUILD.bazel:3:11: er
rors encountered resolving select() keys for @@gazelle~~go_deps~org_golang_google_grpc//internal/syscall:syscall
ERROR: /home/tokongs/.cache/bazel/_bazel_tokongs/51d0d670cf09bb319bf1151bdc73a969/external/gazelle~~go_deps~com_github_outcaste_io_ristretto/z/BUILD.bazel:3:11: errors 
encountered resolving select() keys for @@gazelle~~go_deps~com_github_outcaste_io_ristretto//z:z