Skip to content

[lldb] Tweak Python interpreter workaround on macOS #95582

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

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lldb/test/API/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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"):
Expand Down
Loading