xref: /llvm-project/lldb/test/API/use_lldb_suite.py (revision 2260ebf7b6df15db96c76039758dd9dbf009c334)
1import inspect
2import os
3import sys
4
5
6def find_lldb_root():
7    lldb_root = os.path.realpath(
8        os.path.dirname(inspect.getfile(inspect.currentframe()))
9    )
10    while True:
11        parent = os.path.dirname(lldb_root)
12        if parent == lldb_root:  # dirname('/') == '/'
13            raise Exception("use_lldb_suite_root.py not found")
14        lldb_root = parent
15
16        test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
17        if os.path.isfile(test_path):
18            return lldb_root
19
20
21lldb_root = find_lldb_root()
22
23import importlib.machinery
24import importlib.util
25
26path = os.path.join(lldb_root, "use_lldb_suite_root.py")
27loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
28spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
29module = importlib.util.module_from_spec(spec)
30loader.exec_module(module)
31