[Lldb-commits] [lldb] [lldb] Tweak Python interpreter workaround on macOS (PR #95582)

via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 14 11:44:41 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/95582.diff


1 Files Affected:

- (modified) lldb/test/API/lit.cfg.py (+17-3) 


``````````diff
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"):

``````````

</details>


https://github.com/llvm/llvm-project/pull/95582


More information about the lldb-commits mailing list