diff options
Diffstat (limited to 'core/extension/make_interface_dumper.py')
-rw-r--r-- | core/extension/make_interface_dumper.py | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/core/extension/make_interface_dumper.py b/core/extension/make_interface_dumper.py index a85d62eff3..af35688200 100644 --- a/core/extension/make_interface_dumper.py +++ b/core/extension/make_interface_dumper.py @@ -2,20 +2,18 @@ import zlib def run(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 */ + 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 */ #ifndef GDEXTENSION_INTERFACE_DUMP_H #define GDEXTENSION_INTERFACE_DUMP_H @@ -26,17 +24,17 @@ def run(target, source, env): #include "core/string/ustring.h" """ - ) + ) - g.write("static const int _gdextension_interface_data_compressed_size = " + str(len(buf)) + ";\n") - g.write("static const int _gdextension_interface_data_uncompressed_size = " + str(decomp_size) + ";\n") - g.write("static const unsigned char _gdextension_interface_data_compressed[] = {\n") - for i in range(len(buf)): - g.write("\t" + str(buf[i]) + ",\n") - g.write("};\n") + g.write("static const int _gdextension_interface_data_compressed_size = " + str(len(buf)) + ";\n") + g.write("static const int _gdextension_interface_data_uncompressed_size = " + str(decomp_size) + ";\n") + g.write("static const unsigned char _gdextension_interface_data_compressed[] = {\n") + for i in range(len(buf)): + g.write("\t" + str(buf[i]) + ",\n") + g.write("};\n") - g.write( - """ + g.write( + """ class GDExtensionInterfaceDump { public: static void generate_gdextension_interface_file(const String &p_path) { @@ -54,12 +52,4 @@ class GDExtensionInterfaceDump { #endif // GDEXTENSION_INTERFACE_DUMP_H """ - ) - g.close() - f.close() - - -if __name__ == "__main__": - from platform_methods import subprocess_main - - subprocess_main(globals()) + ) |