bazel-contrib / bazel-contrib/rules_go
Incorrect root for generated embedsrcs in package subdirectory
- 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?
v0.28.0
### What version of gazelle are you using?
v0.23.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?
Linux x86-64
### Any other potentially useful information about your toolchain?
None
### What did you do?
Using a generated file in embedsrcs that is in a package subdirectory ends up in the incorrect location for `go:embed` compared to similar non-generated source files.
e.g.
```
package/ <- some package root in a project
BUILD
some_dir/
some_file <- static source file
some_generated_file <- this file is generated by another rule
app.go
```
### What did you expect to see?
In BUILD, `embedsrcs` is declared that depends on the `some_file` and the rule that produces `some_generated_file`. Then in `app.go` I do `//go:embed *` into an `embed.FS`. I expect to see that the `embed.FS` contains the following paths:
```
some_file
some_generated_file
```
### What did you see instead?
The `embed.FS` has the generated file at the incorrect location:
```
some_file
some_dir/some_generated_file
```
This appears to to be due to this section of code: https://github.com/bazelbuild/rules_go/blob/5de7041f23e3f6d9cabfbd8b9033b49aeb9677a9/go/tools/builders/compilepkg.go#L327-L356
You are adding the outpath on line 336, which means the more specific generated root is ignored by the dupe detection.
Contributor guide
Research direction
Start with the embedsrcs handling in go/tools/builders/compilepkg.go, especially the referenced lines 327-356 and the outpath handling near line 336. Reproduce the reported package/subdirectory layout using go:embed and compare generated versus static file paths in the resulting embed.FS. Done means generated files appear at the same relative paths as equivalent non-generated source files.
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
- Mostly clear
- Newbie friendliness
- 48/100