Skip to content

Commit 1e55916

Browse files
authored
[Python3] Use correct Python version for LLDB-related tests (#33181)
* Use the correct Python executable to match LLDB The linux-fatal-backtrace script needs to run with an LLDB module loaded into Python. This in turn requires that the test be run with the exact same Python version as was used by LLDB (not just the same Python module directory). This can get confused on systems with multiple versions of Python installed. This replaces `lldb-python-path` (the Python module directory path) with `lldb-python` (which is the correct Python version run with the LLDB path). This should ensure that this test is always run with the same Python version and module that LLDB used. * Use consistent braces for the lldb-python substitution * Use os.path utilities to dissect paths * Allow `python3` as a path identifier Previous code required a decimal point before it would recognize a path component as a Python version identifier, so it would accept `python2.7` but not `python3`.
1 parent facabd8 commit 1e55916

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

test/Runtime/linux-fatal-backtrace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift %s -o %t/a.out
3-
// RUN: %{python} %S/../Inputs/not.py "%target-run %t/a.out" 2>&1 | PYTHONPATH=%lldb-python-path %{python} %utils/symbolicate-linux-fatal %t/a.out - | %{python} %utils/backtrace-check -u
3+
// RUN: %{python} %S/../Inputs/not.py "%target-run %t/a.out" 2>&1 | %{lldb-python} %utils/symbolicate-linux-fatal %t/a.out - | %{python} %utils/backtrace-check -u
44
// REQUIRES: executable_test
55
// REQUIRES: OS=linux-gnu
66
// REQUIRES: lldb

test/lit.cfg

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def get_lldb_python_path(lldb_build_root):
104104
return None
105105
return subprocess.check_output([lldb_path, "-P"]).rstrip().decode('utf-8')
106106

107+
def get_lldb_python_from_path(lldb_path):
108+
(head, tail) = os.path.split(lldb_path)
109+
if tail and re.match('^python[23][.0-9]*$', tail):
110+
return tail
111+
if head and head != lldb_path:
112+
return get_lldb_python_from_path(head)
113+
return None
114+
107115
###
108116

109117
# Check that the object root is known.
@@ -1953,8 +1961,15 @@ if config.lldb_build_root != "":
19531961
Specified lldb_build_root, but could not find lldb in that build root
19541962
""")
19551963
else:
1956-
config.available_features.add('lldb')
1957-
config.substitutions.append(('%lldb-python-path', lldb_python_path))
1964+
lldb_python = get_lldb_python_from_path(lldb_python_path)
1965+
if lldb_python == None:
1966+
lit_config.warning("""
1967+
Unable to determine python version from LLDB Python path %s
1968+
""" % lldb_python_path)
1969+
else:
1970+
config.available_features.add('lldb')
1971+
config.substitutions.append(('%lldb-python-path', lldb_python_path))
1972+
config.substitutions.append(('%{lldb-python}', 'PYTHONPATH=%s %s' % (lldb_python_path, lldb_python)))
19581973

19591974
# Disable randomized hash seeding by default. Tests need to manually opt in to
19601975
# random seeds by unsetting the SWIFT_DETERMINISTIC_HASHING environment

0 commit comments

Comments
 (0)