Style: Integrate #pragma once
in builders/checks
This commit is contained in:
parent
7459a0361d
commit
96fdaa616b
@ -154,7 +154,6 @@ repos:
|
|||||||
language: python
|
language: python
|
||||||
entry: python misc/scripts/header_guards.py
|
entry: python misc/scripts/header_guards.py
|
||||||
files: \.(h|hpp|hh|hxx)$
|
files: \.(h|hpp|hh|hxx)$
|
||||||
exclude: ^.*/(dummy|thread|platform_config|platform_gl)\.h$
|
|
||||||
|
|
||||||
- id: file-format
|
- id: file-format
|
||||||
name: file-format
|
name: file-format
|
||||||
|
@ -14,8 +14,7 @@ def run(target, source, env):
|
|||||||
|
|
||||||
g.write(
|
g.write(
|
||||||
"""/* THIS FILE IS GENERATED DO NOT EDIT */
|
"""/* THIS FILE IS GENERATED DO NOT EDIT */
|
||||||
#ifndef GDEXTENSION_INTERFACE_DUMP_H
|
#pragma once
|
||||||
#define GDEXTENSION_INTERFACE_DUMP_H
|
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
@ -49,7 +48,5 @@ class GDExtensionInterfaceDump {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOLS_ENABLED
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
#endif // GDEXTENSION_INTERFACE_DUMP_H
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -119,10 +119,7 @@ def generate_ex_version(argcount, const=False, returns=False):
|
|||||||
def run(target, source, env):
|
def run(target, source, env):
|
||||||
max_versions = 12
|
max_versions = 12
|
||||||
|
|
||||||
txt = """
|
txt = "#pragma once"
|
||||||
#ifndef GDEXTENSION_WRAPPERS_GEN_H
|
|
||||||
#define GDEXTENSION_WRAPPERS_GEN_H
|
|
||||||
"""
|
|
||||||
|
|
||||||
for i in range(max_versions + 1):
|
for i in range(max_versions + 1):
|
||||||
txt += "\n/* Extension Wrapper " + str(i) + " Arguments */\n"
|
txt += "\n/* Extension Wrapper " + str(i) + " Arguments */\n"
|
||||||
@ -138,7 +135,5 @@ def run(target, source, env):
|
|||||||
txt += generate_mod_version(i, True, False)
|
txt += generate_mod_version(i, True, False)
|
||||||
txt += generate_mod_version(i, True, True)
|
txt += generate_mod_version(i, True, True)
|
||||||
|
|
||||||
txt += "\n#endif\n"
|
|
||||||
|
|
||||||
with open(str(target[0]), "w", encoding="utf-8", newline="\n") as f:
|
with open(str(target[0]), "w", encoding="utf-8", newline="\n") as f:
|
||||||
f.write(txt)
|
f.write(txt)
|
||||||
|
@ -207,8 +207,7 @@ def run(target, source, env):
|
|||||||
max_versions = 12
|
max_versions = 12
|
||||||
|
|
||||||
txt = """/* THIS FILE IS GENERATED DO NOT EDIT */
|
txt = """/* THIS FILE IS GENERATED DO NOT EDIT */
|
||||||
#ifndef GDVIRTUAL_GEN_H
|
#pragma once
|
||||||
#define GDVIRTUAL_GEN_H
|
|
||||||
|
|
||||||
#include "core/object/script_instance.h"
|
#include "core/object/script_instance.h"
|
||||||
|
|
||||||
@ -257,7 +256,5 @@ def run(target, source, env):
|
|||||||
txt += generate_version(i, True, False, False, True)
|
txt += generate_version(i, True, False, False, True)
|
||||||
txt += generate_version(i, True, True, False, True)
|
txt += generate_version(i, True, True, False, True)
|
||||||
|
|
||||||
txt += "#endif // GDVIRTUAL_GEN_H\n"
|
|
||||||
|
|
||||||
with open(str(target[0]), "w", encoding="utf-8", newline="\n") as f:
|
with open(str(target[0]), "w", encoding="utf-8", newline="\n") as f:
|
||||||
f.write(txt)
|
f.write(txt)
|
||||||
|
@ -209,13 +209,11 @@ def build_gles3_header(
|
|||||||
defvariant = ""
|
defvariant = ""
|
||||||
|
|
||||||
fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
|
fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
|
||||||
|
fd.write("#pragma once\n")
|
||||||
|
|
||||||
out_file_base = out_file
|
out_file_base = out_file
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
||||||
out_file_ifdef = out_file_base.replace(".", "_").upper()
|
|
||||||
fd.write("#ifndef " + out_file_ifdef + class_suffix + "_GLES3\n")
|
|
||||||
fd.write("#define " + out_file_ifdef + class_suffix + "_GLES3\n")
|
|
||||||
|
|
||||||
out_file_class = (
|
out_file_class = (
|
||||||
out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
|
out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
|
||||||
@ -580,8 +578,7 @@ def build_gles3_header(
|
|||||||
|
|
||||||
fd.write("\t}\n\n")
|
fd.write("\t}\n\n")
|
||||||
|
|
||||||
fd.write("};\n\n")
|
fd.write("};\n")
|
||||||
fd.write("#endif\n")
|
|
||||||
|
|
||||||
|
|
||||||
def build_gles3_headers(target, source, env):
|
def build_gles3_headers(target, source, env):
|
||||||
|
@ -106,7 +106,6 @@ def build_rd_header(
|
|||||||
out_file_base = out_file
|
out_file_base = out_file
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
||||||
out_file_ifdef = out_file_base.replace(".", "_").upper()
|
|
||||||
out_file_class = out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "ShaderRD"
|
out_file_class = out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "ShaderRD"
|
||||||
|
|
||||||
if header_data.compute_lines:
|
if header_data.compute_lines:
|
||||||
@ -125,8 +124,7 @@ def build_rd_header(
|
|||||||
|
|
||||||
# Intended curly brackets are doubled so f-string doesn't eat them up.
|
# Intended curly brackets are doubled so f-string doesn't eat them up.
|
||||||
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef {out_file_ifdef}_RD
|
#pragma once
|
||||||
#define {out_file_ifdef}_RD
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
@ -139,8 +137,6 @@ public:
|
|||||||
{body_content}
|
{body_content}
|
||||||
}}
|
}}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
#endif
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
|
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
|
||||||
@ -189,16 +185,13 @@ def build_raw_header(
|
|||||||
out_file_base = out_file.replace(".glsl.gen.h", "_shader_glsl")
|
out_file_base = out_file.replace(".glsl.gen.h", "_shader_glsl")
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
||||||
out_file_ifdef = out_file_base.replace(".", "_").upper()
|
|
||||||
|
|
||||||
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef {out_file_ifdef}_RAW_H
|
#pragma once
|
||||||
#define {out_file_ifdef}_RAW_H
|
|
||||||
|
|
||||||
static const char {out_file_base}[] = {{
|
static const char {out_file_base}[] = {{
|
||||||
{to_raw_cstring(header_data.code)}
|
{to_raw_cstring(header_data.code)}
|
||||||
}};
|
}};
|
||||||
#endif
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as f:
|
with open(out_file, "w", encoding="utf-8", newline="\n") as f:
|
||||||
|
30
methods.py
30
methods.py
@ -1447,8 +1447,6 @@ def generate_copyright_header(filename: str) -> str:
|
|||||||
def generated_wrapper(
|
def generated_wrapper(
|
||||||
path, # FIXME: type with `Union[str, Node, List[Node]]` when pytest conflicts are resolved
|
path, # FIXME: type with `Union[str, Node, List[Node]]` when pytest conflicts are resolved
|
||||||
guard: Optional[bool] = None,
|
guard: Optional[bool] = None,
|
||||||
prefix: str = "",
|
|
||||||
suffix: str = "",
|
|
||||||
) -> Generator[TextIOBase, None, None]:
|
) -> Generator[TextIOBase, None, None]:
|
||||||
"""
|
"""
|
||||||
Wrapper class to automatically handle copyright headers and header guards
|
Wrapper class to automatically handle copyright headers and header guards
|
||||||
@ -1458,12 +1456,8 @@ def generated_wrapper(
|
|||||||
- `path`: The path of the file to be created. Can be passed a raw string, an
|
- `path`: The path of the file to be created. Can be passed a raw string, an
|
||||||
isolated SCons target, or a full SCons target list. If a target list contains
|
isolated SCons target, or a full SCons target list. If a target list contains
|
||||||
multiple entries, produces a warning & only creates the first entry.
|
multiple entries, produces a warning & only creates the first entry.
|
||||||
- `guard`: Optional bool to determine if a header guard should be added. If
|
- `guard`: Optional bool to determine if `#pragma once` should be added. If
|
||||||
unassigned, header guards are determined by the file extension.
|
unassigned, the value is determined by file extension.
|
||||||
- `prefix`: Custom prefix to prepend to a header guard. Produces a warning if
|
|
||||||
provided a value when `guard` evaluates to `False`.
|
|
||||||
- `suffix`: Custom suffix to append to a header guard. Produces a warning if
|
|
||||||
provided a value when `guard` evaluates to `False`.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Handle unfiltered SCons target[s] passed as path.
|
# Handle unfiltered SCons target[s] passed as path.
|
||||||
@ -1480,35 +1474,19 @@ def generated_wrapper(
|
|||||||
|
|
||||||
path = str(path).replace("\\", "/")
|
path = str(path).replace("\\", "/")
|
||||||
if guard is None:
|
if guard is None:
|
||||||
guard = path.endswith((".h", ".hh", ".hpp", ".inc"))
|
guard = path.endswith((".h", ".hh", ".hpp", ".hxx", ".inc"))
|
||||||
if not guard and (prefix or suffix):
|
|
||||||
print_warning(f'Trying to assign header guard prefix/suffix while `guard` is disabled: "{path}".')
|
|
||||||
|
|
||||||
header_guard = ""
|
|
||||||
if guard:
|
|
||||||
if prefix:
|
|
||||||
prefix += "_"
|
|
||||||
if suffix:
|
|
||||||
suffix = f"_{suffix}"
|
|
||||||
split = path.split("/")[-1].split(".")
|
|
||||||
header_guard = (f"{prefix}{split[0]}{suffix}.{'.'.join(split[1:])}".upper()
|
|
||||||
.replace(".", "_").replace("-", "_").replace(" ", "_").replace("__", "_")) # fmt: skip
|
|
||||||
|
|
||||||
with open(path, "wt", encoding="utf-8", newline="\n") as file:
|
with open(path, "wt", encoding="utf-8", newline="\n") as file:
|
||||||
file.write(generate_copyright_header(path))
|
file.write(generate_copyright_header(path))
|
||||||
file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
|
file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
|
||||||
|
|
||||||
if guard:
|
if guard:
|
||||||
file.write(f"#ifndef {header_guard}\n")
|
file.write("#pragma once\n\n")
|
||||||
file.write(f"#define {header_guard}\n\n")
|
|
||||||
|
|
||||||
with StringIO(newline="\n") as str_io:
|
with StringIO(newline="\n") as str_io:
|
||||||
yield str_io
|
yield str_io
|
||||||
file.write(str_io.getvalue().strip() or "/* NO CONTENT */")
|
file.write(str_io.getvalue().strip() or "/* NO CONTENT */")
|
||||||
|
|
||||||
if guard:
|
|
||||||
file.write(f"\n\n#endif // {header_guard}")
|
|
||||||
|
|
||||||
file.write("\n")
|
file.write("\n")
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,8 +106,7 @@ def generate_char_range_inc() -> None:
|
|||||||
source += f"""
|
source += f"""
|
||||||
// This file was generated using the `misc/scripts/char_range_fetch.py` script.
|
// This file was generated using the `misc/scripts/char_range_fetch.py` script.
|
||||||
|
|
||||||
#ifndef CHAR_RANGE_INC
|
#pragma once
|
||||||
#define CHAR_RANGE_INC
|
|
||||||
|
|
||||||
#include "core/typedefs.h"
|
#include "core/typedefs.h"
|
||||||
|
|
||||||
@ -125,8 +124,6 @@ struct CharRange {{
|
|||||||
source += make_array("lowercase_letter", lowercase_letter)
|
source += make_array("lowercase_letter", lowercase_letter)
|
||||||
source += make_array("unicode_letter", unicode_letter)
|
source += make_array("unicode_letter", unicode_letter)
|
||||||
|
|
||||||
source += "#endif // CHAR_RANGE_INC\n"
|
|
||||||
|
|
||||||
char_range_path: str = os.path.join(os.path.dirname(__file__), "../../core/string/char_range.inc")
|
char_range_path: str = os.path.join(os.path.dirname(__file__), "../../core/string/char_range.inc")
|
||||||
with open(char_range_path, "w", newline="\n") as f:
|
with open(char_range_path, "w", newline="\n") as f:
|
||||||
f.write(source)
|
f.write(source)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Invalid usage of header_guards.py, it should be called with a path to one or multiple files.")
|
print("Invalid usage of header_guards.py, it should be called with a path to one or multiple files.")
|
||||||
@ -13,7 +12,7 @@ invalid = []
|
|||||||
|
|
||||||
for file in sys.argv[1:]:
|
for file in sys.argv[1:]:
|
||||||
header_start = -1
|
header_start = -1
|
||||||
HEADER_CHECK_OFFSET = -1
|
header_end = -1
|
||||||
|
|
||||||
with open(file.strip(), "rt", encoding="utf-8", newline="\n") as f:
|
with open(file.strip(), "rt", encoding="utf-8", newline="\n") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
@ -28,17 +27,21 @@ for file in sys.argv[1:]:
|
|||||||
if sline.startswith("/**********"): # Godot header starts this way.
|
if sline.startswith("/**********"): # Godot header starts this way.
|
||||||
header_start = idx
|
header_start = idx
|
||||||
else:
|
else:
|
||||||
HEADER_CHECK_OFFSET = 0 # There is no Godot header.
|
header_end = 0 # There is no Godot header.
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if not sline.startswith("*") and not sline.startswith("/*"): # Not in the Godot header anymore.
|
if not sline.startswith(("*", "/*")): # Not in the Godot header anymore.
|
||||||
HEADER_CHECK_OFFSET = idx + 1 # The include should be two lines below the Godot header.
|
header_end = idx + 1 # The guard should be two lines below the Godot header.
|
||||||
break
|
break
|
||||||
|
|
||||||
if HEADER_CHECK_OFFSET < 0:
|
if (HEADER_CHECK_OFFSET := header_end) < 0 or HEADER_CHECK_OFFSET >= len(lines):
|
||||||
invalid.append(file)
|
invalid.append(file)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if lines[HEADER_CHECK_OFFSET].startswith("#pragma once"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Might be using legacy header guards.
|
||||||
HEADER_BEGIN_OFFSET = HEADER_CHECK_OFFSET + 1
|
HEADER_BEGIN_OFFSET = HEADER_CHECK_OFFSET + 1
|
||||||
HEADER_END_OFFSET = len(lines) - 1
|
HEADER_END_OFFSET = len(lines) - 1
|
||||||
|
|
||||||
@ -46,124 +49,35 @@ for file in sys.argv[1:]:
|
|||||||
invalid.append(file)
|
invalid.append(file)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
split = file.split("/") # Already in posix-format.
|
|
||||||
|
|
||||||
prefix = ""
|
|
||||||
if split[0] == "modules" and split[-1] == "register_types.h":
|
|
||||||
prefix = f"{split[1]}_" # Name of module.
|
|
||||||
elif split[0] == "platform" and (file.endswith("api/api.h") or "/export/" in file):
|
|
||||||
prefix = f"{split[1]}_" # Name of platform.
|
|
||||||
elif file.startswith("modules/mono/utils") and "mono" not in split[-1]:
|
|
||||||
prefix = "MONO_"
|
|
||||||
elif file == "servers/rendering/storage/utilities.h":
|
|
||||||
prefix = "RENDERER_"
|
|
||||||
|
|
||||||
suffix = ""
|
|
||||||
if "dummy" in file and "dummy" not in split[-1]:
|
|
||||||
suffix = "_DUMMY"
|
|
||||||
elif "gles3" in file and "gles3" not in split[-1]:
|
|
||||||
suffix = "_GLES3"
|
|
||||||
elif "renderer_rd" in file and "rd" not in split[-1]:
|
|
||||||
suffix = "_RD"
|
|
||||||
elif split[-1] == "ustring.h":
|
|
||||||
suffix = "_GODOT"
|
|
||||||
|
|
||||||
name = (f"{prefix}{Path(file).stem}{suffix}{Path(file).suffix}".upper()
|
|
||||||
.replace(".", "_").replace("-", "_").replace(" ", "_")) # fmt: skip
|
|
||||||
|
|
||||||
HEADER_CHECK = f"#ifndef {name}\n"
|
|
||||||
HEADER_BEGIN = f"#define {name}\n"
|
|
||||||
HEADER_END = f"#endif // {name}\n"
|
|
||||||
|
|
||||||
if (
|
|
||||||
lines[HEADER_CHECK_OFFSET] == HEADER_CHECK
|
|
||||||
and lines[HEADER_BEGIN_OFFSET] == HEADER_BEGIN
|
|
||||||
and lines[HEADER_END_OFFSET] == HEADER_END
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Guards might exist but with the wrong names.
|
|
||||||
if (
|
if (
|
||||||
lines[HEADER_CHECK_OFFSET].startswith("#ifndef")
|
lines[HEADER_CHECK_OFFSET].startswith("#ifndef")
|
||||||
and lines[HEADER_BEGIN_OFFSET].startswith("#define")
|
and lines[HEADER_BEGIN_OFFSET].startswith("#define")
|
||||||
and lines[HEADER_END_OFFSET].startswith("#endif")
|
and lines[HEADER_END_OFFSET].startswith("#endif")
|
||||||
):
|
):
|
||||||
lines[HEADER_CHECK_OFFSET] = HEADER_CHECK
|
lines[HEADER_CHECK_OFFSET] = "#pragma once"
|
||||||
lines[HEADER_BEGIN_OFFSET] = HEADER_BEGIN
|
lines[HEADER_BEGIN_OFFSET] = "\n"
|
||||||
lines[HEADER_END_OFFSET] = HEADER_END
|
lines.pop()
|
||||||
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
||||||
f.writelines(lines)
|
f.writelines(lines)
|
||||||
changed.append(file)
|
changed.append(file)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
header_check = -1
|
# Verify `#pragma once` doesn't exist at invalid location.
|
||||||
header_begin = -1
|
misplaced = False
|
||||||
header_end = -1
|
for line in lines:
|
||||||
pragma_once = -1
|
if line.startswith("#pragma once"):
|
||||||
objc = False
|
misplaced = True
|
||||||
|
|
||||||
for idx, line in enumerate(lines):
|
|
||||||
if line.startswith("// #import"): # Some dummy obj-c files only have commented out import lines.
|
|
||||||
objc = True
|
|
||||||
break
|
|
||||||
if not line.startswith("#"):
|
|
||||||
continue
|
|
||||||
elif line.startswith("#ifndef") and header_check == -1:
|
|
||||||
header_check = idx
|
|
||||||
elif line.startswith("#define") and header_begin == -1:
|
|
||||||
header_begin = idx
|
|
||||||
elif line.startswith("#endif") and header_end == -1:
|
|
||||||
header_end = idx
|
|
||||||
elif line.startswith("#pragma once"):
|
|
||||||
pragma_once = idx
|
|
||||||
break
|
|
||||||
elif line.startswith("#import"):
|
|
||||||
objc = True
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if objc:
|
if misplaced:
|
||||||
|
invalid.append(file)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if pragma_once != -1:
|
# Assume that we're simply missing a guard entirely.
|
||||||
lines.pop(pragma_once)
|
lines.insert(HEADER_CHECK_OFFSET, "#pragma once\n\n")
|
||||||
lines.insert(HEADER_CHECK_OFFSET, HEADER_CHECK)
|
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
||||||
lines.insert(HEADER_BEGIN_OFFSET, HEADER_BEGIN)
|
f.writelines(lines)
|
||||||
lines.append("\n")
|
changed.append(file)
|
||||||
lines.append(HEADER_END)
|
|
||||||
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
|
||||||
f.writelines(lines)
|
|
||||||
changed.append(file)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if header_check == -1 and header_begin == -1 and header_end == -1:
|
|
||||||
# Guards simply didn't exist
|
|
||||||
lines.insert(HEADER_CHECK_OFFSET, HEADER_CHECK)
|
|
||||||
lines.insert(HEADER_BEGIN_OFFSET, HEADER_BEGIN)
|
|
||||||
lines.append("\n")
|
|
||||||
lines.append(HEADER_END)
|
|
||||||
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
|
||||||
f.writelines(lines)
|
|
||||||
changed.append(file)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if header_check != -1 and header_begin != -1 and header_end != -1:
|
|
||||||
# All prepends "found", see if we can salvage this.
|
|
||||||
if header_check == header_begin - 1 and header_begin < header_end:
|
|
||||||
lines.pop(header_check)
|
|
||||||
lines.pop(header_begin - 1)
|
|
||||||
lines.pop(header_end - 2)
|
|
||||||
if lines[header_end - 3] == "\n":
|
|
||||||
lines.pop(header_end - 3)
|
|
||||||
lines.insert(HEADER_CHECK_OFFSET, HEADER_CHECK)
|
|
||||||
lines.insert(HEADER_BEGIN_OFFSET, HEADER_BEGIN)
|
|
||||||
lines.append("\n")
|
|
||||||
lines.append(HEADER_END)
|
|
||||||
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
|
||||||
f.writelines(lines)
|
|
||||||
changed.append(file)
|
|
||||||
continue
|
|
||||||
|
|
||||||
invalid.append(file)
|
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
for file in changed:
|
for file in changed:
|
||||||
|
@ -55,8 +55,7 @@ def generate_ucaps_fetch() -> None:
|
|||||||
source: str = generate_copyright_header("ucaps.h")
|
source: str = generate_copyright_header("ucaps.h")
|
||||||
|
|
||||||
source += f"""
|
source += f"""
|
||||||
#ifndef UCAPS_H
|
#pragma once
|
||||||
#define UCAPS_H
|
|
||||||
|
|
||||||
// This file was generated using the `misc/scripts/ucaps_fetch.py` script.
|
// This file was generated using the `misc/scripts/ucaps_fetch.py` script.
|
||||||
|
|
||||||
@ -105,8 +104,6 @@ static int _find_lower(int ch) {
|
|||||||
|
|
||||||
\treturn ch;
|
\treturn ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // UCAPS_H
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ucaps_path: str = os.path.join(os.path.dirname(__file__), "../../core/string/ucaps.h")
|
ucaps_path: str = os.path.join(os.path.dirname(__file__), "../../core/string/ucaps.h")
|
||||||
|
@ -18,7 +18,7 @@ def export_icon_builder(target, source, env):
|
|||||||
platform = src_path.parent.parent.stem
|
platform = src_path.parent.parent.stem
|
||||||
with open(str(source[0]), "r") as file:
|
with open(str(source[0]), "r") as file:
|
||||||
svg = file.read()
|
svg = file.read()
|
||||||
with methods.generated_wrapper(target, prefix=platform) as file:
|
with methods.generated_wrapper(target) as file:
|
||||||
file.write(
|
file.write(
|
||||||
f"""\
|
f"""\
|
||||||
static const char *_{platform}_{src_name}_svg = {methods.to_raw_cstring(svg)};
|
static const char *_{platform}_{src_name}_svg = {methods.to_raw_cstring(svg)};
|
||||||
|
@ -78,8 +78,7 @@ def main():
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#ifndef TEST_{name_upper_snake_case}_H
|
#pragma once
|
||||||
#define TEST_{name_upper_snake_case}_H
|
|
||||||
|
|
||||||
#include "tests/test_macros.h"
|
#include "tests/test_macros.h"
|
||||||
|
|
||||||
@ -90,14 +89,11 @@ TEST_CASE("[{name_pascal_case}] Example test case") {{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
}} // namespace Test{name_pascal_case}
|
}} // namespace Test{name_pascal_case}
|
||||||
|
|
||||||
#endif // TEST_{name_upper_snake_case}_H
|
|
||||||
""".format(
|
""".format(
|
||||||
name_snake_case=name_snake_case,
|
name_snake_case=name_snake_case,
|
||||||
# Capitalize the first letter but keep capitalization for the rest of the string.
|
# Capitalize the first letter but keep capitalization for the rest of the string.
|
||||||
# This is done in case the user passes a camelCase string instead of PascalCase.
|
# This is done in case the user passes a camelCase string instead of PascalCase.
|
||||||
name_pascal_case=args.name[0].upper() + args.name[1:],
|
name_pascal_case=args.name[0].upper() + args.name[1:],
|
||||||
name_upper_snake_case=name_snake_case.upper(),
|
|
||||||
# The padding length depends on the test name length.
|
# The padding length depends on the test name length.
|
||||||
padding=" " * (61 - len(name_snake_case)),
|
padding=" " * (61 - len(name_snake_case)),
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef VERTEX_FRAGMENT_GLSL_GEN_HGLES3_GLES3
|
#pragma once
|
||||||
#define VERTEX_FRAGMENT_GLSL_GEN_HGLES3_GLES3
|
|
||||||
|
|
||||||
|
|
||||||
#include "drivers/gles3/shader_gles3.h"
|
#include "drivers/gles3/shader_gles3.h"
|
||||||
@ -70,5 +69,3 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef COMPUTE_SHADER_GLSL_RAW_H
|
#pragma once
|
||||||
#define COMPUTE_SHADER_GLSL_RAW_H
|
|
||||||
|
|
||||||
static const char compute_shader_glsl[] = {
|
static const char compute_shader_glsl[] = {
|
||||||
R"<!>(#[compute]
|
R"<!>(#[compute]
|
||||||
@ -17,4 +16,3 @@ void main() {
|
|||||||
}
|
}
|
||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef VERTEX_FRAGMENT_SHADER_GLSL_RAW_H
|
#pragma once
|
||||||
#define VERTEX_FRAGMENT_SHADER_GLSL_RAW_H
|
|
||||||
|
|
||||||
static const char vertex_fragment_shader_glsl[] = {
|
static const char vertex_fragment_shader_glsl[] = {
|
||||||
R"<!>(#[versions]
|
R"<!>(#[versions]
|
||||||
@ -37,4 +36,3 @@ void main() {
|
|||||||
}
|
}
|
||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef COMPUTE_GLSL_GEN_H_RD
|
#pragma once
|
||||||
#define COMPUTE_GLSL_GEN_H_RD
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
@ -28,5 +27,3 @@ void main() {
|
|||||||
setup(nullptr, nullptr, _compute_code, "ComputeShaderRD");
|
setup(nullptr, nullptr, _compute_code, "ComputeShaderRD");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
||||||
#ifndef VERTEX_FRAGMENT_GLSL_GEN_H_RD
|
#pragma once
|
||||||
#define VERTEX_FRAGMENT_GLSL_GEN_H_RD
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
@ -42,5 +41,3 @@ void main() {
|
|||||||
setup(_vertex_code, _fragment_code, nullptr, "VertexFragmentShaderRD");
|
setup(_vertex_code, _fragment_code, nullptr, "VertexFragmentShaderRD");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user