[Lldb-commits] [lldb] cf3f100 - [lldb][test] Prevent infinite loop while looking for use_lldb_suite_root.py.
Jordan Rupprecht via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 15 09:57:50 PDT 2020
Author: Jordan Rupprecht
Date: 2020-07-15T09:16:30-07:00
New Revision: cf3f100fcbf94af499501140590b322b4985c1a3
URL: https://github.com/llvm/llvm-project/commit/cf3f100fcbf94af499501140590b322b4985c1a3
DIFF: https://github.com/llvm/llvm-project/commit/cf3f100fcbf94af499501140590b322b4985c1a3.diff
LOG: [lldb][test] Prevent infinite loop while looking for use_lldb_suite_root.py.
Several scripts (two copies of use_lldb_suite.py, and an __init__.py) look for use_lldb_suite_root.py by checking parent directories. If for some reason it doesn't exist, it keeps checking parent directories until it finds it.
However, this only breaks when the parent directory is None, but at least on Linux, dirname('/') == '/', so this will never be None.
This changes the lookup to stop if the dirname(lldb_root) is unchanged. This was previously fixed in 67f6d842fab6d3ac8c949721be8e131cf6b17578, but only in one copy of this script.
Additionally, this makes the failure mode more visible -- if the root is not found, it complains loudly instead of silently failing, and having later modules that need lldb_root fail.
Differential Revision: https://reviews.llvm.org/D83840
Added:
Modified:
lldb/packages/Python/lldbsuite/__init__.py
lldb/scripts/use_lldb_suite.py
lldb/test/API/use_lldb_suite.py
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/__init__.py b/lldb/packages/Python/lldbsuite/__init__.py
index 195b2683f7b4..62f6aee71f30 100644
--- a/lldb/packages/Python/lldbsuite/__init__.py
+++ b/lldb/packages/Python/lldbsuite/__init__.py
@@ -8,14 +8,14 @@
def find_lldb_root():
lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
while True:
- lldb_root = os.path.dirname(lldb_root)
- if lldb_root is None:
- return None
+ parent = os.path.dirname(lldb_root)
+ if parent == lldb_root: # dirname('/') == '/'
+ raise Exception("use_lldb_suite_root.py not found")
+ lldb_root = parent
test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
if os.path.isfile(test_path):
return lldb_root
- return None
# lldbsuite.lldb_root refers to the root of the git/svn source checkout
lldb_root = find_lldb_root()
diff --git a/lldb/scripts/use_lldb_suite.py b/lldb/scripts/use_lldb_suite.py
index a1a2e8b93679..84380f6a5592 100644
--- a/lldb/scripts/use_lldb_suite.py
+++ b/lldb/scripts/use_lldb_suite.py
@@ -8,20 +8,18 @@ def find_lldb_root():
while True:
parent = os.path.dirname(lldb_root)
if parent == lldb_root: # dirname('/') == '/'
- break
+ raise Exception("use_lldb_suite_root.py not found")
lldb_root = parent
test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
if os.path.isfile(test_path):
return lldb_root
- return None
lldb_root = find_lldb_root()
-if lldb_root is not None:
- import imp
- fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
- try:
- imp.load_module("use_lldb_suite_root", fp, pathname, desc)
- finally:
- if fp:
- fp.close()
+import imp
+fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
+try:
+ imp.load_module("use_lldb_suite_root", fp, pathname, desc)
+finally:
+ if fp:
+ fp.close()
diff --git a/lldb/test/API/use_lldb_suite.py b/lldb/test/API/use_lldb_suite.py
index 6a8c12d81898..f1edf1d7304f 100644
--- a/lldb/test/API/use_lldb_suite.py
+++ b/lldb/test/API/use_lldb_suite.py
@@ -8,21 +8,21 @@ def find_lldb_root():
os.path.abspath(inspect.getfile(inspect.currentframe()))
)
while True:
- lldb_root = os.path.dirname(lldb_root)
- if lldb_root is None:
- return None
+ parent = os.path.dirname(lldb_root)
+ if parent == lldb_root: # dirname('/') == '/'
+ raise Exception("use_lldb_suite_root.py not found")
+ lldb_root = parent
test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
if os.path.isfile(test_path):
return lldb_root
- return None
lldb_root = find_lldb_root()
-if lldb_root is not None:
- import imp
- fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
- try:
- imp.load_module("use_lldb_suite_root", fp, pathname, desc)
- finally:
- if fp:
- fp.close()
+
+import imp
+fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
+try:
+ imp.load_module("use_lldb_suite_root", fp, pathname, desc)
+finally:
+ if fp:
+ fp.close()
More information about the lldb-commits
mailing list