Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Tweak Python interpreter workaround on macOS #95582

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

JDevlieghere
Copy link
Member

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Jun 14, 2024

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

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

@JDevlieghere JDevlieghere merged commit 4368726 into llvm:main Jun 14, 2024
6 of 7 checks passed
@JDevlieghere JDevlieghere deleted the rdar129847082 branch June 14, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants