Index: lldb/packages/Python/lldbsuite/test/dotest.py =================================================================== --- lldb/packages/Python/lldbsuite/test/dotest.py +++ lldb/packages/Python/lldbsuite/test/dotest.py @@ -545,68 +545,35 @@ configuration.skip_categories.append("lldb-vscode") lldbPythonDir = None # The directory that contains 'lldb/__init__.py' - if configuration.lldb_framework_path: - lldbtest_config.lldb_framework_path = configuration.lldb_framework_path - candidatePath = os.path.join( - configuration.lldb_framework_path, 'Resources', 'Python') - if os.path.isfile(os.path.join(candidatePath, 'lldb/__init__.py')): - lldbPythonDir = candidatePath - if not lldbPythonDir: - print( - 'Resources/Python/lldb/__init__.py was not found in ' + - configuration.lldb_framework_path) - sys.exit(-1) - else: - # If our lldb supports the -P option, use it to find the python path: - init_in_python_dir = os.path.join('lldb', '__init__.py') - lldb_dash_p_result = subprocess.check_output( - [lldbtest_config.lldbExec, "-P"], stderr=subprocess.STDOUT, universal_newlines=True) - - if lldb_dash_p_result and not lldb_dash_p_result.startswith( - ("<", "lldb: invalid option:")) and not lldb_dash_p_result.startswith("Traceback"): + # If our lldb supports the -P option, use it to find the python path: + with open(os.devnull, 'w') as DEVNULL: + lldb_dash_p_result = subprocess.check_output([lldbtest_config.lldbExec, "-P"], stderr=DEVNULL, universal_newlines=True) + if lldb_dash_p_result and not lldb_dash_p_result.startswith(("<", "lldb: invalid option:")): lines = lldb_dash_p_result.splitlines() + for line in lines: + if os.path.isdir(line) and os.path.exists(os.path.join(line, 'lldb', '__init__.py')): + lldbPythonDir = line + break - # Workaround for readline vs libedit issue on FreeBSD. If stdout - # is not a terminal Python executes - # rl_variable_bind ("enable-meta-key", "off"); - # This produces a warning with FreeBSD's libedit because the - # enable-meta-key variable is unknown. Not an issue on Apple - # because cpython commit f0ab6f9f0603 added a #ifndef __APPLE__ - # around the call. See http://bugs.python.org/issue19884 for more - # information. For now we just discard the warning output. - if len(lines) >= 1 and lines[0].startswith( - "bind: Invalid command"): - lines.pop(0) - - # Taking the last line because lldb outputs - # 'Cannot read termcap database;\nusing dumb terminal settings.\n' - # before the path - if len(lines) >= 1 and os.path.isfile( - os.path.join(lines[-1], init_in_python_dir)): - lldbPythonDir = lines[-1] - if "freebsd" in sys.platform or "linux" in sys.platform: - os.environ['LLDB_LIB_DIR'] = os.path.join( - lldbPythonDir, '..', '..') - - if not lldbPythonDir: - print( - "Unable to load lldb extension module. Possible reasons for this include:") - print(" 1) LLDB was built with LLDB_ENABLE_PYTHON=0") - print( - " 2) PYTHONPATH and PYTHONHOME are not set correctly. PYTHONHOME should refer to") - print( - " the version of Python that LLDB built and linked against, and PYTHONPATH") - print( - " should contain the Lib directory for the same python distro, as well as the") - print(" location of LLDB\'s site-packages folder.") - print( - " 3) A different version of Python than that which was built against is exported in") - print(" the system\'s PATH environment variable, causing conflicts.") - print( - " 4) The executable '%s' could not be found. Please check " % - lldbtest_config.lldbExec) - print(" that it exists and is executable.") + if not lldbPythonDir: + print( + "Unable to load lldb extension module. Possible reasons for this include:") + print(" 1) LLDB was built with LLDB_ENABLE_PYTHON=0") + print( + " 2) PYTHONPATH and PYTHONHOME are not set correctly. PYTHONHOME should refer to") + print( + " the version of Python that LLDB built and linked against, and PYTHONPATH") + print( + " should contain the Lib directory for the same python distro, as well as the") + print(" location of LLDB\'s site-packages folder.") + print( + " 3) A different version of Python than that which was built against is exported in") + print(" the system\'s PATH environment variable, causing conflicts.") + print( + " 4) The executable '%s' could not be found. Please check " % + lldbtest_config.lldbExec) + print(" that it exists and is executable.") if lldbPythonDir: lldbPythonDir = os.path.normpath(lldbPythonDir) @@ -620,6 +587,9 @@ lldbPythonDir = os.path.abspath(lldbPythonDir) + if "freebsd" in sys.platform or "linux" in sys.platform: + os.environ['LLDB_LIB_DIR'] = os.path.join(lldbPythonDir, '..', '..') + # If tests need to find LLDB_FRAMEWORK, now they can do it os.environ["LLDB_FRAMEWORK"] = os.path.dirname( os.path.dirname(lldbPythonDir))