Skip to content

Commit 7c6420e

Browse files
committed
[lldb/Test] Run dotest.py with the Python LLDB was built with.
The Python used to run lit can be different from the Python LLDB was build with. One scenario where this happens is when LLVM can find the Python 3 interpreter, but not the Python 3 libraries, in which case LLDB build and links against Python 3. Without this change, you end up with an ModuleNotFoundError because of the mismatch. Instead of looking at the Python interpreter that's used to run lit, lldbtest should use the interpreter that matches the Python version LLDB was build against. Differential revision: https://reviews.llvm.org/D79519
1 parent 0a52401 commit 7c6420e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lldb/test/API/lldbtest.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ def execute(self, test, litConfig):
6262
return (lit.Test.UNSUPPORTED, 'Test is unsupported')
6363

6464
testPath, testFile = os.path.split(test.getSourcePath())
65+
66+
# The Python used to run lit can be different from the Python LLDB was
67+
# build with.
68+
executable = test.config.python_executable
69+
6570
# On Windows, the system does not always correctly interpret
6671
# shebang lines. To make sure we can execute the tests, add
6772
# python exe as the first parameter of the command.
68-
cmd = [sys.executable] + self.dotest_cmd + [testPath, '-p', testFile]
73+
cmd = [executable] + self.dotest_cmd + [testPath, '-p', testFile]
6974

7075
builddir = getBuildDir(cmd)
7176
mkdir_p(builddir)
@@ -74,13 +79,13 @@ def execute(self, test, litConfig):
7479
# libraries into system binaries, but this can be worked around by
7580
# copying the binary into a different location.
7681
if 'DYLD_INSERT_LIBRARIES' in test.config.environment and \
77-
(sys.executable.startswith('/System/') or \
78-
sys.executable.startswith('/usr/bin/')):
82+
(executable.startswith('/System/') or \
83+
executable.startswith('/usr/bin/')):
7984
copied_python = os.path.join(builddir, 'copied-system-python')
8085
if not os.path.isfile(copied_python):
8186
import shutil, subprocess
8287
python = subprocess.check_output([
83-
sys.executable,
88+
executable,
8489
'-c',
8590
'import sys; print(sys.executable)'
8691
]).decode('utf-8').strip()

0 commit comments

Comments
 (0)