[lldb] make lit use the same Python executable for building and testing (#143756)

When testing LLDB, we want to make sure to use the same Python as the
one we used to build it.

This patch uses the CMake variable `Python3_ROOT_DIR` to add the correct
Python to the `PATH` in LLDB lit tests, in order to ensure of this.

Please see https://github.com/swiftlang/swift/pull/82063 for the
original issue.

This is a continuation of https://github.com/swiftlang/swift/pull/82063.
This commit is contained in:
Charles Zablit
2025-06-17 17:52:03 +01:00
committed by GitHub
parent 5baf351ba8
commit 556e69b7f4
4 changed files with 14 additions and 1 deletions

View File

@@ -6,7 +6,9 @@
macro(FindPython3)
# Use PYTHON_HOME as a hint to find Python 3.
set(Python3_ROOT_DIR "${PYTHON_HOME}")
if(NOT Python3_ROOT_DIR)
set(Python3_ROOT_DIR "${PYTHON_HOME}")
endif()
find_package(Python3 COMPONENTS Interpreter Development)
if(Python3_FOUND AND Python3_Interpreter_FOUND)

View File

@@ -349,3 +349,10 @@ if platform.system() == "Windows":
for v in ["SystemDrive"]:
if v in os.environ:
config.environment[v] = os.environ[v]
# Some steps required to initialize the tests dynamically link with python.dll
# and need to know the location of the Python libraries. This ensures that we
# use the same version of Python that was used to build lldb to run our tests.
config.environment["PATH"] = os.path.pathsep.join(
(config.python_root_dir, config.environment.get("PATH", ""))
)

View File

@@ -20,6 +20,7 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
config.python_executable = "@LLDB_PYTHON_API_TEST_EXECUTABLE@"
config.python_root_dir = "@Python3_ROOT_DIR@"
config.lua_executable = "@LUA_EXECUTABLE@"
config.lldb_lua_cpath = "@LLDB_LUA_CPATH@"
config.lua_test_entry = "TestLuaAPI.py"

View File

@@ -203,3 +203,6 @@ if platform.system() == "Darwin":
# location of the Python libraries. This ensures that we use the same
# version of Python that was used to build lldb to run our tests.
config.environment["PYTHONHOME"] = config.python_root_dir
config.environment["PATH"] = os.path.pathsep.join(
(config.python_root_dir, config.environment.get("PATH", ""))
)