feat: godot-engine-source-4.3-stable

This commit is contained in:
Jan van der Weide 2025-01-17 16:36:38 +01:00
parent c59a7dcade
commit 7125d019b5
11149 changed files with 5070401 additions and 0 deletions

View file

@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
if len(sys.argv) < 2:
print("ERROR: You must run program with file name as argument.")
sys.exit(50)
fname = sys.argv[1]
with open(fname.strip(), "r", encoding="utf-8") as fileread:
file_contents = fileread.read()
# If find "ERROR: AddressSanitizer:", then happens invalid read or write
# This is critical bug, so we need to fix this as fast as possible
if file_contents.find("ERROR: AddressSanitizer:") != -1:
print("FATAL ERROR: An incorrectly used memory was found.")
sys.exit(51)
# There is also possible, that program crashed with or without backtrace.
if (
file_contents.find("Program crashed with signal") != -1
or file_contents.find("Dumping the backtrace") != -1
or file_contents.find("Segmentation fault (core dumped)") != -1
or file_contents.find("Aborted (core dumped)") != -1
or file_contents.find("terminate called without an active exception") != -1
):
print("FATAL ERROR: Godot has been crashed.")
sys.exit(52)
# Finding memory leaks in Godot is quite difficult, because we need to take into
# account leaks also in external libraries. They are usually provided without
# debugging symbols, so the leak report from it usually has only 2/3 lines,
# so searching for 5 element - "#4 0x" - should correctly detect the vast
# majority of memory leaks
if file_contents.find("ERROR: LeakSanitizer:") != -1:
if file_contents.find("#4 0x") != -1:
print("ERROR: Memory leak was found")
sys.exit(53)
# It may happen that Godot detects leaking nodes/resources and removes them, so
# this possibility should also be handled as a potential error, even if
# LeakSanitizer doesn't report anything
if file_contents.find("ObjectDB instances leaked at exit") != -1:
print("ERROR: Memory leak was found")
sys.exit(54)
# In test project may be put several assert functions which will control if
# project is executed with right parameters etc. which normally will not stop
# execution of project
if file_contents.find("Assertion failed") != -1:
print("ERROR: Assertion failed in project, check execution log for more info")
sys.exit(55)
# For now Godot leaks a lot of rendering stuff so for now we just show info
# about it and this needs to be re-enabled after fixing this memory leaks.
if file_contents.find("were leaked") != -1 or file_contents.find("were never freed") != -1:
print("WARNING: Memory leak was found")
sys.exit(0)

View file

@ -0,0 +1,96 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
header = """\
/**************************************************************************/
/* $filename */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
"""
if len(sys.argv) < 2:
print("Invalid usage of copyright_headers.py, it should be called with a path to one or multiple files.")
sys.exit(1)
for f in sys.argv[1:]:
fname = f
# Handle replacing $filename with actual filename and keep alignment
fsingle = os.path.basename(fname.strip())
rep_fl = "$filename"
rep_fi = fsingle
len_fl = len(rep_fl)
len_fi = len(rep_fi)
# Pad with spaces to keep alignment
if len_fi < len_fl:
for x in range(len_fl - len_fi):
rep_fi += " "
elif len_fl < len_fi:
for x in range(len_fi - len_fl):
rep_fl += " "
if header.find(rep_fl) != -1:
text = header.replace(rep_fl, rep_fi)
else:
text = header.replace("$filename", fsingle)
text += "\n"
# We now have the proper header, so we want to ignore the one in the original file
# and potentially empty lines and badly formatted lines, while keeping comments that
# come after the header, and then keep everything non-header unchanged.
# To do so, we skip empty lines that may be at the top in a first pass.
# In a second pass, we skip all consecutive comment lines starting with "/*",
# then we can append the rest (step 2).
with open(fname.strip(), "r", encoding="utf-8") as fileread:
line = fileread.readline()
header_done = False
while line.strip() == "" and line != "": # Skip empty lines at the top
line = fileread.readline()
if line.find("/**********") == -1: # Godot header starts this way
# Maybe starting with a non-Godot comment, abort header magic
header_done = True
while not header_done: # Handle header now
if line.find("/*") != 0: # No more starting with a comment
header_done = True
if line.strip() != "":
text += line
line = fileread.readline()
while line != "": # Dump everything until EOF
text += line
line = fileread.readline()
# Write
with open(fname.strip(), "w", encoding="utf-8", newline="\n") as filewrite:
filewrite.write(text)

View file

@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob
import os
import sys
if len(sys.argv) < 2:
print("Invalid usage of dotnet_format.py, it should be called with a path to one or multiple files.")
sys.exit(1)
# Create dummy generated files, if needed.
for path in [
"modules/mono/SdkPackageVersions.props",
]:
if os.path.exists(path):
continue
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", encoding="utf-8", newline="\n") as f:
f.write("<Project />")
# Avoid importing GeneratedIncludes.props.
os.environ["GodotSkipGenerated"] = "true"
# Match all the input files to their respective C# project.
projects = {
path: " ".join([f for f in sys.argv[1:] if os.path.commonpath([f, path]) == path])
for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
}
# Run dotnet format on all projects with more than 0 modified files.
for path, files in projects.items():
if files:
os.system(f"dotnet format {path} --include {files}")

View file

@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
if len(sys.argv) < 2:
print("Invalid usage of file_format.py, it should be called with a path to one or multiple files.")
sys.exit(1)
BOM = b"\xef\xbb\xbf"
changed = []
invalid = []
for file in sys.argv[1:]:
try:
with open(file, "rt", encoding="utf-8") as f:
original = f.read()
except UnicodeDecodeError:
invalid.append(file)
continue
if original == "":
continue
EOL = "\r\n" if file.endswith((".csproj", ".sln", ".bat")) or file.startswith("misc/msvs") else "\n"
WANTS_BOM = file.endswith((".csproj", ".sln"))
revamp = EOL.join([line.rstrip("\n\r\t ") for line in original.splitlines(True)]).rstrip(EOL) + EOL
new_raw = revamp.encode(encoding="utf-8")
if not WANTS_BOM and new_raw.startswith(BOM):
new_raw = new_raw[len(BOM) :]
elif WANTS_BOM and not new_raw.startswith(BOM):
new_raw = BOM + new_raw
with open(file, "rb") as f:
old_raw = f.read()
if old_raw != new_raw:
changed.append(file)
with open(file, "wb") as f:
f.write(new_raw)
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)

View file

@ -0,0 +1,26 @@
set -uo pipefail
shopt -s globstar
echo -e ".gitignore validation..."
# Get a list of files that exist in the repo but are ignored.
# The --verbose flag also includes files un-ignored via ! prefixes.
# We filter those out with a somewhat awkward `awk` directive.
# (Explanation: Split each line by : delimiters,
# see if the actual gitignore line shown in the third field starts with !,
# if it doesn't, print it.)
# ignorecase for the sake of Windows users.
output=$(git -c core.ignorecase=true check-ignore --verbose --no-index **/* | \
awk -F ':' '{ if ($3 !~ /^!/) print $0 }')
# Then we take this result and return success if it's empty.
if [ -z "$output" ]; then
exit 0
else
# And print the result if it isn't.
echo "$output"
exit 1
fi

View file

@ -0,0 +1,169 @@
#!/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("/**********"): # Godot header starts this way.
header_start = idx
else:
HEADER_CHECK_OFFSET = 0 # There is no Godot header.
break
else:
if not sline.startswith("*") and not sline.startswith("/*"): # Not in the Godot header anymore.
HEADER_CHECK_OFFSET = idx + 1 # The include should be two lines below the Godot 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)

View file

@ -0,0 +1,127 @@
#!/usr/bin/env python
import os
import shutil
import subprocess
import sys
import urllib.request
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
# <https://github.com/python/cpython/issues/73245>
if sys.platform == "win32":
from ctypes import byref, c_int, windll
stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
mode = c_int(0)
windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode))
mode = c_int(mode.value | 4)
windll.kernel32.SetConsoleMode(c_int(stdout_handle), mode)
# Base Godot dependencies path
# If cross-compiling (no LOCALAPPDATA), we install in `bin`
deps_folder = os.getenv("LOCALAPPDATA")
if deps_folder:
deps_folder = os.path.join(deps_folder, "Godot", "build_deps")
else:
deps_folder = os.path.join("bin", "build_deps")
# Mesa NIR
# Check for latest version: https://github.com/godotengine/godot-nir-static/releases/latest
mesa_version = "23.1.9"
mesa_filename = "godot-nir-23.1.9.zip"
mesa_archive = os.path.join(deps_folder, mesa_filename)
mesa_folder = os.path.join(deps_folder, "mesa")
# WinPixEventRuntime
# Check for latest version: https://www.nuget.org/api/v2/package/WinPixEventRuntime (check downloaded filename)
pix_version = "1.0.240308001"
pix_archive = os.path.join(deps_folder, f"WinPixEventRuntime_{pix_version}.nupkg")
pix_folder = os.path.join(deps_folder, "pix")
# DirectX 12 Agility SDK
# Check for latest version: https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12 (check downloaded filename)
# After updating this, remember to change the default value of the `rendering/rendering_device/d3d12/agility_sdk_version`
# project setting to match the minor version (e.g. for `1.613.3`, it should be `613`).
agility_sdk_version = "1.613.3"
agility_sdk_archive = os.path.join(deps_folder, f"Agility_SDK_{agility_sdk_version}.nupkg")
agility_sdk_folder = os.path.join(deps_folder, "agility_sdk")
# Create dependencies folder
if not os.path.exists(deps_folder):
os.makedirs(deps_folder)
# Mesa NIR
print("\x1b[1m[1/3] Mesa NIR\x1b[0m")
if os.path.isfile(mesa_archive):
os.remove(mesa_archive)
print(f"Downloading Mesa NIR {mesa_filename} ...")
urllib.request.urlretrieve(
f"https://github.com/godotengine/godot-nir-static/releases/download/{mesa_version}/{mesa_filename}",
mesa_archive,
)
if os.path.exists(mesa_folder):
print(f"Removing existing local Mesa NIR installation in {mesa_folder} ...")
shutil.rmtree(mesa_folder)
print(f"Extracting Mesa NIR {mesa_filename} to {mesa_folder} ...")
shutil.unpack_archive(mesa_archive, mesa_folder)
os.remove(mesa_archive)
print(f"Mesa NIR {mesa_filename} installed successfully.\n")
# WinPixEventRuntime
# MinGW needs DLLs converted with dlltool.
# We rely on finding gendef/dlltool to detect if we have MinGW.
# Check existence of needed tools for generating mingw library.
gendef = shutil.which("gendef") or ""
dlltool = shutil.which("dlltool") or ""
if dlltool == "":
dlltool = shutil.which("x86_64-w64-mingw32-dlltool") or ""
has_mingw = gendef != "" and dlltool != ""
print("\x1b[1m[2/3] WinPixEventRuntime\x1b[0m")
if os.path.isfile(pix_archive):
os.remove(pix_archive)
print(f"Downloading WinPixEventRuntime {pix_version} ...")
urllib.request.urlretrieve(f"https://www.nuget.org/api/v2/package/WinPixEventRuntime/{pix_version}", pix_archive)
if os.path.exists(pix_folder):
print(f"Removing existing local WinPixEventRuntime installation in {pix_folder} ...")
shutil.rmtree(pix_folder)
print(f"Extracting WinPixEventRuntime {pix_version} to {pix_folder} ...")
shutil.unpack_archive(pix_archive, pix_folder, "zip")
os.remove(pix_archive)
if has_mingw:
print("Adapting WinPixEventRuntime to also support MinGW alongside MSVC.")
cwd = os.getcwd()
os.chdir(pix_folder)
subprocess.run([gendef, "./bin/x64/WinPixEventRuntime.dll"])
subprocess.run(
[dlltool]
+ "--machine i386:x86-64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/x64/libWinPixEventRuntime.a".split()
)
subprocess.run([gendef, "./bin/ARM64/WinPixEventRuntime.dll"])
subprocess.run(
[dlltool]
+ "--machine arm64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/ARM64/libWinPixEventRuntime.a".split()
)
os.chdir(cwd)
else:
print("MinGW wasn't found, so only MSVC support is provided for WinPixEventRuntime.")
print(f"WinPixEventRuntime {pix_version} installed successfully.\n")
# DirectX 12 Agility SDK
print("\x1b[1m[3/3] DirectX 12 Agility SDK\x1b[0m")
if os.path.isfile(agility_sdk_archive):
os.remove(agility_sdk_archive)
print(f"Downloading DirectX 12 Agility SDK {agility_sdk_version} ...")
urllib.request.urlretrieve(
f"https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/{agility_sdk_version}", agility_sdk_archive
)
if os.path.exists(agility_sdk_folder):
print(f"Removing existing local DirectX 12 Agility SDK installation in {agility_sdk_folder} ...")
shutil.rmtree(agility_sdk_folder)
print(f"Extracting DirectX 12 Agility SDK {agility_sdk_version} to {agility_sdk_folder} ...")
shutil.unpack_archive(agility_sdk_archive, agility_sdk_folder, "zip")
os.remove(agility_sdk_archive)
print(f"DirectX 12 Agility SDK {agility_sdk_version} installed successfully.\n")
# Complete message
print(f'\x1b[92mAll Direct3D 12 SDK components were installed to "{deps_folder}" successfully!\x1b[0m')
print('\x1b[92mYou can now build Godot with Direct3D 12 support enabled by running "scons d3d12=yes".\x1b[0m')

View file

@ -0,0 +1,22 @@
#!/usr/bin/env sh
set -euo pipefail
IFS=$'\n\t'
# Download and install the Vulkan SDK.
curl -L "https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg" -o /tmp/vulkan-sdk.dmg
hdiutil attach /tmp/vulkan-sdk.dmg -mountpoint /Volumes/vulkan-sdk
/Volumes/vulkan-sdk/InstallVulkan.app/Contents/MacOS/InstallVulkan \
--accept-licenses --default-answer --confirm-command install
cnt=5
until hdiutil detach -force /Volumes/vulkan-sdk
do
[[ cnt -eq "0" ]] && break
sleep 1
((cnt--))
done
rm -f /tmp/vulkan-sdk.dmg
echo 'Vulkan SDK installed successfully! You can now build Godot by running "scons".'

View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Generate .ico, .icns and .zip set of icons for Steam
# Make icons with transparent backgrounds and all sizes
for s in 16 24 32 48 64 128 256 512 1024; do
convert -resize ${s}x$s -antialias \
-background transparent \
../../icon.svg icon$s.png
done
# 16px tga file for library
convert icon16.png icon16.tga
# zip for Linux
zip godot-icons.zip icon*.png
# ico for Windows
# Not including biggest ones or it blows up in size
icotool -c -o godot-icon.ico icon{16,24,32,48,64,128,256}.png
# icns for macOS
# Only some sizes: https://iconhandbook.co.uk/reference/chart/osx/
png2icns godot-icon.icns icon{16,32,128,256,512,1024}.png
rm -f icon*.png

View file

@ -0,0 +1,66 @@
#!/bin/sh
if [ ! -e "version.py" ]; then
echo "This script should be ran from the root folder of the Godot repository."
exit 1
fi
while getopts "h?sv:g:" opt; do
case "$opt" in
h|\?)
echo "Usage: $0 [OPTIONS...]"
echo
echo " -s script friendly file name (godot.tar.gz)"
echo " -v godot version for file name (e.g. 4.0-stable)"
echo " -g git treeish to archive (e.g. master)"
echo
exit 1
;;
s)
script_friendly_name=1
;;
v)
godot_version=$OPTARG
;;
g)
git_treeish=$OPTARG
;;
esac
done
if [ ! -z "$git_treeish" ]; then
HEAD=$(git rev-parse $git_treeish)
else
HEAD=$(git rev-parse HEAD)
fi
if [ ! -z "$script_friendly_name" ]; then
NAME=godot
else
if [ ! -z "$godot_version" ]; then
NAME=godot-$godot_version
else
NAME=godot-$HEAD
fi
fi
CURDIR=$(pwd)
TMPDIR=$(mktemp -d -t godot-XXXXXX)
echo "Generating tarball for revision $HEAD with folder name '$NAME'."
echo
echo "The tarball will be written to the parent folder:"
echo " $(dirname $CURDIR)/$NAME.tar.gz"
git archive $HEAD --prefix=$NAME/ -o $TMPDIR/$NAME.tar
# Adding custom .git/HEAD to tarball so that we can generate VERSION_HASH.
cd $TMPDIR
mkdir -p $NAME/.git
echo $HEAD > $NAME/.git/HEAD
tar -uf $NAME.tar $NAME
cd $CURDIR
gzip -c $TMPDIR/$NAME.tar > ../$NAME.tar.gz
rm -rf $TMPDIR

View file

@ -0,0 +1,83 @@
#!/bin/bash
set -o pipefail
if [ ! -f "version.py" ]; then
echo "Warning: This script is intended to be run from the root of the Godot repository."
echo "Some of the paths checks may not work as intended from a different folder."
fi
if [ $# != 1 ]; then
echo "Usage: @0 <path-to-godot-executable>"
fi
api_validation_dir="$( dirname -- "$( dirname -- "${BASH_SOURCE[0]//\.\//}" )" )/extension_api_validation/"
has_problems=0
warn_extra=0
reference_tag=""
expected_errors=""
make_annotation()
{
local title=$1
local body=$2
local type=$3
local file=$4
if [[ "$GITHUB_OUTPUT" == "" ]]; then
echo "$title"
echo "$body"
else
body="$(awk 1 ORS='%0A' - <<<"$body")"
echo "::$type file=$file,title=$title ::$body"
fi
}
get_expected_output()
{
local parts=()
IFS='_' read -ra parts <<< "$(basename -s .expected "$1")"
if [[ "${#parts[@]}" == "2" ]]; then
cat "$1" >> "$expected_errors"
get_expected_output "$(find "$api_validation_dir" -name "${parts[1]}*.expected")"
reference_tag="${parts[0]}"
warn_extra=0
else
cat "$1" >> "$expected_errors"
reference_tag="${parts[0]}"
warn_extra=1
fi
}
while read -r file; do
reference_file="$(mktemp)"
validate="$(mktemp)"
validation_output="$(mktemp)"
allowed_errors="$(mktemp)"
expected_errors="$(mktemp)"
get_expected_output "$file"
# Download the reference extension_api.json
wget -nv --retry-on-http-error=503 --tries=5 --timeout=60 -cO "$reference_file" "https://raw.githubusercontent.com/godotengine/godot-cpp/godot-$reference_tag/gdextension/extension_api.json" || has_problems=1
# Validate the current API against the reference
"$1" --headless --validate-extension-api "$reference_file" 2>&1 | tee "$validate" | awk '!/^Validate extension JSON:/' - || true
# Collect the expected and actual validation errors
awk '/^Validate extension JSON:/' - < "$validate" | sort > "$validation_output"
awk '/^Validate extension JSON:/' - < "$expected_errors" | sort > "$allowed_errors"
# Differences between the expected and actual errors
new_validation_error="$(comm -23 "$validation_output" "$allowed_errors")"
obsolete_validation_error="$(comm -13 "$validation_output" "$allowed_errors")"
if [ -n "$obsolete_validation_error" ] && [ "$warn_extra" = "1" ]; then
make_annotation "The following validation errors no longer occur (compared to $reference_tag):" "$obsolete_validation_error" warning "$file"
fi
if [ -n "$new_validation_error" ]; then
make_annotation "Compatibility to $reference_tag is broken in the following ways:" "$new_validation_error" error "$file"
has_problems=1
fi
rm -f "$reference_file" "$validate" "$validation_output" "$allowed_errors" "$expected_errors"
done <<< "$(find "$api_validation_dir" -name "*.expected")"
exit $has_problems