SCons: Ensure with statement where applicable

This commit is contained in:
Thaddeus Crews
2024-03-10 12:09:48 -05:00
parent 0ace0a1292
commit fb299d0fb1
21 changed files with 1649 additions and 1699 deletions

View File

@@ -4,18 +4,16 @@ import zlib
def run(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "rb")
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(src, "rb") as f, open(dst, "w", encoding="utf-8", newline="\n") as g:
buf = f.read()
decomp_size = len(buf)
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)
# 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 */
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,9 +52,7 @@ class GDExtensionInterfaceDump {
#endif // GDEXTENSION_INTERFACE_DUMP_H
"""
)
g.close()
f.close()
)
if __name__ == "__main__":