diff options
Diffstat (limited to 'misc/scripts')
-rwxr-xr-x | misc/scripts/clang_format.sh | 3 | ||||
-rwxr-xr-x | misc/scripts/codespell.sh | 2 | ||||
-rwxr-xr-x | misc/scripts/dotnet_format.sh | 35 | ||||
-rwxr-xr-x | misc/scripts/file_format.sh | 29 | ||||
-rwxr-xr-x | misc/scripts/header_guards.sh | 78 | ||||
-rwxr-xr-x | misc/scripts/install_vulkan_sdk_macos.sh | 2 | ||||
-rw-r--r-- | misc/scripts/mypy.ini | 11 | ||||
-rwxr-xr-x | misc/scripts/mypy_check.sh | 6 | ||||
-rwxr-xr-x | misc/scripts/pytest_builders.sh | 5 |
9 files changed, 161 insertions, 10 deletions
diff --git a/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh index 2b7179f5be..edecdb6ecb 100755 --- a/misc/scripts/clang_format.sh +++ b/misc/scripts/clang_format.sh @@ -7,7 +7,8 @@ set -uo pipefail # Loops through all code files tracked by Git. git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \ - ':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' | + ':!:.git/*' ':!:thirdparty/*' ':!:*/thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' \ + ':!:*-so_wrap.*' ':!:tests/python_build/*' | while read -r f; do # Run clang-format. clang-format --Wno-error=unknown -i "$f" diff --git a/misc/scripts/codespell.sh b/misc/scripts/codespell.sh index f99c5d22b2..4cc01ec637 100755 --- a/misc/scripts/codespell.sh +++ b/misc/scripts/codespell.sh @@ -1,5 +1,5 @@ #!/bin/sh SKIP_LIST="./thirdparty,*.gen.*,*.po,*.pot,package-lock.json,./core/string/locales.h,./DONORS.md,./misc/dist/linux/org.godotengine.Godot.desktop,./misc/scripts/codespell.sh" -IGNORE_LIST="ba,childs,complies,curvelinear,expct,fave,findn,gird,inout,lod,nd,numer,ois,ro,statics,te,varius,varn" +IGNORE_LIST="alo,ba,childs,complies,curvelinear,doubleclick,expct,fave,findn,gird,gud,inout,lod,nd,numer,ois,readded,ro,sav,statics,te,varius,varn,wan" codespell -w -q 3 -S "${SKIP_LIST}" -L "${IGNORE_LIST}" diff --git a/misc/scripts/dotnet_format.sh b/misc/scripts/dotnet_format.sh new file mode 100755 index 0000000000..cc34137a37 --- /dev/null +++ b/misc/scripts/dotnet_format.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# This script runs dotnet format on all relevant files in the repo. +# This is the primary script responsible for fixing style violations in C# files. + +set -uo pipefail + +# Create dummy generated files. +echo "<Project />" > modules/mono/SdkPackageVersions.props +mkdir -p modules/mono/glue/GodotSharp/GodotSharp/Generated +echo "<Project />" > modules/mono/glue/GodotSharp/GodotSharp/Generated/GeneratedIncludes.props +mkdir -p modules/mono/glue/GodotSharp/GodotSharpEditor/Generated +echo "<Project />" > modules/mono/glue/GodotSharp/GodotSharpEditor/Generated/GeneratedIncludes.props + +# Loops through all C# projects tracked by Git. +git ls-files -- '*.csproj' \ + ':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' | +while read -r f; do + # Run dotnet format. + dotnet format "$f" +done + +diff=$(git diff --color) + +# If no diff has been generated all is OK, clean up, and exit. +if [ -z "$diff" ] ; then + printf "Files in this commit comply with the dotnet format style rules.\n" + exit 0 +fi + +# A diff has been created, notify the user, clean up, and exit. +printf "\n*** The following changes have been made to comply with the formatting rules:\n\n" +echo "$diff" +printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" +exit 1 diff --git a/misc/scripts/file_format.sh b/misc/scripts/file_format.sh index c767d3f8a0..1200b96ea0 100755 --- a/misc/scripts/file_format.sh +++ b/misc/scripts/file_format.sh @@ -37,9 +37,11 @@ while IFS= read -rd '' f; do continue elif [[ "$f" == *"-so_wrap."* ]]; then continue + elif [[ "$f" == *".test.txt" ]]; then + continue fi # Ensure that files are UTF-8 formatted. - recode UTF-8 "$f" 2> /dev/null + isutf8 "$f" >> utf8-validation.txt 2>&1 # Ensure that files have LF line endings and do not contain a BOM. dos2unix "$f" 2> /dev/null # Remove trailing space characters and ensures that files end @@ -49,15 +51,28 @@ done diff=$(git diff --color) -# If no diff has been generated all is OK, clean up, and exit. -if [ -z "$diff" ] ; then +# If no UTF-8 violations were collected and no diff has been +# generated all is OK, clean up, and exit. +if [ ! -s utf8-validation.txt ] && [ -z "$diff" ] ; then printf "Files in this commit comply with the formatting rules.\n" + rm -f utf8-violations.txt exit 0 fi -# A diff has been created, notify the user, clean up, and exit. -printf "\n*** The following differences were found between the code " -printf "and the formatting rules:\n\n" -echo "$diff" +# Violations detected, notify the user, clean up, and exit. +if [ -s utf8-validation.txt ] +then + printf "\n*** The following files contain invalid UTF-8 character sequences:\n\n" + cat utf8-validation.txt + rm -f utf8-validation.txt +fi + +if [ ! -z "$diff" ] +then + printf "\n*** The following differences were found between the code " + printf "and the formatting rules:\n\n" + echo "$diff" +fi + printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" exit 1 diff --git a/misc/scripts/header_guards.sh b/misc/scripts/header_guards.sh new file mode 100755 index 0000000000..9fdc864f8c --- /dev/null +++ b/misc/scripts/header_guards.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +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 + +files_invalid_guard="" + +for file in $(find -name "thirdparty" -prune -o -name "*.h" -print); do + # Skip *.gen.h and *-so_wrap.h, they're generated. + if [[ "$file" == *".gen.h" || "$file" == *"-so_wrap.h" ]]; then continue; fi + # Has important define before normal header guards. + if [[ "$file" == *"thread.h" || "$file" == *"platform_config.h" ]]; then continue; fi + # Obj-C files don't use header guards. + if grep -q "#import " "$file"; then continue; fi + + bname=$(basename $file .h) + + # Add custom prefix or suffix for generic filenames with a well-defined namespace. + + prefix= + if [[ "$file" == "./modules/"*"/register_types.h" ]]; then + module=$(echo $file | sed "s@.*modules/\([^/]*\).*@\1@") + prefix="${module^^}_" + fi + if [[ "$file" == "./platform/"*"/api/api.h" || "$file" == "./platform/"*"/export/"* ]]; then + platform=$(echo $file | sed "s@.*platform/\([^/]*\).*@\1@") + prefix="${platform^^}_" + fi + if [[ "$file" == "./modules/mono/utils/"* && "$bname" != *"mono"* ]]; then prefix="MONO_"; fi + if [[ "$file" == "./servers/rendering/storage/utilities.h" ]]; then prefix="RENDERER_"; fi + + suffix= + if [[ "$file" == *"dummy"* && "$bname" != *"dummy"* ]]; then suffix="_DUMMY"; fi + if [[ "$file" == *"gles3"* && "$bname" != *"gles3"* ]]; then suffix="_GLES3"; fi + if [[ "$file" == *"renderer_rd"* && "$bname" != *"rd"* ]]; then suffix="_RD"; fi + if [[ "$file" == *"ustring.h" ]]; then suffix="_GODOT"; fi + + # ^^ is bash builtin for UPPERCASE. + guard="${prefix}${bname^^}${suffix}_H" + + # Replaces guards to use computed name. + # We also add some \n to make sure there's a proper separation. + sed -i $file -e "0,/ifndef/s/#ifndef.*/\n#ifndef $guard/" + sed -i $file -e "0,/define/s/#define.*/#define $guard\n/" + sed -i $file -e "$ s/#endif.*/\n#endif \/\/ $guard/" + # Removes redundant \n added before, if they weren't needed. + sed -i $file -e "/^$/N;/^\n$/D" + + # Check that first ifndef (should be header guard) is at the expected position. + # If not it can mean we have some code before the guard that should be after. + # "31" is the expected line with the copyright header. + first_ifndef=$(grep -n -m 1 "ifndef" $file | sed 's/\([0-9]*\).*/\1/') + if [[ "$first_ifndef" != "31" ]]; then + files_invalid_guard+="$file\n" + fi +done + +if [[ ! -z "$files_invalid_guard" ]]; then + echo -e "The following files were found to have potentially invalid header guard:\n" + echo -e "$files_invalid_guard" +fi + +diff=$(git diff --color) + +# If no diff has been generated all is OK, clean up, and exit. +if [ -z "$diff" ] ; then + printf "Files in this commit comply with the header guards formatting rules.\n" + exit 0 +fi + +# A diff has been created, notify the user, clean up, and exit. +printf "\n*** The following differences were found between the code " +printf "and the header guards formatting rules:\n\n" +echo "$diff" +printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" +exit 1 diff --git a/misc/scripts/install_vulkan_sdk_macos.sh b/misc/scripts/install_vulkan_sdk_macos.sh index 817302d77f..d78659fa9f 100755 --- a/misc/scripts/install_vulkan_sdk_macos.sh +++ b/misc/scripts/install_vulkan_sdk_macos.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh set -euo pipefail IFS=$'\n\t' diff --git a/misc/scripts/mypy.ini b/misc/scripts/mypy.ini new file mode 100644 index 0000000000..c1ea695ca5 --- /dev/null +++ b/misc/scripts/mypy.ini @@ -0,0 +1,11 @@ +[mypy] +ignore_missing_imports = true +disallow_any_generics = True +pretty = True +show_column_numbers = True +warn_redundant_casts = True +warn_return_any = True +warn_unreachable = True + +namespace_packages = True +explicit_package_bases = True diff --git a/misc/scripts/mypy_check.sh b/misc/scripts/mypy_check.sh new file mode 100755 index 0000000000..2a06486d67 --- /dev/null +++ b/misc/scripts/mypy_check.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -uo pipefail + +echo -e "Python: mypy static analysis..." +mypy --config-file=./misc/scripts/mypy.ini . diff --git a/misc/scripts/pytest_builders.sh b/misc/scripts/pytest_builders.sh new file mode 100755 index 0000000000..eb2ddbcddc --- /dev/null +++ b/misc/scripts/pytest_builders.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -uo pipefail + +echo "Running Python checks for builder system" +pytest ./tests/python_build |