From 0a4aee29aedd9079d03750c0757f4a2e93da5933 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Wed, 11 Jun 2025 18:43:13 +0100 Subject: [PATCH 1/3] [lldb] make lit use the same Python executable for building and testing --- lldb/test/Shell/lit.cfg.py | 3 +++ lldb/test/Unit/lit.cfg.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py index ab6113767187a..a48d43251c988 100644 --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -203,3 +203,6 @@ def calculate_arch_features(arch_string): # 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", "") +) diff --git a/lldb/test/Unit/lit.cfg.py b/lldb/test/Unit/lit.cfg.py index 681e3b19dce34..38ab821e5ee16 100644 --- a/lldb/test/Unit/lit.cfg.py +++ b/lldb/test/Unit/lit.cfg.py @@ -34,6 +34,9 @@ ) llvm_config.with_environment("PATH", os.path.dirname(sys.executable), append_path=True) config.environment["PYTHONHOME"] = config.python_root_dir +config.environment["PATH"] = os.path.pathsep.join( + config.python_root_dir, config.environment.get("PATH", "") +) # Enable sanitizer runtime flags. if config.llvm_use_sanitizer: From 585d6e2b1a765ab1539b5aaa820f2070bed14181 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Wed, 11 Jun 2025 20:01:52 +0100 Subject: [PATCH 2/3] fixup! [lldb] make lit use the same Python executable for building and testing --- lldb/test/Shell/lit.cfg.py | 2 +- lldb/test/Unit/lit.cfg.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py index a48d43251c988..8c9448b23c56b 100644 --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -204,5 +204,5 @@ def calculate_arch_features(arch_string): # 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", "") + (config.python_root_dir, config.environment.get("PATH", "")) ) diff --git a/lldb/test/Unit/lit.cfg.py b/lldb/test/Unit/lit.cfg.py index 38ab821e5ee16..75ed4c7186e44 100644 --- a/lldb/test/Unit/lit.cfg.py +++ b/lldb/test/Unit/lit.cfg.py @@ -35,7 +35,7 @@ llvm_config.with_environment("PATH", os.path.dirname(sys.executable), append_path=True) config.environment["PYTHONHOME"] = config.python_root_dir config.environment["PATH"] = os.path.pathsep.join( - config.python_root_dir, config.environment.get("PATH", "") + (config.python_root_dir, config.environment.get("PATH", "")) ) # Enable sanitizer runtime flags. From 7577c95295d3c61e6da413991d32ff056807bd78 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Thu, 12 Jun 2025 17:26:56 +0100 Subject: [PATCH 3/3] add python to the PATH in lldb API tests --- lldb/cmake/modules/FindPythonAndSwig.cmake | 4 +++- lldb/test/API/lit.cfg.py | 7 +++++++ lldb/test/API/lit.site.cfg.py.in | 1 + lldb/test/Unit/lit.cfg.py | 3 --- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lldb/cmake/modules/FindPythonAndSwig.cmake b/lldb/cmake/modules/FindPythonAndSwig.cmake index 1f6f553e86048..b478038f144d9 100644 --- a/lldb/cmake/modules/FindPythonAndSwig.cmake +++ b/lldb/cmake/modules/FindPythonAndSwig.cmake @@ -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) diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py index 646a446c86fdb..83713213ce1fe 100644 --- a/lldb/test/API/lit.cfg.py +++ b/lldb/test/API/lit.cfg.py @@ -349,3 +349,10 @@ def delete_module_cache(path): 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", "")) +) diff --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in index 8552d17d66631..86d58889cc4ad 100644 --- a/lldb/test/API/lit.site.cfg.py.in +++ b/lldb/test/API/lit.site.cfg.py.in @@ -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" diff --git a/lldb/test/Unit/lit.cfg.py b/lldb/test/Unit/lit.cfg.py index 75ed4c7186e44..681e3b19dce34 100644 --- a/lldb/test/Unit/lit.cfg.py +++ b/lldb/test/Unit/lit.cfg.py @@ -34,9 +34,6 @@ ) llvm_config.with_environment("PATH", os.path.dirname(sys.executable), append_path=True) config.environment["PYTHONHOME"] = config.python_root_dir -config.environment["PATH"] = os.path.pathsep.join( - (config.python_root_dir, config.environment.get("PATH", "")) -) # Enable sanitizer runtime flags. if config.llvm_use_sanitizer: