`--incompatible_locations_prefers_executable`
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 72
Description
### Motivation
Many rules (e.g. Python and Shell) that build an executable provide more than one file in their default outputs for technical reasons (e.g. symlinks to source files). This made it impossible to get the path to the executable via location expansion since `$(execpath :x)` will fail and `$(execpaths :x)` expands to multiple files, one of which is the executable.
In https://github.com/bazelbuild/bazel/commit/457d248218540b0ae93d6454fa8a95ccad877063, this situation was improved by letting the singular forms of location expansion always prefer the executable if it would otherwise fail due to multiple files. While this by itself is a backwards compatible change, it wasn't possible to do this without also changing the behavior of the plural forms.
### Description
`$(locations :x)` now expands to the executable of a target `:x` if it provides one and the number of files provided by it is not one. Previously, it would have expanded to the list of these files.
### Incompatible Flag
`--incompatible_locations_prefers_executable`
### Migration Guide
Usage of the plural forms should be rare, especially for executable rules. The native location expansion has always had this behavior, only the ongoing Starlarkification and increased usage of `ctx.expand_location`'s extra target argument have made this change necessary. If needed, users can write a custom rule that accepts a rule and returns the space-separated list of output files via a custom Make variable.
### In which Bazel LTS version will this incompatible change be enabled?
Bazel 9
### Additional Context
_No response_
### TODO List
_No response_
Contributor guide
Research direction
Start with commit 457d248218540b0ae93d6454fa8a95ccad877063 and review Bazel's location expansion behavior, including ctx.expand_location and its extra target argument. Confirm that $(locations :x) prefers a target's executable when it provides one and multiple files, with the incompatible flag governing the change; verify the behavior against existing tests if found.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100