xref: /llvm-project/lldb/bindings/python/createPythonInit.py (revision c8387a31a4adfa9c29a578cf67321f756d3b4ac1)
16498aff2SJonas Devlieghereimport os
26498aff2SJonas Devlieghereimport sys
36498aff2SJonas Devlieghere
46498aff2SJonas DevliegherepkgRelDir = sys.argv[1]
56498aff2SJonas DevliegherepkgFiles = sys.argv[2:]
66498aff2SJonas Devlieghere
76498aff2SJonas DevliegheregetFileName = lambda f: os.path.splitext(os.path.basename(f))[0]
8*c8387a31SDavid SpickettimportNames = ", ".join('"{}"'.format(getFileName(f)) for f in pkgFiles)
96498aff2SJonas Devlieghere
106498aff2SJonas Devliegherescript = """__all__ = [{import_names}]
116498aff2SJonas Devliegherefor x in __all__:
126498aff2SJonas Devlieghere  __import__('lldb.{pkg_name}.' + x)
13bf02586cSDave Lee
14bf02586cSDave Leedef __lldb_init_module(debugger, internal_dict):
15bf02586cSDave Lee  import lldb
16bf02586cSDave Lee  for x in __all__:
17bf02586cSDave Lee    submodule = getattr(lldb.{pkg_name}, x)
18bf02586cSDave Lee    lldb_init = getattr(submodule, '__lldb_init_module', None)
19bf02586cSDave Lee    if lldb_init:
20bf02586cSDave Lee      lldb_init(debugger, internal_dict)
21*c8387a31SDavid Spickett""".format(
22*c8387a31SDavid Spickett    import_names=importNames, pkg_name=pkgRelDir.replace("/", ".")
23*c8387a31SDavid Spickett)
246498aff2SJonas Devlieghere
256498aff2SJonas DevliegherepkgIniFile = os.path.normpath(os.path.join(pkgRelDir, "__init__.py"))
266498aff2SJonas Devliegherewith open(pkgIniFile, "w") as f:
276498aff2SJonas Devlieghere    f.write(script)
28