diff options
Diffstat (limited to 'core/core_builders.py')
-rw-r--r-- | core/core_builders.py | 228 |
1 files changed, 103 insertions, 125 deletions
diff --git a/core/core_builders.py b/core/core_builders.py index e40ebbb14d..a401f03693 100644 --- a/core/core_builders.py +++ b/core/core_builders.py @@ -1,11 +1,7 @@ -"""Functions used to generate source files during build time +"""Functions used to generate source files during build time""" -All such functions are invoked in a subprocess on Windows to prevent build flakiness. -""" import zlib -from platform_methods import subprocess_main - def escape_string(s): def charcode_to_c_escapes(c): @@ -28,37 +24,33 @@ def escape_string(s): def make_certs_header(target, source, env): - src = source[0] - dst = target[0] - f = open(src, "rb") - g = open(dst, "w", encoding="utf-8") - buf = f.read() - decomp_size = len(buf) - - # Use maximum zlib compression level to further reduce file size - # (at the cost of initial build times). - buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION) - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef CERTS_COMPRESSED_GEN_H\n") - g.write("#define CERTS_COMPRESSED_GEN_H\n") - - # System certs path. Editor will use them if defined. (for package maintainers) - path = env["system_certs_path"] - g.write('#define _SYSTEM_CERTS_PATH "%s"\n' % str(path)) - if env["builtin_certs"]: - # Defined here and not in env so changing it does not trigger a full rebuild. - g.write("#define BUILTIN_CERTS_ENABLED\n") - g.write("static const int _certs_compressed_size = " + str(len(buf)) + ";\n") - g.write("static const int _certs_uncompressed_size = " + str(decomp_size) + ";\n") - g.write("static const unsigned char _certs_compressed[] = {\n") - for i in range(len(buf)): - g.write("\t" + str(buf[i]) + ",\n") - g.write("};\n") - g.write("#endif // CERTS_COMPRESSED_GEN_H") - - g.close() - f.close() + src = str(source[0]) + dst = str(target[0]) + with open(src, "rb") as f, open(dst, "w", encoding="utf-8", newline="\n") as g: + buf = f.read() + decomp_size = len(buf) + + # Use maximum zlib compression level to further reduce file size + # (at the cost of initial build times). + buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION) + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef CERTS_COMPRESSED_GEN_H\n") + g.write("#define CERTS_COMPRESSED_GEN_H\n") + + # System certs path. Editor will use them if defined. (for package maintainers) + path = env["system_certs_path"] + g.write('#define _SYSTEM_CERTS_PATH "%s"\n' % str(path)) + if env["builtin_certs"]: + # Defined here and not in env so changing it does not trigger a full rebuild. + g.write("#define BUILTIN_CERTS_ENABLED\n") + g.write("static const int _certs_compressed_size = " + str(len(buf)) + ";\n") + g.write("static const int _certs_uncompressed_size = " + str(decomp_size) + ";\n") + g.write("static const unsigned char _certs_compressed[] = {\n") + for i in range(len(buf)): + g.write("\t" + str(buf[i]) + ",\n") + g.write("};\n") + g.write("#endif // CERTS_COMPRESSED_GEN_H") def make_authors_header(target, source, env): @@ -75,112 +67,102 @@ def make_authors_header(target, source, env): "AUTHORS_DEVELOPERS", ] - src = source[0] - dst = target[0] - f = open(src, "r", encoding="utf-8") - g = open(dst, "w", encoding="utf-8") - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef AUTHORS_GEN_H\n") - g.write("#define AUTHORS_GEN_H\n") + src = str(source[0]) + dst = str(target[0]) + with open(src, "r", encoding="utf-8") as f, open(dst, "w", encoding="utf-8", newline="\n") as g: + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef AUTHORS_GEN_H\n") + g.write("#define AUTHORS_GEN_H\n") - reading = False + reading = False - def close_section(): - g.write("\t0\n") - g.write("};\n") + def close_section(): + g.write("\t0\n") + g.write("};\n") - for line in f: - if reading: - if line.startswith(" "): - g.write('\t"' + escape_string(line.strip()) + '",\n') - continue - if line.startswith("## "): + for line in f: if reading: - close_section() - reading = False - for section, section_id in zip(sections, sections_id): - if line.strip().endswith(section): - current_section = escape_string(section_id) - reading = True - g.write("const char *const " + current_section + "[] = {\n") - break - - if reading: - close_section() + if line.startswith(" "): + g.write('\t"' + escape_string(line.strip()) + '",\n') + continue + if line.startswith("## "): + if reading: + close_section() + reading = False + for section, section_id in zip(sections, sections_id): + if line.strip().endswith(section): + current_section = escape_string(section_id) + reading = True + g.write("const char *const " + current_section + "[] = {\n") + break - g.write("#endif // AUTHORS_GEN_H\n") + if reading: + close_section() - g.close() - f.close() + g.write("#endif // AUTHORS_GEN_H\n") def make_donors_header(target, source, env): sections = [ + "Patrons", "Platinum sponsors", "Gold sponsors", "Silver sponsors", - "Bronze sponsors", - "Mini sponsors", - "Gold donors", - "Silver donors", - "Bronze donors", + "Diamond members", + "Titanium members", + "Platinum members", + "Gold members", ] sections_id = [ - "DONORS_SPONSOR_PLATINUM", - "DONORS_SPONSOR_GOLD", - "DONORS_SPONSOR_SILVER", - "DONORS_SPONSOR_BRONZE", - "DONORS_SPONSOR_MINI", - "DONORS_GOLD", - "DONORS_SILVER", - "DONORS_BRONZE", + "DONORS_PATRONS", + "DONORS_SPONSORS_PLATINUM", + "DONORS_SPONSORS_GOLD", + "DONORS_SPONSORS_SILVER", + "DONORS_MEMBERS_DIAMOND", + "DONORS_MEMBERS_TITANIUM", + "DONORS_MEMBERS_PLATINUM", + "DONORS_MEMBERS_GOLD", ] - src = source[0] - dst = target[0] - f = open(src, "r", encoding="utf-8") - g = open(dst, "w", encoding="utf-8") - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef DONORS_GEN_H\n") - g.write("#define DONORS_GEN_H\n") - - reading = False + src = str(source[0]) + dst = str(target[0]) + with open(src, "r", encoding="utf-8") as f, open(dst, "w", encoding="utf-8", newline="\n") as g: + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef DONORS_GEN_H\n") + g.write("#define DONORS_GEN_H\n") + + reading = False + + def close_section(): + g.write("\t0\n") + g.write("};\n") + + for line in f: + if reading >= 0: + if line.startswith(" "): + g.write('\t"' + escape_string(line.strip()) + '",\n') + continue + if line.startswith("## "): + if reading: + close_section() + reading = False + for section, section_id in zip(sections, sections_id): + if line.strip().endswith(section): + current_section = escape_string(section_id) + reading = True + g.write("const char *const " + current_section + "[] = {\n") + break - def close_section(): - g.write("\t0\n") - g.write("};\n") - - for line in f: - if reading >= 0: - if line.startswith(" "): - g.write('\t"' + escape_string(line.strip()) + '",\n') - continue - if line.startswith("## "): - if reading: - close_section() - reading = False - for section, section_id in zip(sections, sections_id): - if line.strip().endswith(section): - current_section = escape_string(section_id) - reading = True - g.write("const char *const " + current_section + "[] = {\n") - break - - if reading: - close_section() - - g.write("#endif // DONORS_GEN_H\n") + if reading: + close_section() - g.close() - f.close() + g.write("#endif // DONORS_GEN_H\n") def make_license_header(target, source, env): - src_copyright = source[0] - src_license = source[1] - dst = target[0] + src_copyright = str(source[0]) + src_license = str(source[1]) + dst = str(target[0]) class LicenseReader: def __init__(self, license_file): @@ -238,7 +220,7 @@ def make_license_header(target, source, env): part["copyright_index"] = len(data_list) data_list += part["Copyright"] - with open(dst, "w", encoding="utf-8") as f: + with open(dst, "w", encoding="utf-8", newline="\n") as f: f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") f.write("#ifndef LICENSE_GEN_H\n") f.write("#define LICENSE_GEN_H\n") @@ -331,7 +313,3 @@ def make_license_header(target, source, env): f.write("};\n\n") f.write("#endif // LICENSE_GEN_H\n") - - -if __name__ == "__main__": - subprocess_main(globals()) |