111 lines
4.6 KiB
Python
Executable file
111 lines
4.6 KiB
Python
Executable file
#!/usr/bin/python3
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import os.path as path
|
|
import shutil
|
|
from shutil import which
|
|
from glob import glob
|
|
olddir = os.curdir
|
|
print("Entering assets directory to begin asset conversion...")
|
|
os.chdir(path.realpath(path.dirname(__file__)))
|
|
ASSETS = []
|
|
WARNINGS: dict[str, bool] = {}
|
|
def warn(id: str, message: str, WARNINGS = WARNINGS) -> None:
|
|
warned_already: bool = False
|
|
try:
|
|
warned_already = WARNINGS[id]
|
|
except KeyError:
|
|
pass
|
|
if not warned_already:
|
|
print("WARNING: %s" % message)
|
|
def run_btcc(args: list[str], outpath: str):
|
|
with open(outpath + ".h", "wt+") as f:
|
|
actual_args = ["./btcc"]
|
|
for arg in args:
|
|
actual_args += [arg]
|
|
actual_args += [outpath]
|
|
subprocess.call(actual_args, stdout=f)
|
|
def add_basic(input: str, output: str):
|
|
global ASSETS
|
|
ASSETS += [output + ".h"]
|
|
run_btcc(["-nocompress", input], output)
|
|
def add_base85(input: str, output: str):
|
|
global ASSETS
|
|
ASSETS += [output + ".h"]
|
|
run_btcc(["-base85", input], output)
|
|
def add_font(input: str, output: str|None = None):
|
|
if output == None:
|
|
FONT=path.basename(input).removesuffix(".ttf").lower().replace('-', '_')
|
|
else:
|
|
FONT=output
|
|
print("Adding font '%s' from file '%s'" % (FONT, path.abspath(input)))
|
|
add_base85(input, FONT)
|
|
def add_graphic(input: str):
|
|
GRAPHIC=path.basename(input).removesuffix(".png").lower().replace('-', '_')
|
|
print("Adding graphic '%s' from file '%s'" % (GRAPHIC, input))
|
|
add_base85(input, GRAPHIC)
|
|
def add_license(input: str, output: str):
|
|
LICENSE = output + "_license"
|
|
print("Adding license '%s' (C identifier: '%s') from file '%s'" % (output, LICENSE, input))
|
|
add_basic(input, LICENSE)
|
|
def compile_program(file: str, output: str):
|
|
print("Compiling file '%s' to '%s'" % (path.abspath(file), path.abspath(output)))
|
|
subprocess.call([os.environ.get("CXX", "c++"), file, "-o", output])
|
|
def add_css(file: str, output: str):
|
|
CSS_FILE = output + ".h"
|
|
print("Adding CSS file '%s' (C identifier '%s') from file '%s'" % (file, output, CSS_FILE))
|
|
add_basic(file, output)
|
|
def add_dbus(file: str, output_basename: str, adaptor: str|None = None, proxy: str|None = None, WARNINGS = WARNINGS):
|
|
if adaptor == None:
|
|
adaptor = output_basename + '_adaptor.hpp'
|
|
if proxy == None:
|
|
proxy = output_basename + '_proxy.hpp'
|
|
if which('sdbus-c++-xml2cpp') is not None:
|
|
subprocess.call(['sdbus-c++-xml2cpp', file, '--adaptor=' + adaptor, '--proxy=' + proxy])
|
|
else:
|
|
warn("dbus-nogen", "Not generating DBus API stubs.")
|
|
compile_program("../backends/ui/imgui/imgui/misc/fonts/binary_to_compressed_c.cpp", "btcc")
|
|
for i in glob("Noto_Sans/*.ttf"):
|
|
add_font(i)
|
|
for i in glob("Noto_Sans_JP/*.ttf"):
|
|
add_font(i)
|
|
add_font("ForkAwesome/fonts/forkawesome-webfont.ttf", "forkawesome")
|
|
add_graphic("icon.png")
|
|
add_license("Noto_Sans/OFL.txt", "notosans")
|
|
add_license("Noto_Sans_JP/OFL.txt", "notosansjp")
|
|
add_license("../LICENSE.MIT", "looper_mit")
|
|
add_license("../LICENSE.GPL", "looper_gpl")
|
|
add_license("../COPYING.md", "looper")
|
|
add_license("../subprojects/jsoncpp/LICENSE", "jsoncpp")
|
|
|
|
add_license("../subprojects/SDL-Mixer-X/COPYING.txt", "sdl_mixer_x")
|
|
add_license("../backends/ui/imgui/imgui-filebrowser/LICENSE", "imgui_filebrowser")
|
|
add_license("../backends/ui/imgui/imgui/LICENSE.txt", "imgui")
|
|
add_license("licenses/lgpl-3.0.txt", "lgpl_3_0")
|
|
add_license("licenses/lgpl-2.1.txt", "lgpl_2_1")
|
|
add_license("licenses/lgpl-2.0.txt", "lgpl_2_0")
|
|
add_license("licenses/ForkAwesome.txt", "forkawesome")
|
|
add_license("licenses/cli11.txt", "cli11")
|
|
add_license("licenses/TomlPlusPlus.txt", "tomlplusplus")
|
|
add_license("../backends/ui/imgui/IconFontCppHeaders/licence.txt", "icnfntcpphdrs")
|
|
add_css("gtk-frontend.css", "gtk_frontend_css")
|
|
add_dbus('app.dbus.xml', 'dbus_stub')
|
|
add_dbus('mpris.dbus.xml', 'mpris_stub')
|
|
def finalize(output: str):
|
|
global ASSETS
|
|
print("Writing a header including all previous asset headers and writing it to '%s'..." % output)
|
|
with open(output, "wt+") as f:
|
|
f.write("#pragma once\n")
|
|
for asset in ASSETS:
|
|
print("Adding include for '%s'..." % (asset))
|
|
f.write("#include \"%s\"\n" % asset)
|
|
ASSETS = []
|
|
finalize("assets.h")
|
|
for file in os.listdir("testdata"):
|
|
fpath = path.join(os.curdir, "testdata", path.basename(file))
|
|
add_basic(fpath, "testdata_%s_%s" % (path.splitext(path.basename(file))[0], path.splitext(file)[1].removeprefix(".")))
|
|
finalize("test_assets.h")
|
|
os.remove("btcc")
|
|
print("Returning to previous directory, now that we're done!")
|
|
os.chdir(olddir)
|