Skip to content

Commit 0868359

Browse files
authored
fix: preserve arguments with spaces (#4026)
The runtime environment launcher collapsed interpreter arguments into one shell word. It now forwards each argument without reparsing it, preserving the original argument boundaries. This includes a regression test for interpreter arguments containing spaces. Related: bazelbuild/bazel#30644
1 parent b401c75 commit 0868359

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

python/private/runtime_env_toolchain_interpreter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ if [ -e "$self_dir/pyvenv.cfg" ] || [ -e "$self_dir/../pyvenv.cfg" ]; then
7777
# binary, not the actual one invoked.
7878
# NOTE: exec -a would be simpler, but isn't posix-compatible, and dash shell
7979
# (Ubuntu/debian default) doesn't support it; see #3009.
80-
exec sh -c "$PYTHON_BIN \$@" "$venv_bin" "$@"
80+
exec sh -c 'exec "$@"' "$venv_bin" "$PYTHON_BIN" "$@"
8181
else
8282
exec "$PYTHON_BIN" "$@"
8383
fi

tests/runtime_env_toolchain/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ py_reconfig_test(
4444
py_reconfig_test(
4545
name = "bootstrap_script_test",
4646
srcs = ["toolchain_runs_test.py"],
47+
args = ["'argument with spaces'"],
4748
bootstrap_impl = "script",
4849
data = [
4950
"//tests/support:current_build_settings",

tests/runtime_env_toolchain/toolchain_runs_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_ran(self):
2525
)
2626

2727
if settings["bootstrap_impl"] == "script":
28+
self.assertEqual(sys.argv[1:], ["argument with spaces"])
2829
# Verify we're running in a venv
2930
self.assertNotEqual(sys.prefix, sys.base_prefix)
3031
# .venv/ occurs for a build-time venv.
@@ -34,4 +35,4 @@ def test_ran(self):
3435

3536

3637
if __name__ == "__main__":
37-
unittest.main()
38+
unittest.main(argv=sys.argv[:1])

0 commit comments

Comments
 (0)