[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 67f6d842fa, 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
This commit is contained in:
Jordan Rupprecht 2020-07-15 09:16:30 -07:00
parent 7ebb10d46a
commit cf3f100fcb
3 changed files with 24 additions and 26 deletions

View File

@ -8,14 +8,14 @@ import sys
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()

View File

@ -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()

View File

@ -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()