I'm trying to put together a small build system in Python that generates Ninja files for my C++ project. Its behavior should be similar to CMake; that is, a bldfile.py script defines rules and targets and optionally recurses into one or more directories by calling bld.subdir(). Each bldfile.py script has a corresponding bld.File object. When the bldfile.py script is executing, the bld global should be predefined as that file's bld.File instance, but only in that module's scope.
Additionally, I would like to take advantage of Python's bytecode caching somehow, but the .pyc file should be stored in the build output directory instead of in a __pycache__ directory alongside the bldfile.py script.
I know I should use importlib (requiring Python 3.4+ is fine), but I'm not sure how to:
- Load and execute a module file with custom globals.
- Re-use the bytecode caching infrastructure.
Any help would be greatly appreciated!
bldglobal will automatically be distinct (unless they explicitly import it from another module, or store it into another module).__pycache__, I think it is hard-coded although the definition seems to be unused. Can't elaborate an answer on the import stuff now; will check back tomorrow.