Skip to content

fix java.io.IOException: ... Argument list too long during pex generation. #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions py/private/py_pex_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,18 @@ def _py_python_pex_impl(ctx):
)
args.add(output, format = "--output-file=%s")

# The argument list can become quite long which can throw java.io.IOException Argument list too long.
# Instead write the args to a file and read that file at runtime
args_file = ctx.actions.declare_file("args.txt")
ctx.actions.write(
output = args_file,
content = args,
)

ctx.actions.run(
executable = ctx.executable._pex,
inputs = runfiles.files,
arguments = [args],
inputs = runfiles.files.to_list() + [args_file],
arguments = [args_file.path],
outputs = [output],
mnemonic = "PyPex",
progress_message = "Building PEX binary %{label}",
Expand Down
5 changes: 4 additions & 1 deletion py/tools/pex/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def __call__(self, parser, namespace, value, option_str=None):
action="append",
)

options = parser.parse_args(args = sys.argv[1:])
options = None
with open(sys.argv[1], "r") as args_file:
args = [arg[1:-1] for arg in args_file.read().splitlines()]
options = parser.parse_args(args)

# Monkey patch bootstrap template to inject some templated environment variables.
# Unfortunately we can't use `preamble` feature because it runs before any initialization code.
Expand Down