Merge pull request #98653 from Repiteo/scons/pretty-builders
SCons: Make builders prettier, utilize `constexpr`
This commit is contained in:
@ -9,7 +9,6 @@ env.add_source_files(env.scene_sources, "*.cpp")
|
||||
|
||||
SConscript("icons/SCsub")
|
||||
|
||||
env.Depends("#scene/theme/default_font.gen.h", "#thirdparty/fonts/OpenSans_SemiBold.woff2")
|
||||
env.CommandNoCache(
|
||||
"#scene/theme/default_font.gen.h",
|
||||
"#thirdparty/fonts/OpenSans_SemiBold.woff2",
|
||||
|
||||
@ -1,30 +1,21 @@
|
||||
"""Functions used to generate source files during build time"""
|
||||
|
||||
import os
|
||||
import os.path
|
||||
|
||||
import methods
|
||||
|
||||
|
||||
def make_fonts_header(target, source, env):
|
||||
dst = str(target[0])
|
||||
with methods.generated_wrapper(str(target[0])) as file:
|
||||
for src in map(str, source):
|
||||
# Saving uncompressed, since FreeType will reference from memory pointer.
|
||||
buffer = methods.get_buffer(src)
|
||||
name = os.path.splitext(os.path.basename(src))[0]
|
||||
|
||||
with open(dst, "w", encoding="utf-8", newline="\n") as g:
|
||||
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
||||
g.write("#ifndef _DEFAULT_FONTS_H\n")
|
||||
g.write("#define _DEFAULT_FONTS_H\n")
|
||||
file.write(f"""\
|
||||
inline constexpr int _font_{name}_size = {len(buffer)};
|
||||
inline constexpr unsigned char _font_{name}[] = {{
|
||||
{methods.format_buffer(buffer, 1)}
|
||||
}};
|
||||
|
||||
# Saving uncompressed, since FreeType will reference from memory pointer.
|
||||
for i in range(len(source)):
|
||||
file = str(source[i])
|
||||
with open(file, "rb") as f:
|
||||
buf = f.read()
|
||||
|
||||
name = os.path.splitext(os.path.basename(file))[0]
|
||||
|
||||
g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
|
||||
g.write("static const unsigned char _font_" + name + "[] = {\n")
|
||||
for j in range(len(buf)):
|
||||
g.write("\t" + str(buf[j]) + ",\n")
|
||||
|
||||
g.write("};\n")
|
||||
|
||||
g.write("#endif")
|
||||
""")
|
||||
|
||||
@ -1,51 +1,35 @@
|
||||
"""Functions used to generate source files during build time"""
|
||||
|
||||
import os
|
||||
from io import StringIO
|
||||
|
||||
from methods import to_raw_cstring
|
||||
import methods
|
||||
|
||||
|
||||
# See also `editor/icons/editor_icons_builders.py`.
|
||||
def make_default_theme_icons_action(target, source, env):
|
||||
dst = str(target[0])
|
||||
svg_icons = [str(x) for x in source]
|
||||
icons_names = []
|
||||
icons_raw = []
|
||||
|
||||
with StringIO() as icons_string, StringIO() as s:
|
||||
for svg in svg_icons:
|
||||
with open(svg, "r") as svgf:
|
||||
icons_string.write("\t%s,\n" % to_raw_cstring(svgf.read()))
|
||||
for src in map(str, source):
|
||||
with open(src, encoding="utf-8", newline="\n") as file:
|
||||
icons_raw.append(methods.to_raw_cstring(file.read()))
|
||||
|
||||
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n\n")
|
||||
s.write('#include "modules/modules_enabled.gen.h"\n\n')
|
||||
s.write("#ifndef _DEFAULT_THEME_ICONS_H\n")
|
||||
s.write("#define _DEFAULT_THEME_ICONS_H\n")
|
||||
s.write("static const int default_theme_icons_count = {};\n\n".format(len(svg_icons)))
|
||||
s.write("#ifdef MODULE_SVG_ENABLED\n")
|
||||
s.write("static const char *default_theme_icons_sources[] = {\n")
|
||||
s.write(icons_string.getvalue())
|
||||
s.write("};\n")
|
||||
s.write("#endif // MODULE_SVG_ENABLED\n\n")
|
||||
s.write("static const char *default_theme_icons_names[] = {\n")
|
||||
name = os.path.splitext(os.path.basename(src))[0]
|
||||
icons_names.append(f'"{name}"')
|
||||
|
||||
index = 0
|
||||
for f in svg_icons:
|
||||
fname = str(f)
|
||||
icons_names_str = ",\n\t".join(icons_names)
|
||||
icons_raw_str = ",\n\t".join(icons_raw)
|
||||
|
||||
# Trim the `.svg` extension from the string.
|
||||
icon_name = os.path.basename(fname)[:-4]
|
||||
with methods.generated_wrapper(str(target[0])) as file:
|
||||
file.write(f"""\
|
||||
#include "modules/modules_enabled.gen.h"
|
||||
|
||||
s.write('\t"{0}"'.format(icon_name))
|
||||
inline constexpr int default_theme_icons_count = {len(icons_names)};
|
||||
inline constexpr const char *default_theme_icons_sources[] = {{
|
||||
{icons_raw_str}
|
||||
}};
|
||||
|
||||
if fname != svg_icons[-1]:
|
||||
s.write(",")
|
||||
s.write("\n")
|
||||
|
||||
index += 1
|
||||
|
||||
s.write("};\n")
|
||||
|
||||
s.write("#endif\n")
|
||||
|
||||
with open(dst, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write(s.getvalue())
|
||||
inline constexpr const char *default_theme_icons_names[] = {{
|
||||
{icons_names_str}
|
||||
}};
|
||||
""")
|
||||
|
||||
Reference in New Issue
Block a user