Skip to content

Commit 4368726

Browse files
authored
[lldb] Tweak Python interpreter workaround on macOS (#95582)
Avoid copying the Python interpreter when running in a virtual environment as it will already have its own copy of the Python interpreter. Also leave a breadcrumb that we're running with a different Python interpreter.
1 parent f6947e4 commit 4368726

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lldb/test/API/lit.cfg.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ def find_shlibpath_var():
5858
# enabled, we can't inject libraries into system binaries at all, so we need a
5959
# copy of the "real" python to work with.
6060
def find_python_interpreter():
61+
# This is only necessary when using DYLD_INSERT_LIBRARIES.
62+
if "DYLD_INSERT_LIBRARIES" not in config.environment:
63+
return None
64+
65+
# If we're running in a virtual environment, we already have a copy of the
66+
# Python executable.
67+
if "VIRTUAL_ENV" in config.environment:
68+
return None
69+
6170
# Avoid doing any work if we already copied the binary.
6271
copied_python = os.path.join(config.lldb_build_directory, "copied-python")
6372
if os.path.isfile(copied_python):
@@ -84,7 +93,7 @@ def find_python_interpreter():
8493
# RPATH and cannot be copied.
8594
try:
8695
# We don't care about the output, just make sure it runs.
87-
subprocess.check_output([copied_python, "-V"], stderr=subprocess.STDOUT)
96+
subprocess.check_call([copied_python, "-V"])
8897
except subprocess.CalledProcessError:
8998
# The copied Python didn't work. Assume we're dealing with the Python
9099
# interpreter in Xcode. Given that this is not a system binary SIP
@@ -130,8 +139,13 @@ def delete_module_cache(path):
130139
"libclang_rt.tsan_osx_dynamic.dylib"
131140
)
132141

133-
if "DYLD_INSERT_LIBRARIES" in config.environment and platform.system() == "Darwin":
134-
config.python_executable = find_python_interpreter()
142+
if platform.system() == "Darwin":
143+
python_executable = find_python_interpreter()
144+
if python_executable:
145+
lit_config.note(
146+
"Using {} instead of {}".format(python_executable, config.python_executable)
147+
)
148+
config.python_executable = python_executable
135149

136150
# Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
137151
if is_configured("shared_libs"):

0 commit comments

Comments
 (0)