CVS Repository/ src/ gnu/ llvm/ lldb/ bindings/ python/ createPythonInit.py

Annotated Revision 1.1.1.3 Back
1.1  (patrick 03-Aug-20)  1
: import os
   2
: import sys
   3
: 
   4
: pkgRelDir = sys.argv[1]
   5
: pkgFiles = sys.argv[2:]
   6
: 
   7
: getFileName = lambda f: os.path.splitext(os.path.basename(f))[0]
1.1.1.3  (robert 11-Jun-25)  8
: importNames = ", ".join('"{}"'.format(getFileName(f)) for f in pkgFiles)
1.1  (patrick 03-Aug-20)  9
: 
   10
: script = """__all__ = [{import_names}]
   11
: for x in __all__:
   12
:   __import__('lldb.{pkg_name}.' + x)
1.1.1.2  (robert 11-Nov-23)  13
: 
   14
: def __lldb_init_module(debugger, internal_dict):
   15
:   import lldb
   16
:   for x in __all__:
   17
:     submodule = getattr(lldb.{pkg_name}, x)
   18
:     lldb_init = getattr(submodule, '__lldb_init_module', None)
   19
:     if lldb_init:
   20
:       lldb_init(debugger, internal_dict)
1.1.1.3  (robert 11-Jun-25)  21
: """.format(
   22
:     import_names=importNames, pkg_name=pkgRelDir.replace("/", ".")
   23
: )
1.1  (patrick 03-Aug-20)  24
: 
   25
: pkgIniFile = os.path.normpath(os.path.join(pkgRelDir, "__init__.py"))
   26
: with open(pkgIniFile, "w") as f:
   27
:     f.write(script)