2018-03-18 06:23:55 +08:00
|
|
|
"""Functions used to generate source files during build time
|
|
|
|
|
|
|
|
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
|
|
|
|
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
from platform_methods import subprocess_main
|
|
|
|
|
|
|
|
|
|
|
|
def make_doc_header(target, source, env):
|
|
|
|
|
|
|
|
dst = target[0]
|
2020-03-25 21:36:03 +08:00
|
|
|
g = open(dst, "w", encoding="utf-8")
|
2018-03-18 06:23:55 +08:00
|
|
|
buf = ""
|
|
|
|
docbegin = ""
|
|
|
|
docend = ""
|
|
|
|
for src in source:
|
|
|
|
if not src.endswith(".xml"):
|
|
|
|
continue
|
2020-03-25 21:36:03 +08:00
|
|
|
with open(src, "r", encoding="utf-8") as f:
|
2018-03-18 06:23:55 +08:00
|
|
|
content = f.read()
|
|
|
|
buf += content
|
|
|
|
|
2020-03-25 21:36:03 +08:00
|
|
|
buf = (docbegin + buf + docend).encode("utf-8")
|
2018-03-18 06:23:55 +08:00
|
|
|
decomp_size = len(buf)
|
|
|
|
import zlib
|
2020-03-30 14:28:32 +08:00
|
|
|
|
2018-03-18 06:23:55 +08:00
|
|
|
buf = zlib.compress(buf)
|
|
|
|
|
|
|
|
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
|
|
|
g.write("#ifndef _DOC_DATA_RAW_H\n")
|
|
|
|
g.write("#define _DOC_DATA_RAW_H\n")
|
|
|
|
g.write("static const int _doc_data_compressed_size = " + str(len(buf)) + ";\n")
|
|
|
|
g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n")
|
|
|
|
g.write("static const unsigned char _doc_data_compressed[] = {\n")
|
|
|
|
for i in range(len(buf)):
|
2020-03-25 21:36:03 +08:00
|
|
|
g.write("\t" + str(buf[i]) + ",\n")
|
2018-03-18 06:23:55 +08:00
|
|
|
g.write("};\n")
|
|
|
|
|
|
|
|
g.write("#endif")
|
|
|
|
|
|
|
|
g.close()
|
|
|
|
|
|
|
|
|
|
|
|
def make_fonts_header(target, source, env):
|
|
|
|
|
|
|
|
dst = target[0]
|
|
|
|
|
2020-03-25 21:36:03 +08:00
|
|
|
g = open(dst, "w", encoding="utf-8")
|
2018-03-18 06:23:55 +08:00
|
|
|
|
|
|
|
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
|
|
|
g.write("#ifndef _EDITOR_FONTS_H\n")
|
|
|
|
g.write("#define _EDITOR_FONTS_H\n")
|
|
|
|
|
|
|
|
# saving uncompressed, since freetype will reference from memory pointer
|
|
|
|
xl_names = []
|
|
|
|
for i in range(len(source)):
|
2020-03-30 14:28:32 +08:00
|
|
|
with open(source[i], "rb") as f:
|
2018-03-18 06:23:55 +08:00
|
|
|
buf = f.read()
|
|
|
|
|
|
|
|
name = os.path.splitext(os.path.basename(source[i]))[0]
|
|
|
|
|
|
|
|
g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
|
|
|
|
g.write("static const unsigned char _font_" + name + "[] = {\n")
|
2019-07-11 23:02:36 +08:00
|
|
|
for j in range(len(buf)):
|
2020-03-25 21:36:03 +08:00
|
|
|
g.write("\t" + str(buf[j]) + ",\n")
|
2018-03-18 06:23:55 +08:00
|
|
|
|
|
|
|
g.write("};\n")
|
|
|
|
|
|
|
|
g.write("#endif")
|
|
|
|
|
|
|
|
g.close()
|
|
|
|
|
|
|
|
|
2020-03-19 01:34:36 +08:00
|
|
|
def make_translations_header(target, source, env, category):
|
2018-03-18 06:23:55 +08:00
|
|
|
|
|
|
|
dst = target[0]
|
|
|
|
|
2020-03-25 21:36:03 +08:00
|
|
|
g = open(dst, "w", encoding="utf-8")
|
2018-03-18 06:23:55 +08:00
|
|
|
|
|
|
|
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
2020-03-19 01:34:36 +08:00
|
|
|
g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))
|
|
|
|
g.write("#define _{}_TRANSLATIONS_H\n".format(category.upper()))
|
2018-03-18 06:23:55 +08:00
|
|
|
|
|
|
|
import zlib
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
sorted_paths = sorted(source, key=lambda path: os.path.splitext(os.path.basename(path))[0])
|
|
|
|
|
|
|
|
xl_names = []
|
|
|
|
for i in range(len(sorted_paths)):
|
|
|
|
with open(sorted_paths[i], "rb") as f:
|
|
|
|
buf = f.read()
|
|
|
|
decomp_size = len(buf)
|
|
|
|
buf = zlib.compress(buf)
|
|
|
|
name = os.path.splitext(os.path.basename(sorted_paths[i]))[0]
|
|
|
|
|
2020-03-19 01:34:36 +08:00
|
|
|
g.write("static const unsigned char _{}_translation_{}_compressed[] = {{\n".format(category, name))
|
2019-07-11 23:02:36 +08:00
|
|
|
for j in range(len(buf)):
|
2020-03-25 21:36:03 +08:00
|
|
|
g.write("\t" + str(buf[j]) + ",\n")
|
2018-03-18 06:23:55 +08:00
|
|
|
|
|
|
|
g.write("};\n")
|
|
|
|
|
|
|
|
xl_names.append([name, len(buf), str(decomp_size)])
|
|
|
|
|
2020-03-19 01:34:36 +08:00
|
|
|
g.write("struct {}TranslationList {{\n".format(category.capitalize()))
|
2018-03-18 06:23:55 +08:00
|
|
|
g.write("\tconst char* lang;\n")
|
|
|
|
g.write("\tint comp_size;\n")
|
|
|
|
g.write("\tint uncomp_size;\n")
|
|
|
|
g.write("\tconst unsigned char* data;\n")
|
|
|
|
g.write("};\n\n")
|
2020-03-19 01:34:36 +08:00
|
|
|
g.write("static {}TranslationList _{}_translations[] = {{\n".format(category.capitalize(), category))
|
2018-03-18 06:23:55 +08:00
|
|
|
for x in xl_names:
|
2020-03-30 14:28:32 +08:00
|
|
|
g.write(
|
|
|
|
'\t{{ "{}", {}, {}, _{}_translation_{}_compressed }},\n'.format(x[0], str(x[1]), str(x[2]), category, x[0])
|
|
|
|
)
|
2020-04-02 20:41:58 +08:00
|
|
|
g.write("\t{nullptr, 0, 0, nullptr}\n")
|
2018-03-18 06:23:55 +08:00
|
|
|
g.write("};\n")
|
|
|
|
|
|
|
|
g.write("#endif")
|
|
|
|
|
|
|
|
g.close()
|
|
|
|
|
2020-03-19 01:34:36 +08:00
|
|
|
|
|
|
|
def make_editor_translations_header(target, source, env):
|
|
|
|
make_translations_header(target, source, env, "editor")
|
|
|
|
|
|
|
|
|
|
|
|
def make_doc_translations_header(target, source, env):
|
|
|
|
make_translations_header(target, source, env, "doc")
|
|
|
|
|
|
|
|
|
2020-03-30 14:28:32 +08:00
|
|
|
if __name__ == "__main__":
|
2018-03-18 06:23:55 +08:00
|
|
|
subprocess_main(globals())
|