diff --git a/lldb/cmake/modules/FindPythonAndSwig.cmake b/lldb/cmake/modules/FindPythonAndSwig.cmake index a3fcf8a5ccbba..2c8d86b54aab2 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 d825ad330ff4f..e16b7dfe3197d 100644 --- a/lldb/test/API/lit.cfg.py +++ b/lldb/test/API/lit.cfg.py @@ -367,3 +367,10 @@ def delete_module_cache(path): # Propagate XDG_CACHE_HOME if "XDG_CACHE_HOME" in os.environ: config.environment["XDG_CACHE_HOME"] = os.environ["XDG_CACHE_HOME"] + +# 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 420e0aa4751b1..5b64ccc0375cc 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 = "@Python3_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/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py index 480cebc5f0926..9928d0b58d58d 100644 --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -224,3 +224,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", "")) +)