mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 23:31:53 -05:00
Add Linux Editor tests workflow matrix Add Windows Editor w/ Mono workflow matrix Add Generate Glue Code job to Windows workflow Add Build GodotSharp job to Windows workflow Add godot compatibility version references Add Godot author info Add Godot version compatibility info Add Godot donor info Add Godot authors and donors to editor_about.cpp Credits: Co-authored-by: Skogi <skogi.b@gmail.com> Co-authored-by: Spartan322 <Megacake1234@gmail.com> Co-authored-by: swashberry <swashdev@pm.me> Co-authored-by: Christoffer Sundbom <christoffer_karlsson@live.se> Co-authored-by: Dubhghlas McLaughlin <103212704+mcdubhghlas@users.noreply.github.com> Co-authored-by: McDubh <103212704+mcdubhghlas@users.noreply.github.com> Co-authored-by: Dubhghlas McLaughlin <103212704+mcdubhghlas@users.noreply.github.com> Co-authored-by: radenthefolf <radenthefolf@gmail.com> Co-authored-by: John Knight <80524176+Tekisasu-JohnK@users.noreply.github.com> Co-authored-by: Adam Vondersaar <adam.vondersaar@uphold.com> Co-authored-by: decryptedchaos <nixgod@gmail.com> Co-authored-by: zaftnotameni <122100803+zaftnotameni@users.noreply.github.com> Co-authored-by: Aaron Benjamin <lifeartstudios@gmail.com> Co-authored-by: wesam <108880473+wesamdev@users.noreply.github.com> Co-authored-by: Mister Puma <MisterPuma80@gmail.com> Co-authored-by: Aaron Benjamin <lifeartstudios@gmail.com> Co-authored-by: SingleError <isaaconeoneone@gmail.com> Co-authored-by: Bioblaze Payne <BioblazePayne@gmail.com>
170 lines
5.5 KiB
Python
Executable File
170 lines
5.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
if len(sys.argv) < 2:
|
|
print("Invalid usage of header_guards.py, it should be called with a path to one or multiple files.")
|
|
sys.exit(1)
|
|
|
|
changed = []
|
|
invalid = []
|
|
|
|
for file in sys.argv[1:]:
|
|
header_start = -1
|
|
HEADER_CHECK_OFFSET = -1
|
|
|
|
with open(file.strip(), "rt", encoding="utf-8", newline="\n") as f:
|
|
lines = f.readlines()
|
|
|
|
for idx, line in enumerate(lines):
|
|
sline = line.strip()
|
|
|
|
if header_start < 0:
|
|
if sline == "": # Skip empty lines at the top.
|
|
continue
|
|
|
|
if sline.startswith("/**********"): # Redot header starts this way.
|
|
header_start = idx
|
|
else:
|
|
HEADER_CHECK_OFFSET = 0 # There is no Redot header.
|
|
break
|
|
else:
|
|
if not sline.startswith("*") and not sline.startswith("/*"): # Not in the Redot header anymore.
|
|
HEADER_CHECK_OFFSET = idx + 1 # The include should be two lines below the Redot header.
|
|
break
|
|
|
|
if HEADER_CHECK_OFFSET < 0:
|
|
continue
|
|
|
|
HEADER_BEGIN_OFFSET = HEADER_CHECK_OFFSET + 1
|
|
HEADER_END_OFFSET = len(lines) - 1
|
|
|
|
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 (
|
|
lines[HEADER_CHECK_OFFSET].startswith("#ifndef")
|
|
and lines[HEADER_BEGIN_OFFSET].startswith("#define")
|
|
and lines[HEADER_END_OFFSET].startswith("#endif")
|
|
):
|
|
lines[HEADER_CHECK_OFFSET] = HEADER_CHECK
|
|
lines[HEADER_BEGIN_OFFSET] = HEADER_BEGIN
|
|
lines[HEADER_END_OFFSET] = HEADER_END
|
|
with open(file, "wt", encoding="utf-8", newline="\n") as f:
|
|
f.writelines(lines)
|
|
changed.append(file)
|
|
continue
|
|
|
|
header_check = -1
|
|
header_begin = -1
|
|
header_end = -1
|
|
pragma_once = -1
|
|
objc = False
|
|
|
|
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
|
|
|
|
if objc:
|
|
continue
|
|
|
|
if pragma_once != -1:
|
|
lines.pop(pragma_once)
|
|
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:
|
|
# 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:
|
|
for file in changed:
|
|
print(f"FIXED: {file}")
|
|
if invalid:
|
|
for file in invalid:
|
|
print(f"REQUIRES MANUAL CHANGES: {file}")
|
|
sys.exit(1)
|