runfiles symlink obscured
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the problem / feature request:
There seems to be a hidden requirement for `data` files, namely that the target label must not be a prefix of the runfile. If it is, we get a warning like
```
WARNING: /Users/gar/mina/ppx_optcomp/test/BUILD.bazel:21:9: runfiles symlink test/import_relativity/exit.mlh -> test/import_relativity/exit.mlh obscured by test/import_relativity -> bazel-out/darwin-fastbuild/bin/test/import_relativity
```
and failure, at least for test rules.
If I were not familiar with test rule implementation details I think this would be indecipherable. I suggest:
* document this in the [`data` attribute documentation ](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes), not just the runfiles docs.
* add a suggestion to the warning message, something like "Make sure your target name is not a prefix of a data file."
* even better, eliminate the problem - do not symlink the target label name, generate something unique.
### Feature requests: what underlying problem are you trying to solve with this feature?
Avoid surprises.
### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I have a test rule in package //test with `name="import_relativity"`, and `data=["import_relativity/entry.mlh"]`. In the rule implementation, I iterate over `ctx.files.data`, adding each to `ctx.runfiles`. What gets added is `test/import_relativity/entry.mlh`. The test fails when run with file not found for the `entry.mlh` file, plus the warning noted above. This is apparently because a symlink is created from the target label, `test/import_relativity`, which "obscures" the runfile symlink. If I change the name of the rule, e.g. to `import_relativity_test`, then the test succeeds.
### What operating system are you running Bazel on?
MacOS Catalina
### What's the output of `bazel info release`?
release 3.6.0
### Have you found anything relevant by searching the web?
No.
Contributor guide
Research direction
Reproduce the failure from the test rule in test/BUILD.bazel at the reported data attribute, using data=["import_relativity/entry.mlh"] and the rule's ctx.files.data-to-ctx.runfiles flow. Read the common data attribute documentation and runfiles documentation, then trace the warning and obscured symlink behavior. Done means the target/data naming case no longer fails, or the documented constraint and warning provide an actionable explanation.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100