bazel-contrib / bazel-contrib/bazel-lib
[Bug]: expand_template should pass data into runfiles for executable outputs
- Dominant language
- Starlark
- Stars
- 182
- Forks
- 134
- Avg merge
- 1d 46m
- Merged PRs (30d)
- 1
Description
### What happened?
When using `expand_template` to write an executable script, files passed in `data` are not made available to the script in its runfiles. This is contrary to how data should behave according to https://bazel.build/reference/be/common-definitions#typical.data
The result is running the generated executable output of a call to `expand_template` will fail if it attempts to use any files passed in data.
As a workaround, I am running the output executable with `sh_binary` and passing in dependencies to the data attribute of that rule.
### Version
Development (host) and target OS/architectures: Mac OS 12.6.7 / arm64
Output of `bazel --version`: 6.3.1
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: v1.34.5 / 09b51a9957adc56c905a2c980d6eb06f04beb1d85c665b467f659871403cf423
Language(s) and/or frameworks involved:
### How to reproduce
As an example, given the following directory structure:
```shell
- expand-template-example
∟ BUILD
∟ file.txt
∟ test.sh.tmpl
```
Where `BUILD` contains the following:
```skylark
file = "file.txt"
expand_template(
name = "bin-tmpl",
out = "bin",
template = "test.sh.tmpl",
is_executable = True,
data = [file],
substitutions = {},
)
```
When running `bazel run expand-template-example:bin`, `file.txt` is not available to the script in its runfiles.
### Any other information?
_No response_
Contributor guide
Research direction
Start with the expand_template entry point and reproduce the issue using the BUILD file, file.txt, and test.sh.tmpl example. Run bazel run expand-template-example:bin and verify that data files such as file.txt are available to the generated executable in its runfiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100