Skip to content

[lldb] make lit use the same PYTHONHOME for building and testing #143183

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

Conversation

charles-zablit
Copy link
Contributor

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

This patch used the CMake variable Python3_ROOT_DIR to set the PYTHONHOME env variable in LLDB lit tests, in order to ensure of this.

Please see swiftlang/swift#82063 for the original issue.

@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-lldb

Author: Charles Zablit (charles-zablit)

Changes

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

This patch used the CMake variable Python3_ROOT_DIR to set the PYTHONHOME env variable in LLDB lit tests, in order to ensure of this.

Please see swiftlang/swift#82063 for the original issue.


Full diff: https://github.com/llvm/llvm-project/pull/143183.diff

5 Files Affected:

  • (modified) compiler-rt/test/lit.common.configured.in (+1)
  • (modified) lldb/test/Shell/lit.cfg.py (+5)
  • (modified) lldb/test/Shell/lit.site.cfg.py.in (+1)
  • (modified) lldb/test/Unit/lit.cfg.py (+1)
  • (modified) lldb/test/Unit/lit.site.cfg.py.in (+1)
diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in
index 04d1a4df5a54f..8ca47a8df5aed 100644
--- a/compiler-rt/test/lit.common.configured.in
+++ b/compiler-rt/test/lit.common.configured.in
@@ -25,6 +25,7 @@ set_default("gold_executable", "@GOLD_EXECUTABLE@")
 set_default("clang", "@COMPILER_RT_RESOLVED_TEST_COMPILER@")
 set_default("compiler_id", "@COMPILER_RT_TEST_COMPILER_ID@")
 set_default("python_executable", "@Python3_EXECUTABLE@")
+set_default("python_root_dir", "@Python3_ROOT_DIR@")
 set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
 set_default("compiler_rt_intercept_libdispatch", @COMPILER_RT_INTERCEPT_LIBDISPATCH_PYBOOL@)
 set_default("compiler_rt_output_dir", "@COMPILER_RT_RESOLVED_OUTPUT_DIR@")
diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py
index 193639667db5b..ab6113767187a 100644
--- a/lldb/test/Shell/lit.cfg.py
+++ b/lldb/test/Shell/lit.cfg.py
@@ -198,3 +198,8 @@ def calculate_arch_features(arch_string):
             config.available_features.add("ld_new-bug")
     except:
         pass
+
+# Some shell 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["PYTHONHOME"] = config.python_root_dir
diff --git a/lldb/test/Shell/lit.site.cfg.py.in b/lldb/test/Shell/lit.site.cfg.py.in
index 7e03938b12b23..5be5359217769 100644
--- a/lldb/test/Shell/lit.site.cfg.py.in
+++ b/lldb/test/Shell/lit.site.cfg.py.in
@@ -21,6 +21,7 @@ config.enable_remote = not @LLDB_TEST_SHELL_DISABLE_REMOTE@
 config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
+config.python_root_dir = "@Python3_ROOT_DIR@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
diff --git a/lldb/test/Unit/lit.cfg.py b/lldb/test/Unit/lit.cfg.py
index 8d711f17d858e..681e3b19dce34 100644
--- a/lldb/test/Unit/lit.cfg.py
+++ b/lldb/test/Unit/lit.cfg.py
@@ -33,6 +33,7 @@
     ]
 )
 llvm_config.with_environment("PATH", os.path.dirname(sys.executable), append_path=True)
+config.environment["PYTHONHOME"] = config.python_root_dir
 
 # Enable sanitizer runtime flags.
 if config.llvm_use_sanitizer:
diff --git a/lldb/test/Unit/lit.site.cfg.py.in b/lldb/test/Unit/lit.site.cfg.py.in
index 2748be229cf1c..fb94797bcd7de 100644
--- a/lldb/test/Unit/lit.site.cfg.py.in
+++ b/lldb/test/Unit/lit.site.cfg.py.in
@@ -11,6 +11,7 @@ config.lldb_src_root = "@LLDB_SOURCE_DIR@"
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.python_executable = "@Python3_EXECUTABLE@"
+config.python_root_dir = "@Python3_ROOT_DIR@"
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Michael137
Copy link
Member

Merging based on Jonas's approval (@charles-zablit doesn't have commit access yet)

@Michael137 Michael137 merged commit b62488f into llvm:main Jun 9, 2025
10 checks passed
@Michael137 Michael137 deleted the charles-zablit/lldb/use-common-pythonhome branch June 9, 2025 09:20
charles-zablit added a commit to swiftlang/llvm-project that referenced this pull request Jun 9, 2025
…m#143183)

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

This patch used the CMake variable `Python3_ROOT_DIR` to set the
`PYTHONHOME` env variable in LLDB lit tests, in order to ensure of this.

Please see swiftlang/swift#82063 for the
original issue.
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
…m#143183)

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

This patch used the CMake variable `Python3_ROOT_DIR` to set the
`PYTHONHOME` env variable in LLDB lit tests, in order to ensure of this.

Please see swiftlang/swift#82063 for the
original issue.
Michael137 pushed a commit that referenced this pull request Jun 12, 2025
In #143183 was mistakenly added
a default value to `python_root_dir` in lit tests of compiler-rt.

This is unused by the lit tests of compiler-rt, as it was meant to be
used by `lldb`.

This patch removes this change.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 12, 2025
…ts (#143738)

In llvm/llvm-project#143183 was mistakenly added
a default value to `python_root_dir` in lit tests of compiler-rt.

This is unused by the lit tests of compiler-rt, as it was meant to be
used by `lldb`.

This patch removes this change.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
…m#143183)

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

This patch used the CMake variable `Python3_ROOT_DIR` to set the
`PYTHONHOME` env variable in LLDB lit tests, in order to ensure of this.

Please see swiftlang/swift#82063 for the
original issue.
charles-zablit added a commit to swiftlang/llvm-project that referenced this pull request Jun 12, 2025
…3738)

In llvm#143183 was mistakenly added
a default value to `python_root_dir` in lit tests of compiler-rt.

This is unused by the lit tests of compiler-rt, as it was meant to be
used by `lldb`.

This patch removes this change.
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
…m#143183)

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

This patch used the CMake variable `Python3_ROOT_DIR` to set the
`PYTHONHOME` env variable in LLDB lit tests, in order to ensure of this.

Please see swiftlang/swift#82063 for the
original issue.
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
…3738)

In llvm#143183 was mistakenly added
a default value to `python_root_dir` in lit tests of compiler-rt.

This is unused by the lit tests of compiler-rt, as it was meant to be
used by `lldb`.

This patch removes this change.
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request Jun 17, 2025
…on-pythonhome-to-6.2

🍒 [lldb] make lit use the same PYTHONHOME for building and testing (llvm#143183)
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
…3738)

In llvm#143183 was mistakenly added
a default value to `python_root_dir` in lit tests of compiler-rt.

This is unused by the lit tests of compiler-rt, as it was meant to be
used by `lldb`.

This patch removes this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants