run_shell doesn't pass arguments to scripts
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
When run_shell is used with a script of big size, Bazel saves the script to a file and runs it. With that, arguments of the action are not passed to the script.
### Which category does this issue belong to?
Core
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Example with the problem: https://github.com/bazelbuild/examples/pull/685
Running `bazel build shell_command:echo` produces this error:
```
ERROR: .../examples/rules/shell_command/BUILD:22:5: Action shell_command/echo.txt failed: (Exit 1): bash failed: error executing Action command (from target //shell_command:echo) /bin/bash -c bazel-out/darwin_arm64-fastbuild/bin/shell_command/echo.run_shell_0.sh '' arg
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
bazel-out/darwin_arm64-fastbuild/bin/shell_command/echo.run_shell_0.sh: line 2: $1: unbound variable
```
However, if I remove one "a" from this [line](https://github.com/styurin/examples/blob/b8b146226c5f4dcb7d3f30784fafe27d98c88152/rules/shell_command/echo.bzl#L9), the build succeeds.
### Which operating system are you running Bazel on?
MacOS
### What is the output of `bazel info release`?
release 8.1.0
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
It looks like it's related to https://github.com/bazelbuild/bazel/issues/6391, but the current issue is more generic. It reports an issue that can appear with scripts which size depends on input files: with small set of input files such actions can work fine, but fail unexpectedly when number of input files grows.
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Start with the linked bazelbuild/examples reproduction, especially rules/shell_command/echo.bzl and its BUILD target, then run `bazel build shell_command:echo` with the large and shortened script variants. Trace the `run_shell` entry point in Bazel's core action handling and identify where arguments are lost when the command is written to a script file. Done means both variants pass and a regression test covers the large-script case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100