Skip to content

Commit 82bc102

Browse files
committed
Sync misc/ scripts and hooks with upstream Godot
1 parent 1632322 commit 82bc102

11 files changed

+63
-81
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
7979
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
8080
endif(CMAKE_BUILD_TYPE MATCHES Debug)
8181

82-
# Disable conversion warning, truncation, unreferenced var, signed missmatch, different type
82+
# Disable conversion warning, truncation, unreferenced var, signed mismatch, different type
8383
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267 /wd4099")
8484

8585
# Todo: Check if needed.

misc/hooks/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ contributors to make sure they comply with our requirements.
1212
`PATH`, or if you want to enable colored output with `pygmentize`.
1313
- Pre-commit hook for `black`: Applies `black` to the staged Python files
1414
before accepting a commit.
15+
- Pre-commit hook for `make_rst`: Checks the class reference syntax using
16+
`make_rst.py`.
1517

1618
## Installation
1719

@@ -26,7 +28,7 @@ so they should work out of the box on Linux/macOS.
2628
#### Windows
2729

2830
##### clang-format
29-
- Download LLVM for Windows (version 8 or later) from
31+
- Download LLVM for Windows (version 13 or later) from
3032
<https://releases.llvm.org/download.html>
3133
- Make sure LLVM is added to the `PATH` during installation
3234

misc/hooks/canonicalize_filename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# specified filename. This should reproduce the results of the GNU version of
1717
# readlink with the -f option.
1818
#
19-
# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
19+
# Reference: https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
2020
canonicalize_filename () {
2121
local target_file="$1"
2222
local physical_directory=""

misc/hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# as this script. Hooks should return 0 if successful and nonzero to cancel the
1515
# commit. They are executed in the order in which they are listed.
1616
#HOOKS="pre-commit-compile pre-commit-uncrustify"
17-
HOOKS="pre-commit-clang-format pre-commit-black"
17+
HOOKS="pre-commit-clang-format pre-commit-black pre-commit-make-rst"
1818
###########################################################
1919
# There should be no need to change anything below this line.
2020

misc/hooks/pre-commit-black

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DELETE_OLD_PATCHES=false
1414

1515
# File types to parse.
1616
FILE_NAMES="SConstruct SCsub"
17-
FILE_EXTS="py"
17+
FILE_EXTS=".py"
1818

1919
# Use pygmentize instead of cat to parse diff with highlighting.
2020
# Install it with `pip install pygments` (Linux) or `easy_install Pygments` (Mac)
@@ -139,33 +139,33 @@ fi
139139
while true; do
140140
if [ $terminal = "0" ] ; then
141141
if [ -x "$ZENITY" ] ; then
142-
ans=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage")
142+
choice=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage")
143143
if [ "$?" = "0" ] ; then
144144
yn="Y"
145145
else
146-
if [ "$ans" = "Apply and stage" ] ; then
146+
if [ "$choice" = "Apply and stage" ] ; then
147147
yn="S"
148148
else
149149
yn="N"
150150
fi
151151
fi
152152
elif [ -x "$XMSG" ] ; then
153153
$XMSG -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?"
154-
ans=$?
155-
if [ "$ans" = "100" ] ; then
154+
choice=$?
155+
if [ "$choice" = "100" ] ; then
156156
yn="Y"
157-
elif [ "$ans" = "200" ] ; then
157+
elif [ "$choice" = "200" ] ; then
158158
yn="S"
159159
else
160160
yn="N"
161161
fi
162162
elif [ \( \( "$OSTYPE" = "msys" \) -o \( "$OSTYPE" = "win32" \) \) -a \( -x "$PWSH" \) ]; then
163163
winmessage="$(canonicalize_filename "./.git/hooks/winmessage.ps1")"
164164
$PWSH -noprofile -executionpolicy bypass -file "$winmessage" -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?"
165-
ans=$?
166-
if [ "$ans" = "100" ] ; then
165+
choice=$?
166+
if [ "$choice" = "100" ] ; then
167167
yn="Y"
168-
elif [ "$ans" = "200" ] ; then
168+
elif [ "$choice" = "200" ] ; then
169169
yn="S"
170170
else
171171
yn="N"

misc/hooks/pre-commit-clang-format

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ fi
7676

7777
# To get consistent formatting, we recommend contributors to use the same
7878
# clang-format version as CI.
79-
RECOMMENDED_CLANG_FORMAT_MAJOR_MIN="11"
80-
RECOMMENDED_CLANG_FORMAT_MAJOR_MAX="12"
79+
RECOMMENDED_CLANG_FORMAT_MAJOR_MIN="12"
80+
RECOMMENDED_CLANG_FORMAT_MAJOR_MAX="13"
8181

8282
if [ ! -x "$CLANG_FORMAT" ] ; then
83-
message="Error: clang-format executable not found. Please install clang-format $RECOMMENDED_CLANG_FORMAT_MAJOR.x.x."
83+
message="Error: clang-format executable not found. Please install clang-format $RECOMMENDED_CLANG_FORMAT_MAJOR_MAX."
8484

8585
if [ ! -t 1 ] ; then
8686
if [ -x "$ZENITY" ] ; then
@@ -108,7 +108,7 @@ CLANG_FORMAT_VERSION="$(clang-format --version | sed "s/[^0-9\.]*\([0-9\.]*\).*/
108108
CLANG_FORMAT_MAJOR="$(echo "$CLANG_FORMAT_VERSION" | cut -d. -f1)"
109109

110110
if [[ "$CLANG_FORMAT_MAJOR" -lt "$RECOMMENDED_CLANG_FORMAT_MAJOR_MIN" || "$CLANG_FORMAT_MAJOR" -gt "$RECOMMENDED_CLANG_FORMAT_MAJOR_MAX" ]]; then
111-
echo "Warning: Your clang-format binary is the wrong version ($CLANG_FORMAT_VERSION, expected between $RECOMMENDED_CLANG_FORMAT_MAJOR_MIN.x.x and $RECOMMENDED_CLANG_FORMAT_MAJOR_MAX.x.x)."
111+
echo "Warning: Your clang-format binary is the wrong version ($CLANG_FORMAT_VERSION, expected between $RECOMMENDED_CLANG_FORMAT_MAJOR_MIN and $RECOMMENDED_CLANG_FORMAT_MAJOR_MAX)."
112112
echo " Consider upgrading or downgrading clang-format as formatting may not be applied correctly."
113113
fi
114114

@@ -146,7 +146,7 @@ do
146146
# +++ - timestamp
147147
# to both lines working on the same file and having a/ and b/ prefix.
148148
# Else it can not be applied with 'git apply'.
149-
"$CLANG_FORMAT" -style=file "$file" | \
149+
"$CLANG_FORMAT" -style=file "$file" --Wno-error=unknown | \
150150
diff -u "$file" - | \
151151
sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch"
152152
done
@@ -179,33 +179,33 @@ fi
179179
while true; do
180180
if [ $terminal = "0" ] ; then
181181
if [ -x "$ZENITY" ] ; then
182-
ans=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage")
182+
choice=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage")
183183
if [ "$?" = "0" ] ; then
184184
yn="Y"
185185
else
186-
if [ "$ans" = "Apply and stage" ] ; then
186+
if [ "$choice" = "Apply and stage" ] ; then
187187
yn="S"
188188
else
189189
yn="N"
190190
fi
191191
fi
192192
elif [ -x "$XMSG" ] ; then
193193
$XMSG -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?"
194-
ans=$?
195-
if [ "$ans" = "100" ] ; then
194+
choice=$?
195+
if [ "$choice" = "100" ] ; then
196196
yn="Y"
197-
elif [ "$ans" = "200" ] ; then
197+
elif [ "$choice" = "200" ] ; then
198198
yn="S"
199199
else
200200
yn="N"
201201
fi
202202
elif [ \( \( "$OSTYPE" = "msys" \) -o \( "$OSTYPE" = "win32" \) \) -a \( -x "$PWSH" \) ]; then
203203
winmessage="$(canonicalize_filename "./.git/hooks/winmessage.ps1")"
204204
$PWSH -noprofile -executionpolicy bypass -file "$winmessage" -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?"
205-
ans=$?
206-
if [ "$ans" = "100" ] ; then
205+
choice=$?
206+
if [ "$choice" = "100" ] ; then
207207
yn="Y"
208-
elif [ "$ans" = "200" ] ; then
208+
elif [ "$choice" = "200" ] ; then
209209
yn="S"
210210
else
211211
yn="N"

misc/scripts/black_format.sh

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,20 @@ set -uo pipefail
66

77
# Apply black.
88
echo -e "Formatting Python files..."
9-
PY_FILES=$(find \( -path "./.git" \
10-
-o -path "./thirdparty" \
11-
\) -prune \
12-
-o \( -name "SConstruct" \
13-
-o -name "SCsub" \
14-
-o -name "*.py" \
15-
\) -print)
9+
PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*')
1610
black -l 120 $PY_FILES
1711

18-
git diff > patch.patch
12+
diff=$(git diff --color)
1913

2014
# If no patch has been generated all is OK, clean up, and exit.
21-
if [ ! -s patch.patch ] ; then
15+
if [ -z "$diff" ] ; then
2216
printf "Files in this commit comply with the black style rules.\n"
23-
rm -f patch.patch
2417
exit 0
2518
fi
2619

2720
# A patch has been created, notify the user, clean up, and exit.
2821
printf "\n*** The following differences were found between the code "
2922
printf "and the formatting rules:\n\n"
30-
cat patch.patch
23+
echo "$diff"
3124
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
32-
rm -f patch.patch
3325
exit 1

misc/scripts/clang_format.sh

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,36 @@
44
# This is the primary script responsible for fixing style violations.
55

66
set -uo pipefail
7-
IFS=$'\n\t'
87

9-
CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl")
8+
# Loops through all code files tracked by Git.
9+
git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \
10+
':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' |
11+
while read -r f; do
12+
# Run clang-format.
13+
clang-format --Wno-error=unknown -i "$f"
1014

11-
# Loops through all text files tracked by Git.
12-
git grep -zIl '' |
13-
while IFS= read -rd '' f; do
14-
# Exclude some files.
15-
if [[ "$f" == "thirdparty"* ]]; then
15+
# Fix copyright headers, but not all files get them.
16+
if [[ "$f" == *"inc" ]]; then
1617
continue
17-
# elif [[ "$f" == "gen"* ]]; then
18-
# continue
19-
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
18+
elif [[ "$f" == *"glsl" ]]; then
2019
continue
21-
elif [[ "$f" == *"-so_wrap."* ]]; then
20+
elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then
2221
continue
2322
fi
2423

25-
for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do
26-
if [[ "$f" == *"$extension" ]]; then
27-
# Run clang-format.
28-
clang-format -i "$f"
29-
# Fix copyright headers, but not all files get them.
30-
if [[ "$f" == *"inc" ]]; then
31-
continue 2
32-
elif [[ "$f" == *"glsl" ]]; then
33-
continue 2
34-
elif [[ "$f" == *"theme_data.h" ]]; then
35-
continue 2
36-
elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then
37-
continue 2
38-
fi
39-
python misc/scripts/copyright_headers.py "$f"
40-
continue 2
41-
fi
42-
done
24+
python misc/scripts/copyright_headers.py "$f"
4325
done
4426

45-
git diff > patch.patch
27+
diff=$(git diff --color)
4628

4729
# If no patch has been generated all is OK, clean up, and exit.
48-
if [ ! -s patch.patch ] ; then
49-
printf "Files in this commit comply with the clang-format style rules.\n"
50-
rm -f patch.patch
30+
if [ -z "$diff" ] ; then
31+
printf "Files in this commit comply with the clang-tidy style rules.\n"
5132
exit 0
5233
fi
5334

5435
# A patch has been created, notify the user, clean up, and exit.
55-
printf "\n*** The following differences were found between the code "
56-
printf "and the formatting rules:\n\n"
57-
cat patch.patch
58-
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
59-
rm -f patch.patch
36+
printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
37+
echo "$diff"
38+
printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
6039
exit 1

misc/scripts/codespell.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
SKIP_LIST="./thirdparty,*.gen.*,*.po,*.pot,package-lock.json,./core/string/locales.h,./DONORS.md,./misc/scripts/codespell.sh"
3+
IGNORE_LIST="ba,childs,curvelinear,expct,fave,findn,gird,inout,lod,nd,numer,ois,ro,statics,te,varn"
4+
5+
codespell -w -q 3 -S "${SKIP_LIST}" -L "${IGNORE_LIST}"

misc/scripts/file_format.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ while IFS= read -rd '' f; do
2020
continue
2121
elif [[ "$f" == *"sln" ]]; then
2222
continue
23+
elif [[ "$f" == *".bat" ]]; then
24+
continue
25+
elif [[ "$f" == *".out" ]]; then
26+
# GDScript integration testing files.
27+
continue
2328
elif [[ "$f" == *"patch" ]]; then
2429
continue
2530
elif [[ "$f" == *"pot" ]]; then
@@ -42,10 +47,10 @@ while IFS= read -rd '' f; do
4247
perl -i -ple 's/\s*$//g' "$f"
4348
done
4449

45-
git diff > patch.patch
50+
diff=$(git diff --color)
4651

4752
# If no patch has been generated all is OK, clean up, and exit.
48-
if [ ! -s patch.patch ] ; then
53+
if [ -z "$diff" ] ; then
4954
printf "Files in this commit comply with the formatting rules.\n"
5055
rm -f patch.patch
5156
exit 0
@@ -54,7 +59,6 @@ fi
5459
# A patch has been created, notify the user, clean up, and exit.
5560
printf "\n*** The following differences were found between the code "
5661
printf "and the formatting rules:\n\n"
57-
cat patch.patch
62+
echo "$diff"
5863
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
59-
rm -f patch.patch
6064
exit 1

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
4747
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
4848
endif(CMAKE_BUILD_TYPE MATCHES Debug)
4949

50-
# Disable conversion warning, trunkation, unreferenced var, signed missmatch
50+
# Disable conversion warning, truncation, unreferenced var, signed mismatch
5151
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
5252

5353
# Todo: Check if needed.

0 commit comments

Comments
 (0)