rupprecht created this revision.
rupprecht added reviewers: labath, JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

use_lldb_suite.py looks 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. It 
still stops if dirname returns None on some systems.

Additionally, this makes the failure mode more visible -- if the root is not 
found, it complains loudly instead of silently failing, having later modules 
that need lldb_root fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83840

Files:
  lldb/test/API/use_lldb_suite.py


Index: lldb/test/API/use_lldb_suite.py
===================================================================
--- lldb/test/API/use_lldb_suite.py
+++ lldb/test/API/use_lldb_suite.py
@@ -7,22 +7,25 @@
     lldb_root = os.path.dirname(
         os.path.abspath(inspect.getfile(inspect.currentframe()))
     )
+    # On Linux, dirname('/') == '/', so we keep looking in parent directories
+    # until the parent directory doesn't change.
+    prev_lldb_root = None
     while True:
+        prev_lldb_root = lldb_root
         lldb_root = os.path.dirname(lldb_root)
-        if lldb_root is None:
-            return None
+        if lldb_root is None or lldb_root == prev_lldb_root:
+            raise Exception("use_lldb_suite_root.py not found")
 
         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()


Index: lldb/test/API/use_lldb_suite.py
===================================================================
--- lldb/test/API/use_lldb_suite.py
+++ lldb/test/API/use_lldb_suite.py
@@ -7,22 +7,25 @@
     lldb_root = os.path.dirname(
         os.path.abspath(inspect.getfile(inspect.currentframe()))
     )
+    # On Linux, dirname('/') == '/', so we keep looking in parent directories
+    # until the parent directory doesn't change.
+    prev_lldb_root = None
     while True:
+        prev_lldb_root = lldb_root
         lldb_root = os.path.dirname(lldb_root)
-        if lldb_root is None:
-            return None
+        if lldb_root is None or lldb_root == prev_lldb_root:
+            raise Exception("use_lldb_suite_root.py not found")
 
         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()
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to