[Lldb-commits] [lldb] f22496a - [dotest] Simplify logic to find the Python path
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 5 19:04:40 PDT 2020
Author: Jonas Devlieghere
Date: 2020-10-05T19:04:33-07:00
New Revision: f22496a9f4cabb97e735314b62731fedb2e01e50
URL: https://github.com/llvm/llvm-project/commit/f22496a9f4cabb97e735314b62731fedb2e01e50
DIFF: https://github.com/llvm/llvm-project/commit/f22496a9f4cabb97e735314b62731fedb2e01e50.diff
LOG: [dotest] Simplify logic to find the Python path
Simplify the logic of parsing the lldb -P output to find the python
path. This removes the special handling for the LLDB.framework case and
instead of pattern matching known errors focus on finding a directory
path that contains an __init__.py.
Differential revision: https://reviews.llvm.org/D88840
Added:
Modified:
lldb/packages/Python/lldbsuite/test/dotest.py
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index b4eddda91403..922d7c9377ee 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -545,68 +545,33 @@ def setupSysPath():
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"):
- lines = lldb_dash_p_result.splitlines()
-
- # 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
diff erent 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 our lldb supports the -P option, use it to find the python path:
+ lldb_dash_p_result = subprocess.check_output([lldbtest_config.lldbExec, "-P"], universal_newlines=True)
+ if lldb_dash_p_result:
+ for line in lldb_dash_p_result.splitlines():
+ if os.path.isdir(line) and os.path.exists(os.path.join(line, 'lldb', '__init__.py')):
+ lldbPythonDir = line
+ break
+
+ 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
diff erent 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 +585,9 @@ def setupSysPath():
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))
More information about the lldb-commits
mailing list