bazelbuild / bazelbuild/bazel-skylib
run_binary expands $(locations …) to a single string instead of a list
- Dominant language
- Starlark
- Stars
- 444
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
Example:
WORKSPACE:
```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazel_skylib",
sha256 = "fc64d71583f383157e3e5317d24e789f942bc83c76fde7e5981cadc097a3c3cc",
strip_prefix = "bazel-skylib-1.1.1/",
urls = [
"https://github.com/bazelbuild/bazel-skylib/archive/refs/tags/1.1.1.zip", # 2021-09-27
],
)
```
BUILD:
```python
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
sh_binary(
name = "cat",
srcs = ["cat.sh"],
)
filegroup(
name = "files",
srcs = [
"a.txt",
"b.txt",
],
)
run_binary(
name = "run_cat",
srcs = [":files"],
outs = ["cat.out"],
args = [
"$(location :cat.out)",
"$(locations :files)",
],
tool = ":cat",
)
```
cat.sh:
```bash
#!/bin/bash
out="$1"
shift
cat -- "$@" > "${out:?}"
```
a.txt and b.txt are arbitrary source files.
* * *
Running `bazel build //:cat.out` will then result in an error message:
```
cat: './a.txt ./b.txt': No such file or directory
```
This is because `$(locations …)` expands to a single string.
Not sure whether this can be fixed in Skylib alone – probably needs a Bazel/Starlark change for a variant of `ctx.expand_location` that works on an `Args` object.
Contributor guide
Research direction
Reproduce the issue with the WORKSPACE and BUILD example, using `bazel build //:cat.out` and `cat.sh`. Read `run_binary.bzl` and investigate the reported `ctx.expand_location` and `Args` behavior in Bazel/Starlark. Done means `$(locations :files)` reaches `cat.sh` as separate arguments so both input files are read successfully.
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