bazelbuild / 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.19k stars 378 forks source link

Using the repo name rules_go removes proto embed from all go_library rules #1823

Open jschaf opened 4 months ago

jschaf commented 4 months ago

What version of gazelle are you using?

0.37.0

What version of rules_go are you using?

0.48.0

What version of Bazel are you using?

7.2.0rc3

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

Yes

What operating system and processor architecture are you using?

macOS arm64

What did you do?

  1. I manually replaced all instances of io_bazel_rules_go to rules_go in my repo.

  2. I removed the repo_name from the rules_go bazel dep in MODULE.bazel.

# Before
bazel_dep(name = "rules_go", version = "0.48.0", repo_name = "io_bazel_rules_go")

# After
bazel_dep(name = "rules_go", version = "0.48.0")

What did you expect to see?

Running gazelle should do nothing.

What did you see instead?

Gazelle removed the go_library.embed for every go_proto_library embedded into a go_library.

Before

go_library(
    name = "api",
    srcs = [], 
    embed = [":api_go_proto"],
    importpath = "github.com/arryved/simc/erp/api",
    visibility = ["//visibility:public"],
)

After

go_library(
    name = "api",
    srcs = [], 
    importpath = "github.com/arryved/simc/erp/api",
    visibility = ["//visibility:public"],
)

Debugging

The problem might be that `io_bazel_rules_go is hardcoded: https://github.com/bazelbuild/bazel-gazelle/blob/7d10bf7befce477f518056cfc502939000bea3fa/config/constants.go#L22

fmeum commented 4 months ago

Could you send a PR that adds a reproducer for this to some subdirectory of https://github.com/bazelbuild/bazel-gazelle/tree/master/tests/bcr/go_mod/proto, which uses a non-io_bazel_rules_go repo name? Then I could work on a fix. I have trouble reproducing this right now.