mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-26 11:25:27 +00:00
cf3f100fcb
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
26 lines
697 B
Python
26 lines
697 B
Python
import inspect
|
|
import os
|
|
import sys
|
|
|
|
|
|
def find_lldb_root():
|
|
lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
|
|
while True:
|
|
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
|
|
|
|
lldb_root = find_lldb_root()
|
|
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()
|