[Lldb-commits] [lldb] 4368726 - [lldb] Tweak Python interpreter workaround on macOS (#95582)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 14 11:52:30 PDT 2024
Author: Jonas Devlieghere
Date: 2024-06-14T11:52:27-07:00
New Revision: 436872693a8a57487bf4510437183878d1e35cfb
URL: https://github.com/llvm/llvm-project/commit/436872693a8a57487bf4510437183878d1e35cfb
DIFF: https://github.com/llvm/llvm-project/commit/436872693a8a57487bf4510437183878d1e35cfb.diff
LOG: [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.
Added:
Modified:
lldb/test/API/lit.cfg.py
Removed:
################################################################################
diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py
index d934349fe3ca3..1e99c8cb95d16 100644
--- a/lldb/test/API/lit.cfg.py
+++ b/lldb/test/API/lit.cfg.py
@@ -58,6 +58,15 @@ def find_shlibpath_var():
# enabled, we can't inject libraries into system binaries at all, so we need a
# copy of the "real" python to work with.
def find_python_interpreter():
+ # This is only necessary when using DYLD_INSERT_LIBRARIES.
+ if "DYLD_INSERT_LIBRARIES" not in config.environment:
+ return None
+
+ # If we're running in a virtual environment, we already have a copy of the
+ # Python executable.
+ if "VIRTUAL_ENV" in config.environment:
+ return None
+
# Avoid doing any work if we already copied the binary.
copied_python = os.path.join(config.lldb_build_directory, "copied-python")
if os.path.isfile(copied_python):
@@ -84,7 +93,7 @@ def find_python_interpreter():
# RPATH and cannot be copied.
try:
# We don't care about the output, just make sure it runs.
- subprocess.check_output([copied_python, "-V"], stderr=subprocess.STDOUT)
+ subprocess.check_call([copied_python, "-V"])
except subprocess.CalledProcessError:
# The copied Python didn't work. Assume we're dealing with the Python
# interpreter in Xcode. Given that this is not a system binary SIP
@@ -130,8 +139,13 @@ def delete_module_cache(path):
"libclang_rt.tsan_osx_dynamic.dylib"
)
-if "DYLD_INSERT_LIBRARIES" in config.environment and platform.system() == "Darwin":
- config.python_executable = find_python_interpreter()
+if platform.system() == "Darwin":
+ python_executable = find_python_interpreter()
+ if python_executable:
+ lit_config.note(
+ "Using {} instead of {}".format(python_executable, config.python_executable)
+ )
+ config.python_executable = python_executable
# Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
if is_configured("shared_libs"):
More information about the lldb-commits
mailing list