bazel-contrib / bazel-contrib/rules_go
go_path: re-building `go_path` target does not clear stale/non-existent files from the built artifact in `link` mode
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
### What version of rules_go are you using?
0.29
### What version of gazelle are you using?
0.24.0
### What version of Bazel are you using?
4.2.1
### Does this issue reproduce with the latest releases of all the above?
Yes
### What operating system and processor architecture are you using?
macOS ARM
### Any other potentially useful information about your toolchain?
N/A
### What did you do?
See the [minimal repro](https://github.com/rickystewart/repro/tree/reprogopath) in the `reprogopath` branch (commit `2ef35dce723a6c09e9aa7cdf861283f4e3748bdb`). The workspace has two files, `file1.go` and `file2.go`, both of which constitute a `go_library` called `repro`, with a `go_path` target that captures `repro`.
To repro:
1. `bazel build :all` to build the library and its `go_path` -- this creates a `go_path` containing `file1.go` and `file2.go` as expected.
2. `rm file2.go && bazel run :gazelle` to remove `file2.go` from the `srcs` on the `go_library`.
3. `bazel build :all` *again* and observe that despite `file2.go` no longer existing and being removed from the `srcs`, `file2.go` is still in the built `go_path`
On my machine, those steps looked like this:
```
repro$ bazel build :all
INFO: Analyzed 2 targets (1 packages loaded, 4 targets configured).
INFO: Found 2 targets...
INFO: Elapsed time: 0.219s, Critical Path: 0.09s
INFO: 4 processes: 2 internal, 2 darwin-sandbox.
INFO: Build completed successfully, 4 total actions
repro$ find bazel-bin/go_path
bazel-bin/go_path
bazel-bin/go_path/src
bazel-bin/go_path/src/github.com
bazel-bin/go_path/src/github.com/rickystewart
bazel-bin/go_path/src/github.com/rickystewart/repro
bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go
bazel-bin/go_path/src/github.com/rickystewart/repro/file1.go
repro$ ls -lah bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go
lrwxr-xr-x 1 ricky wheel 32B Jan 7 11:24 bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go -> ../../../../../../../../file2.go
repro$ cat bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go
package repro
func Function2() {}
repro$ rm file2.go
repro$ bazel run :gazelle
INFO: Analyzed target //:gazelle (9 packages loaded, 57 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
INFO: Elapsed time: 0.304s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
repro$ bazel build :all
INFO: Analyzed 2 targets (1 packages loaded, 3 targets configured).
INFO: Found 2 targets...
INFO: Elapsed time: 0.236s, Critical Path: 0.09s
INFO: 4 processes: 2 internal, 2 darwin-sandbox.
INFO: Build completed successfully, 4 total actions
repro$ find bazel-bin/go_path
bazel-bin/go_path
bazel-bin/go_path/src
bazel-bin/go_path/src/github.com
bazel-bin/go_path/src/github.com/rickystewart
bazel-bin/go_path/src/github.com/rickystewart/repro
bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go
bazel-bin/go_path/src/github.com/rickystewart/repro/file1.go
repro$ ls -lah bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go
lrwxr-xr-x 1 ricky wheel 32B Jan 7 11:24 bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go -> ../../../../../../../../file2.go
repro$ cat bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go
cat: bazel-bin/go_path/src/github.com/rickystewart/repro/file2.go: No such file or directory
```
Note that the `file2.go` symlink is untouched despite the rebuild and that symlink is broken due to the deleted file.
### What did you expect to see?
Removing `file2.go` from the `srcs` list for the `go_library` should additionally remove it from the `go_path`. The `go_path` should especially not contain any broken symlinks at any point.
### What did you see instead?
`go_path` artifact contains a broken symlink to a deleted file that is not in the `srcs` for the constituent `go_library`.
Contributor guide
Research direction
Use the linked minimal repro at commit 2ef35dce723a6c09e9aa7cdf861283f4e3748bdb and reproduce the two successive `bazel build :all` commands in link mode. Trace the `go_path` action and its handling of removed sources; done means rebuilding after Gazelle removes `file2.go` leaves no stale or broken symlink in the go_path artifact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100