Skip to content

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

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 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 swiftlang/swift#82063 for the original issue.

This is a continuation of swiftlang/swift#82063.

@llvmbot
Copy link
Member

llvmbot commented Jun 11, 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 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 swiftlang/swift#82063 for the original issue.

This is a continuation of swiftlang/swift#82063.


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

2 Files Affected:

  • (modified) lldb/test/Shell/lit.cfg.py (+3)
  • (modified) lldb/test/Unit/lit.cfg.py (+3)
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:

@JDevlieghere
Copy link
Member

Makes sense for the shell test (we could also make it an alias and resolve the path ourselves, that would be a bit more reliable) but why is this necessary for the unit tests?

@labath
Copy link
Collaborator

labath commented Jun 12, 2025

+1 for %python

@charles-zablit
Copy link
Contributor Author

charles-zablit commented Jun 12, 2025

On Windows, lldb looks for python39.dll when running the tests. Therefore, even if we make the path an alias, lldb will still not be able to resolve python39.dll if it's not in the PATH env variable.

but why is this necessary for the unit tests?

It is not, after testing it does not impact the tests. However, python39.dll being in the PATH does impact the API tests, as dotest will try to run lldb before starting the test suite. If the DLL is not in the path, the lldb -P invocation fails.

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.

Thanks for explaining. LGTM.

@JDevlieghere JDevlieghere merged commit 556e69b into llvm:main Jun 17, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants