diff options
Diffstat (limited to 'misc/scripts')
-rwxr-xr-x | misc/scripts/black_format.sh | 20 | ||||
-rwxr-xr-x | misc/scripts/check_ci_log.py | 2 | ||||
-rwxr-xr-x | misc/scripts/clang_format.sh | 59 | ||||
-rwxr-xr-x | misc/scripts/clang_tidy.sh | 31 | ||||
-rwxr-xr-x | misc/scripts/codespell.sh | 5 | ||||
-rwxr-xr-x | misc/scripts/compare_extension_api.py | 11 | ||||
-rwxr-xr-x | misc/scripts/copyright_headers.py | 4 | ||||
-rwxr-xr-x | misc/scripts/file_format.sh | 19 | ||||
-rwxr-xr-x | misc/scripts/header_guards.sh | 61 | ||||
-rwxr-xr-x | misc/scripts/install_vulkan_sdk_macos.sh | 14 |
10 files changed, 166 insertions, 60 deletions
diff --git a/misc/scripts/black_format.sh b/misc/scripts/black_format.sh index 2ad9a23832..f6fac58e50 100755 --- a/misc/scripts/black_format.sh +++ b/misc/scripts/black_format.sh @@ -6,28 +6,20 @@ set -uo pipefail # Apply black. echo -e "Formatting Python files..." -PY_FILES=$(find \( -path "./.git" \ - -o -path "./thirdparty" \ - \) -prune \ - -o \( -name "SConstruct" \ - -o -name "SCsub" \ - -o -name "*.py" \ - \) -print) +PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*') black -l 120 $PY_FILES -git diff --color > patch.patch +diff=$(git diff --color) -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; then +# 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 black style rules.\n" - rm -f patch.patch exit 0 fi -# A patch has been created, notify the user, clean up, and exit. +# 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" -cat patch.patch +echo "$diff" printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" -rm -f patch.patch exit 1 diff --git a/misc/scripts/check_ci_log.py b/misc/scripts/check_ci_log.py index 2c75b83bd7..1e5a12eeb4 100755 --- a/misc/scripts/check_ci_log.py +++ b/misc/scripts/check_ci_log.py @@ -25,6 +25,8 @@ 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) diff --git a/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh index bcd63aa73b..2b7179f5be 100755 --- a/misc/scripts/clang_format.sh +++ b/misc/scripts/clang_format.sh @@ -4,55 +4,40 @@ # This is the primary script responsible for fixing style violations. set -uo pipefail -IFS=$'\n\t' -CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl") +# 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.*' | +while read -r f; do + # Run clang-format. + clang-format --Wno-error=unknown -i "$f" -# Loops through all text files tracked by Git. -git grep -zIl '' | -while IFS= read -rd '' f; do - # Exclude some files. - if [[ "$f" == "thirdparty"* ]]; then + # Fix copyright headers, but not all files get them. + if [[ "$f" == *"inc" ]]; then continue - elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then + elif [[ "$f" == *"glsl" ]]; then continue - elif [[ "$f" == *"-so_wrap."* ]]; then + elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView"* ]]; then + continue + elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper"* ]]; then + continue + elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix"* ]]; then continue fi - for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do - if [[ "$f" == *"$extension" ]]; then - # Run clang-format. - clang-format -i "$f" - # Fix copyright headers, but not all files get them. - if [[ "$f" == *"inc" ]]; then - continue 2 - elif [[ "$f" == *"glsl" ]]; then - continue 2 - elif [[ "$f" == *"theme_data.h" ]]; then - continue 2 - elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then - continue 2 - fi - python misc/scripts/copyright_headers.py "$f" - continue 2 - fi - done + python misc/scripts/copyright_headers.py "$f" done -git diff --color > patch.patch +diff=$(git diff --color) -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; then +# 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 clang-format style rules.\n" - rm -f patch.patch exit 0 fi -# A patch 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" -cat patch.patch -printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" -rm -f patch.patch +# 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/clang_tidy.sh b/misc/scripts/clang_tidy.sh new file mode 100755 index 0000000000..63c1b10042 --- /dev/null +++ b/misc/scripts/clang_tidy.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# This script runs clang-tidy on all relevant files in the repo. +# This is more thorough than clang-format and thus slower; it should only be run manually. + +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.*' | +while read -r f; do + # Run clang-tidy. + clang-tidy --quiet --fix "$f" &> /dev/null + + # Run clang-format. This also fixes the output of clang-tidy. + clang-format --Wno-error=unknown -i "$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 clang-tidy 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/codespell.sh b/misc/scripts/codespell.sh new file mode 100755 index 0000000000..f99c5d22b2 --- /dev/null +++ b/misc/scripts/codespell.sh @@ -0,0 +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" + +codespell -w -q 3 -S "${SKIP_LIST}" -L "${IGNORE_LIST}" diff --git a/misc/scripts/compare_extension_api.py b/misc/scripts/compare_extension_api.py new file mode 100755 index 0000000000..f96db4278c --- /dev/null +++ b/misc/scripts/compare_extension_api.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys + +# TODO: +# Add a process that compares the original godot-cpp/godot-headers/extension_api.json with the new extension_api.json (both passed as arguments) and reports any API calls that have been removed. +# If we only have additions or no changes to the file, we pass +# For now we deem this too early because the API isn't stable enough yet. + +sys.exit(0) diff --git a/misc/scripts/copyright_headers.py b/misc/scripts/copyright_headers.py index 2f3e4a1b6a..cf3adbfbfa 100755 --- a/misc/scripts/copyright_headers.py +++ b/misc/scripts/copyright_headers.py @@ -11,8 +11,8 @@ header = """\ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/misc/scripts/file_format.sh b/misc/scripts/file_format.sh index 0b49b175f2..731b3ee005 100755 --- a/misc/scripts/file_format.sh +++ b/misc/scripts/file_format.sh @@ -20,6 +20,11 @@ while IFS= read -rd '' f; do continue elif [[ "$f" == *"sln" ]]; then continue + elif [[ "$f" == *".bat" ]]; then + continue + elif [[ "$f" == *".out" ]]; then + # GDScript integration testing files. + continue elif [[ "$f" == *"patch" ]]; then continue elif [[ "$f" == *"pot" ]]; then @@ -32,6 +37,8 @@ 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 @@ -42,19 +49,17 @@ while IFS= read -rd '' f; do perl -i -ple 's/\s*$//g' "$f" done -git diff --color > patch.patch +diff=$(git diff --color) -# If no patch has been generated all is OK, clean up, and exit. -if [ ! -s patch.patch ] ; then +# 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 formatting rules.\n" - rm -f patch.patch exit 0 fi -# A patch has been created, notify the user, clean up, and exit. +# 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" -cat patch.patch +echo "$diff" printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n" -rm -f patch.patch exit 1 diff --git a/misc/scripts/header_guards.sh b/misc/scripts/header_guards.sh new file mode 100755 index 0000000000..9a830f3ad2 --- /dev/null +++ b/misc/scripts/header_guards.sh @@ -0,0 +1,61 @@ +#!/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 + +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 + + 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" +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 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 new file mode 100755 index 0000000000..d78659fa9f --- /dev/null +++ b/misc/scripts/install_vulkan_sdk_macos.sh @@ -0,0 +1,14 @@ +#!/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 +hdiutil detach /Volumes/vulkan-sdk +rm -f /tmp/vulkan-sdk.dmg + +echo 'Vulkan SDK installed successfully! You can now build Godot by running "scons".' |