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

map_kind directive is not applied on empty rules #1440

Closed
ghost opened this issue Feb 10, 2023 · 0 comments · Fixed by #1441
Closed

map_kind directive is not applied on empty rules #1440

ghost opened this issue Feb 10, 2023 · 0 comments · Fixed by #1441

Comments

@ghost
Copy link

ghost commented Feb 10, 2023

What version of gazelle are you using?

0.29.0

What version of rules_go are you using?

v0.38.1

What version of Bazel are you using?

6.0.0

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

Yes.

What operating system and processor architecture are you using?

Linux/amd64

What did you do?

We use map_kind directive to replace go_binary and go_library kind rules (with different names).
When all Go files are removed from the package and we execute gazelle, go_* rules are not removed from the BUILD file.

Example:

load("//:my.bzl", "my_go_binary", "my_go_library")

# gazelle:go_naming_convention import

# gazelle:map_kind go_binary my_go_binary //:my.bzl
# gazelle:map_kind go_library my_go_library //:my.bzl

my_go_library(
    name = "foo_lib"",
    srcs = ["main.go"],
    importpath = "example.com/foo",
    visibility = ["//visibility:private"],
)

my_go_binary(
    name = "foo",
    embed = [":foo_lib"],
    visibility = ["//visibility:public"],
)

What did you expect to see?

# gazelle:go_naming_convention import

# gazelle:map_kind go_binary my_go_binary //:my.bzl
# gazelle:map_kind go_library my_go_library //:my.bzl

What did you see instead?

load("//:my.bzl", "my_go_binary", "my_go_library")

# gazelle:go_naming_convention import

# gazelle:map_kind go_binary my_go_binary //:my.bzl
# gazelle:map_kind go_library my_go_library //:my.bzl

my_go_library(
    name = "foo_lib"",
    srcs = ["main.go"],
    importpath = "example.com/foo",
    visibility = ["//visibility:private"],
)

my_go_binary(
    name = "foo",
    embed = [":foo_lib"],
    visibility = ["//visibility:public"],
)
fmeum pushed a commit that referenced this issue Sep 13, 2023
* fix: language/go: fileContainsGoBinary() doesn't interprete correctly KindMap

With this directive `# gazelle:map_kind OLD NEW NEW_LOAD`,
c.KindMap should be equal:

  "OLD": {
    FromKind: "OLD",
    KindName: "NEW",
    KindLoad: "NEW_LOAD",
  }

`fileContainsGoBinary()` should search directly the mapping
for the `go_binary` kind rule.

Issue #1440

* fix: map_kind should also be applied on empty rules

If `map_kind` is not applied on empty rules returned
by GenerateRules(), all mapped rules can't be removed
from the BUILD file.

Close #1440
jeromep-stripe pushed a commit to jeromep-stripe/bazel-gazelle that referenced this issue Mar 22, 2024
* fix: language/go: fileContainsGoBinary() doesn't interprete correctly KindMap

With this directive `# gazelle:map_kind OLD NEW NEW_LOAD`,
c.KindMap should be equal:

  "OLD": {
    FromKind: "OLD",
    KindName: "NEW",
    KindLoad: "NEW_LOAD",
  }

`fileContainsGoBinary()` should search directly the mapping
for the `go_binary` kind rule.

Issue bazel-contrib#1440

* fix: map_kind should also be applied on empty rules

If `map_kind` is not applied on empty rules returned
by GenerateRules(), all mapped rules can't be removed
from the BUILD file.

Close bazel-contrib#1440
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

Successfully merging a pull request may close this issue.

0 participants