bazelbuild / bazelbuild/bazel

bazel run fails on long argument list

Open
#27,528 7 comments 0 reactions 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

When I run `git ls-files | xargs bazel run //:my_script` in a large repo, Bazel errors with:
```
FATAL: execv of '/bin/bash' failed: (error: 7): Argument list too long
```
This happens with both `py_binary` and `sh_binary` on a minimal script. It only seems to happen on Linux, not MacOS.

The only workaround I can see is to write a bash script that pushes arguments into a response file and invoke `bazel run //:my_script -- @args.txt`. But it would be nice to just pass the arguments without a wrapper bash 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.

```py
genrule(
name = "foo_src",
outs = ["foo.sh"],
cmd = """echo 'echo $$#; SUM=0; for arg in "$$@"; do SUM=$$((SUM + $${#arg})); done; echo $$SUM' > $@""",
)

sh_binary(
name = "foo",
srcs = ["foo_src"],
)
```

```shell
git clone git@github.com:bazelbuild/bazel /tmp/bazel
git -C /tmp/bazel ls-files | xargs bazel run //:foo --
```

### Which operating system are you running Bazel on?

Rocky 9 + Centos 7

### What is the output of `bazel info release`?

8.4.2

### 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?

No

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported `bazel run //:foo --` command from the minimal `genrule` and `sh_binary` example on Linux, comparing it with MacOS behavior. Trace the `bazel run` argument-handling entry point and add or locate coverage for a long argument list; done means `py_binary` and `sh_binary` accept the arguments without a wrapper script.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, shell
Domain
build-system, cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.