Skip to content

Commit 9a60610

Browse files
authored
Merge pull request #1907 from JDevlieghere/🍒/bastille/f22496a9f4cabb97e735314b62731fedb2e01e50
[dotest] Simplify logic to find the Python path
2 parents a00b13e + 7ad7c1b commit 9a60610

File tree

1 file changed

+30
-62
lines changed

1 file changed

+30
-62
lines changed

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -560,68 +560,33 @@ def setupSysPath():
560560
configuration.skip_categories.append("lldb-vscode")
561561

562562
lldbPythonDir = None # The directory that contains 'lldb/__init__.py'
563-
if configuration.lldb_framework_path:
564-
lldbtest_config.lldb_framework_path = configuration.lldb_framework_path
565-
candidatePath = os.path.join(
566-
configuration.lldb_framework_path, 'Resources', 'Python')
567-
if os.path.isfile(os.path.join(candidatePath, 'lldb/__init__.py')):
568-
lldbPythonDir = candidatePath
569-
if not lldbPythonDir:
570-
print(
571-
'Resources/Python/lldb/__init__.py was not found in ' +
572-
configuration.lldb_framework_path)
573-
sys.exit(-1)
574-
else:
575-
# If our lldb supports the -P option, use it to find the python path:
576-
init_in_python_dir = os.path.join('lldb', '__init__.py')
577-
578-
lldb_dash_p_result = subprocess.check_output(
579-
[lldbtest_config.lldbExec, "-P"], stderr=subprocess.STDOUT, universal_newlines=True)
580-
581-
if lldb_dash_p_result and not lldb_dash_p_result.startswith(
582-
("<", "lldb: invalid option:")) and not lldb_dash_p_result.startswith("Traceback"):
583-
lines = lldb_dash_p_result.splitlines()
584-
585-
# Workaround for readline vs libedit issue on FreeBSD. If stdout
586-
# is not a terminal Python executes
587-
# rl_variable_bind ("enable-meta-key", "off");
588-
# This produces a warning with FreeBSD's libedit because the
589-
# enable-meta-key variable is unknown. Not an issue on Apple
590-
# because cpython commit f0ab6f9f0603 added a #ifndef __APPLE__
591-
# around the call. See http://bugs.python.org/issue19884 for more
592-
# information. For now we just discard the warning output.
593-
if len(lines) >= 1 and lines[0].startswith(
594-
"bind: Invalid command"):
595-
lines.pop(0)
596-
597-
# Taking the last line because lldb outputs
598-
# 'Cannot read termcap database;\nusing dumb terminal settings.\n'
599-
# before the path
600-
if len(lines) >= 1 and os.path.isfile(
601-
os.path.join(lines[-1], init_in_python_dir)):
602-
lldbPythonDir = lines[-1]
603-
if "freebsd" in sys.platform or "linux" in sys.platform:
604-
os.environ['LLDB_LIB_DIR'] = os.path.join(
605-
lldbPythonDir, '..', '..')
606-
607-
if not lldbPythonDir:
608-
print(
609-
"Unable to load lldb extension module. Possible reasons for this include:")
610-
print(" 1) LLDB was built with LLDB_ENABLE_PYTHON=0")
611-
print(
612-
" 2) PYTHONPATH and PYTHONHOME are not set correctly. PYTHONHOME should refer to")
613-
print(
614-
" the version of Python that LLDB built and linked against, and PYTHONPATH")
615-
print(
616-
" should contain the Lib directory for the same python distro, as well as the")
617-
print(" location of LLDB\'s site-packages folder.")
618-
print(
619-
" 3) A different version of Python than that which was built against is exported in")
620-
print(" the system\'s PATH environment variable, causing conflicts.")
621-
print(
622-
" 4) The executable '%s' could not be found. Please check " %
623-
lldbtest_config.lldbExec)
624-
print(" that it exists and is executable.")
563+
564+
# If our lldb supports the -P option, use it to find the python path:
565+
lldb_dash_p_result = subprocess.check_output([lldbtest_config.lldbExec, "-P"], universal_newlines=True)
566+
if lldb_dash_p_result:
567+
for line in lldb_dash_p_result.splitlines():
568+
if os.path.isdir(line) and os.path.exists(os.path.join(line, 'lldb', '__init__.py')):
569+
lldbPythonDir = line
570+
break
571+
572+
if not lldbPythonDir:
573+
print(
574+
"Unable to load lldb extension module. Possible reasons for this include:")
575+
print(" 1) LLDB was built with LLDB_ENABLE_PYTHON=0")
576+
print(
577+
" 2) PYTHONPATH and PYTHONHOME are not set correctly. PYTHONHOME should refer to")
578+
print(
579+
" the version of Python that LLDB built and linked against, and PYTHONPATH")
580+
print(
581+
" should contain the Lib directory for the same python distro, as well as the")
582+
print(" location of LLDB\'s site-packages folder.")
583+
print(
584+
" 3) A different version of Python than that which was built against is exported in")
585+
print(" the system\'s PATH environment variable, causing conflicts.")
586+
print(
587+
" 4) The executable '%s' could not be found. Please check " %
588+
lldbtest_config.lldbExec)
589+
print(" that it exists and is executable.")
625590

626591
if lldbPythonDir:
627592
lldbPythonDir = os.path.normpath(lldbPythonDir)
@@ -635,6 +600,9 @@ def setupSysPath():
635600

636601
lldbPythonDir = os.path.abspath(lldbPythonDir)
637602

603+
if "freebsd" in sys.platform or "linux" in sys.platform:
604+
os.environ['LLDB_LIB_DIR'] = os.path.join(lldbPythonDir, '..', '..')
605+
638606
# If tests need to find LLDB_FRAMEWORK, now they can do it
639607
os.environ["LLDB_FRAMEWORK"] = os.path.dirname(
640608
os.path.dirname(lldbPythonDir))

0 commit comments

Comments
 (0)