bazel-contrib / bazel-contrib/rules_go

gazelle deletes go_library for protos on second run when map_kind go_proto_library is used

Open
#4,204 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
762
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

0.51.0

### What version of gazelle are you using?

0.40.0

### What version of Bazel are you using?

8.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 (Ubuntu)

### Any other potentially useful information about your toolchain?

n/a

### What did you do?

I tried to use a custom `go_proto_library` macro using map kind in the root `BUILD.bazel` file:

```starlark
# gazelle:map_kind go_proto_library go_proto_library //bazel:go_proto_library.bzl
```

### What did you expect to see?

I expected to see the usual behavior of gazelle for protos, except `load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")` would be replaced by `load("//bazel:go_proto_library.bzl", "go_proto_library")`.

### What did you see instead?

When gazelle is first run, the behavior is as I would expect. When gazelle is run again, go_library entries disappear from BUILD.bazel files.

`example/proto/BUILD.bazel` after first //:gazelle run:

```starlark
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:go_proto_library.bzl", "go_proto_library")

proto_library(
name = "example_proto",
srcs = ["example.proto"],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "example_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/gonzojive/gazelle-idempotency-bug/proto/example",
proto = ":example_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "example",
embed = [":example_go_proto"],
importpath = "github.com/gonzojive/gazelle-idempotency-bug/proto/example",
visibility = ["//visibility:public"],
)
```

After second //:gazelle run:

```starlark
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:go_proto_library.bzl", "go_proto_library")

proto_library(
name = "example_proto",
srcs = ["example.proto"],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "example_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/gonzojive/gazelle-idempotency-bug/proto/example",
proto = ":example_proto",
visibility = ["//visibility:public"],
)
```

### Reproduction

I created a repo for reproducing the issue: https://github.com/gonzojive/gazelle-idempotency-bug

```shell
git clone https://github.com/gonzojive/gazelle-idempotency-bug
cd gazelle-idempotency-bug
SOURCE_REPO_PATH=$PWD go test gazelletest/gazelletest_test.go
```

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction command in gazelletest/gazelletest_test.go and inspect how the root BUILD.bazel map_kind go_proto_library directive is handled. Run the test or two consecutive Gazelle runs against the linked reproduction repository; done means the second run preserves the generated go_library and its load while using the custom macro.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.