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

@@ -54,41 +54,41 @@ def parse_template(inherits, source, delimiter):
def make_templates(target, source, env):
dst = target[0]
s = StringIO()
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n\n")
s.write("#ifndef _CODE_TEMPLATES_H\n")
s.write("#define _CODE_TEMPLATES_H\n\n")
s.write('#include "core/object/object.h"\n')
s.write('#include "core/object/script_language.h"\n')
with StringIO() as s:
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n\n")
s.write("#ifndef _CODE_TEMPLATES_H\n")
s.write("#define _CODE_TEMPLATES_H\n\n")
s.write('#include "core/object/object.h"\n')
s.write('#include "core/object/script_language.h"\n')
delimiter = "#" # GDScript single line comment delimiter by default.
if source:
ext = os.path.splitext(source[0])[1]
if ext == ".cs":
delimiter = "//"
delimiter = "#" # GDScript single line comment delimiter by default.
if source:
ext = os.path.splitext(source[0])[1]
if ext == ".cs":
delimiter = "//"
parsed_template_string = ""
number_of_templates = 0
parsed_template_string = ""
number_of_templates = 0
for filepath in source:
node_name = os.path.basename(os.path.dirname(filepath))
parsed_template = parse_template(node_name, filepath, delimiter)
parsed_template_string += "\t" + parsed_template
number_of_templates += 1
for filepath in source:
node_name = os.path.basename(os.path.dirname(filepath))
parsed_template = parse_template(node_name, filepath, delimiter)
parsed_template_string += "\t" + parsed_template
number_of_templates += 1
s.write("\nstatic const int TEMPLATES_ARRAY_SIZE = " + str(number_of_templates) + ";\n")
s.write("\nstatic const struct ScriptLanguage::ScriptTemplate TEMPLATES[" + str(number_of_templates) + "] = {\n")
s.write("\nstatic const int TEMPLATES_ARRAY_SIZE = " + str(number_of_templates) + ";\n")
s.write(
"\nstatic const struct ScriptLanguage::ScriptTemplate TEMPLATES[" + str(number_of_templates) + "] = {\n"
)
s.write(parsed_template_string)
s.write(parsed_template_string)
s.write("};\n")
s.write("};\n")
s.write("\n#endif\n")
s.write("\n#endif\n")
with open(dst, "w", encoding="utf-8", newline="\n") as f:
f.write(s.getvalue())
s.close()
with open(dst, "w", encoding="utf-8", newline="\n") as f:
f.write(s.getvalue())
if __name__ == "__main__":