File tree Expand file tree Collapse file tree 4 files changed +45
-6
lines changed Expand file tree Collapse file tree 4 files changed +45
-6
lines changed Original file line number Diff line number Diff line change @@ -71,14 +71,15 @@ if [ -e "$self_dir/pyvenv.cfg" ] || [ -e "$self_dir/../pyvenv.cfg" ]; then
71
71
if [ ! -e " $PYTHON_BIN " ]; then
72
72
die " ERROR: Python interpreter does not exist: $PYTHON_BIN "
73
73
fi
74
- # PYTHONEXECUTABLE is also used because `exec -a` doesn't fully trick the
75
- # pyenv wrappers.
74
+ # PYTHONEXECUTABLE is also used because switching argv0 doesn't fully trick
75
+ # the pyenv wrappers.
76
76
# NOTE: The PYTHONEXECUTABLE envvar only works for non-Mac starting in Python 3.11
77
77
export PYTHONEXECUTABLE=" $venv_bin "
78
- # Python looks at argv[0] to determine sys.executable, so use exec -a
79
- # to make it think it's the venv's binary, not the actual one invoked.
80
- # NOTE: exec -a isn't strictly posix-compatible, but very widespread
81
- exec -a " $venv_bin " " $PYTHON_BIN " " $@ "
78
+ # Python looks at argv[0] to determine sys.executable, so set that to the venv
79
+ # binary, not the actual one invoked.
80
+ # NOTE: exec -a would be simpler, but isn't posix-compatible, and dash shell
81
+ # (Ubuntu/debian default) doesn't support it; see #3009.
82
+ exec sh -c " $PYTHON_BIN \$ @" " $venv_bin " " $@ "
82
83
else
83
84
exec " $PYTHON_BIN " " $@ "
84
85
fi
Original file line number Diff line number Diff line change @@ -40,3 +40,26 @@ py_reconfig_test(
40
40
tags = ["no-remote-exec" ],
41
41
deps = ["//python/runfiles" ],
42
42
)
43
+
44
+ py_reconfig_test (
45
+ name = "bootstrap_script_test" ,
46
+ srcs = ["toolchain_runs_test.py" ],
47
+ bootstrap_impl = "script" ,
48
+ data = [
49
+ "//tests/support:current_build_settings" ,
50
+ ],
51
+ extra_toolchains = [
52
+ "//python/runtime_env_toolchains:all" ,
53
+ # Necessary for RBE CI
54
+ CC_TOOLCHAIN ,
55
+ ],
56
+ main = "toolchain_runs_test.py" ,
57
+ # With bootstrap=script, the build version must match the runtime version
58
+ # because the venv has the version in the lib/site-packages dir name.
59
+ python_version = PYTHON_VERSION ,
60
+ # Our RBE has Python 3.6, which is too old for the language features
61
+ # we use now. Using the runtime-env toolchain on RBE is pretty
62
+ # questionable anyways.
63
+ tags = ["no-remote-exec" ],
64
+ deps = ["//python/runfiles" ],
65
+ )
Original file line number Diff line number Diff line change 1
1
import json
2
2
import pathlib
3
3
import platform
4
+ import sys
4
5
import unittest
5
6
6
7
from python .runfiles import runfiles
@@ -23,6 +24,14 @@ def test_ran(self):
23
24
settings ["interpreter" ]["short_path" ],
24
25
)
25
26
27
+ if settings ["bootstrap_impl" ] == "script" :
28
+ # Verify we're running in a venv
29
+ self .assertNotEqual (sys .prefix , sys .base_prefix )
30
+ # .venv/ occurs for a build-time venv.
31
+ # For a runtime created venv, it goes into a temp dir, so
32
+ # look for the /bin/ dir as an indicator.
33
+ self .assertRegex (sys .executable , r"[.]venv/|/bin/" )
34
+
26
35
27
36
if __name__ == "__main__" :
28
37
unittest .main ()
Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ def _current_build_settings_impl(ctx):
135
135
ctx .actions .write (
136
136
output = info ,
137
137
content = json .encode ({
138
+ "bootstrap_impl" : ctx .attr ._bootstrap_impl_flag [config_common .FeatureFlagInfo ].value ,
138
139
"interpreter" : {
139
140
"short_path" : runtime .interpreter .short_path if runtime .interpreter else None ,
140
141
},
@@ -153,6 +154,11 @@ Writes information about the current build config to JSON for testing.
153
154
This is so tests can verify information about the build config used for them.
154
155
""" ,
155
156
implementation = _current_build_settings_impl ,
157
+ attrs = {
158
+ "_bootstrap_impl_flag" : attr .label (
159
+ default = "//python/config_settings:bootstrap_impl" ,
160
+ ),
161
+ },
156
162
toolchains = [
157
163
TARGET_TOOLCHAIN_TYPE ,
158
164
],
You can’t perform that action at this time.
0 commit comments