2024-03-23 18:41:26 -07:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import os
|
|
|
|
import os.path as path
|
|
|
|
import sys
|
|
|
|
from glob import glob
|
|
|
|
import json
|
2024-08-08 13:12:37 -07:00
|
|
|
|
2024-03-23 18:41:26 -07:00
|
|
|
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")
|
2024-03-23 18:41:26 -07:00
|
|
|
ui_backend_dir = path.join(scriptdir, "backends", "ui")
|
|
|
|
ui_backend_metafiles = []
|
2024-08-08 13:12:37 -07:00
|
|
|
playback_backend_dir = path.join(scriptdir, "backends", "playback")
|
|
|
|
playback_backend_metafiles = []
|
|
|
|
adding_uis = True
|
2024-05-01 09:07:08 -07:00
|
|
|
for backend in sys.argv[2:]:
|
2024-08-08 13:12:37 -07:00
|
|
|
if backend == "--ui":
|
|
|
|
adding_uis = True
|
|
|
|
continue
|
|
|
|
elif backend == "--playback":
|
|
|
|
adding_uis = False
|
|
|
|
continue
|
|
|
|
if adding_uis:
|
|
|
|
ui_backend_metafiles += [ui_backend_dir + "/" + backend + "/ui.json"]
|
|
|
|
else:
|
|
|
|
playback_backend_metafiles += [playback_backend_dir + "/" + backend + "/backend.json"]
|
2024-03-23 18:41:26 -07:00
|
|
|
ui_backends = []
|
2024-08-08 13:12:37 -07:00
|
|
|
playback_backends = []
|
2024-03-23 18:41:26 -07:00
|
|
|
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)
|
2024-08-08 13:12:37 -07:00
|
|
|
for metafile_path in playback_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)
|
|
|
|
playback_backend = {"class_name": metajson["class_name"], "include_path": incpath}
|
|
|
|
playback_backends.append(playback_backend)
|
2024-03-23 18:41:26 -07:00
|
|
|
with open(outpath, "wt+") as of:
|
2024-08-08 13:12:37 -07:00
|
|
|
of.write("#include \"playback_backend.hpp\"\n")
|
2024-03-23 18:41:26 -07:00
|
|
|
of.write("#include \"backend.hpp\"\n")
|
|
|
|
for ui_backend in ui_backends:
|
|
|
|
of.write("#include \"%s\"\n" % ui_backend["include_path"])
|
2024-08-08 13:12:37 -07:00
|
|
|
for playback_backend in playback_backends:
|
|
|
|
of.write("#include \"%s\"\n" % playback_backend["include_path"])
|
2024-03-23 18:41:26 -07:00
|
|
|
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")
|
2024-08-08 13:12:37 -07:00
|
|
|
of.write("""
|
|
|
|
void init_playback_backends() {
|
|
|
|
""")
|
|
|
|
for playback_backend in playback_backends:
|
|
|
|
of.write("\tPlaybackBackend::register_backend<%s>();\n" % playback_backend["class_name"])
|
|
|
|
of.write("}\n")
|
2024-03-23 18:41:26 -07:00
|
|
|
os.chdir(olddir)
|