Allowing outputs and targets to mask source files leads to confusing behaviour with `glob()`. Should this be disallowed?
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
Thread on bazelbuild slack: https://bazelbuild.slack.com/archives/CA31HN1T3/p1761023024622639
I was surprised to learn today that source files and output files are allowed to have the same name. I discovered this while trying to understand why a target was depending on another target, despite only depending on source files via `glob([...])`. This was happening because the package had a source file and a generated file that shared the same name. When this happens, the generated file is preferred.
Simple repro:
```
$ echo source file > hello.txt
$ cat > BUILD.bazel
genrule(
name = "gen_hello",
outs = ["hello.txt"],
cmd = "echo 'generated file' > $@"
)
genrule(
name = "cat",
srcs = glob(["*.txt"]),
outs = ["cat.txt"],
cmd = "cat $(SRCS) > $@",
)
$ bazel build :cat &> /dev/null && cat bazel-bin/cat.txt
generated file
```
This also happens if you have a target named `:hello.txt`.
This is confusing because the user definitely meant to pass the *source file* as an input to the `:cat` target, not the generated file.
Should this be an error? Perhaps this could be introduced with One More Flag, e.g. `--[no]incompatible_disallow_source_file_masking`
### Which category does this issue belong to?
Core
Contributor guide
Research direction
Start with the BUILD.bazel reproduction and run `bazel build :cat` to confirm how `glob(["*.txt"])` resolves the source and generated files. The issue does not name an implementation entry point or test; done would require a decided policy for source-file masking, including whether an incompatible flag and corresponding validation are needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100