2015-11-07 09:08:25 +08:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-07 09:08:25 +08:00
|
|
|
def find_lldb_root():
|
|
|
|
lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
|
|
|
|
while True:
|
2019-02-07 22:03:43 +08:00
|
|
|
parent = os.path.dirname(lldb_root)
|
|
|
|
if parent == lldb_root: # dirname('/') == '/'
|
[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
2020-07-16 00:16:30 +08:00
|
|
|
raise Exception("use_lldb_suite_root.py not found")
|
2019-02-07 22:03:43 +08:00
|
|
|
lldb_root = parent
|
2015-11-07 09:08:25 +08:00
|
|
|
|
2015-11-21 01:40:57 +08:00
|
|
|
test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
|
2015-11-07 09:08:25 +08:00
|
|
|
if os.path.isfile(test_path):
|
|
|
|
return lldb_root
|
|
|
|
|
|
|
|
lldb_root = find_lldb_root()
|
[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
2020-07-16 00:16:30 +08:00
|
|
|
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()
|