bazel-contrib / bazel-contrib/bazel-lib
[Bug]: run_binary fails to correctly quote make variable expansion
- Dominant language
- Starlark
- Stars
- 182
- Forks
- 134
- Avg merge
- 1d 46m
- Merged PRs (30d)
- 1
Description
### What happened?
When using a `$(locations)` expansion run_binary is placing extra quotes and mis-grouping.
```
filegroup(
name = "src",
srcs = ["src1", "src2", "src3"]
)
run_binary(
...
args = [
"--inputs \"$(locations :src)\"",
],
...
)
```
Results in a command that's quoted as:
```
cmd --inputs '"src1' src2 src3"'
^-- this quote misplaced
```
Using no quotes (`"--inputs $(locations :src)",`) results in a quote-less expansion:
```
cmd --inputs src1 src2 src3
```
### Version
Development (host) and target OS/architectures: MacOS / x86_64
Output of `bazel --version`: bazel 6.4.0
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: 2.0.1
Language(s) and/or frameworks involved:
### How to reproduce
```shell
(see above)
```
### Any other information?
Using bazel_skylib's run_binary results in slightly different behavior where the entire option is quoted, the commands render as:
```
cmd '--inputs src1 src2 src3'
```
Or appropriately quoted if the `$(locations)` expansion is available.
I'm attempting to migrate away from a genrule that uses `$(SRCS)`, an ideal fix would make SRCS available or allow for more advanced argument generation (I'm calling a Python CLI that uses click and would prefer being able to generate `cmd --input src1 --input src2 --input src3`).
Contributor guide
Research direction
Start with the run_binary argument expansion and quoting behavior described in the reproduction, then compare it with bazel_skylib's run_binary and genrule's $(SRCS) handling. Check how quoted and unquoted $(locations :src) values are grouped, and consider the requested repeated --input form. Done means the resulting command preserves the intended groups without misplaced or missing quotes.
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
- 35/100