looper/gen_ui_backend_inc.py

33 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/python3
import os
import os.path as path
import sys
from glob import glob
import json
olddir = os.curdir
scriptdir = path.realpath(path.dirname(__file__))
os.chdir(scriptdir)
2024-05-01 09:07:08 -07:00
outpath = path.join(sys.argv[1], "backend_glue.cpp")
ui_backend_dir = path.join(scriptdir, "backends", "ui")
ui_backend_metafiles = []
2024-05-01 09:07:08 -07:00
for backend in sys.argv[2:]:
ui_backend_metafiles += [ui_backend_dir + "/" + backend + "/ui.json"]
ui_backends = []
for metafile_path in ui_backend_metafiles:
with open(metafile_path, "rt") as metafile:
metajson = json.load(metafile)
incpath = path.join(path.dirname(metafile_path), metajson["include_path"])
incpath = path.relpath(incpath, scriptdir)
ui_backend = {"class_name": metajson["class_name"], "include_path": incpath}
ui_backends.append(ui_backend)
with open(outpath, "wt+") as of:
of.write("#include \"backend.hpp\"\n")
for ui_backend in ui_backends:
of.write("#include \"%s\"\n" % ui_backend["include_path"])
of.write("""
void init_backends() {
""")
for ui_backend in ui_backends:
of.write("\tUIBackend::register_backend<%s>();\n" % ui_backend["class_name"])
of.write("}\n")
os.chdir(olddir)