summaryrefslogtreecommitdiff
path: root/misc/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'misc/hooks')
-rw-r--r--misc/hooks/README.md6
-rwxr-xr-xmisc/hooks/canonicalize_filename.sh4
-rwxr-xr-xmisc/hooks/pre-commit2
-rwxr-xr-xmisc/hooks/pre-commit-black2
-rwxr-xr-xmisc/hooks/pre-commit-clang-format32
-rwxr-xr-xmisc/hooks/pre-commit-make-rst (renamed from misc/hooks/pre-commit-makerst)4
-rw-r--r--[-rwxr-xr-x]misc/hooks/winmessage.ps10
7 files changed, 36 insertions, 14 deletions
diff --git a/misc/hooks/README.md b/misc/hooks/README.md
index 5661c239ed..8732237244 100644
--- a/misc/hooks/README.md
+++ b/misc/hooks/README.md
@@ -12,8 +12,8 @@ contributors to make sure they comply with our requirements.
`PATH`, or if you want to enable colored output with `pygmentize`.
- Pre-commit hook for `black`: Applies `black` to the staged Python files
before accepting a commit.
-- Pre-commit hook for `makerst`: Checks the class reference syntax using
- `makerst.py`.
+- Pre-commit hook for `make_rst`: Checks the class reference syntax using
+ `make_rst.py`.
## Installation
@@ -28,7 +28,7 @@ so they should work out of the box on Linux/macOS.
#### Windows
##### clang-format
-- Download LLVM for Windows (version 8 or later) from
+- Download LLVM for Windows (version 13 or later) from
<https://releases.llvm.org/download.html>
- Make sure LLVM is added to the `PATH` during installation
diff --git a/misc/hooks/canonicalize_filename.sh b/misc/hooks/canonicalize_filename.sh
index 5eecabf5bc..fe66999d8c 100755
--- a/misc/hooks/canonicalize_filename.sh
+++ b/misc/hooks/canonicalize_filename.sh
@@ -13,10 +13,10 @@
# There should be no need to change anything below this line.
# Canonicalize by recursively following every symlink in every component of the
-# specified filename. This should reproduce the results of the GNU version of
+# specified filename. This should reproduce the results of the GNU version of
# readlink with the -f option.
#
-# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
+# Reference: https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
canonicalize_filename () {
local target_file="$1"
local physical_directory=""
diff --git a/misc/hooks/pre-commit b/misc/hooks/pre-commit
index 40cb00253b..ab0fc8176f 100755
--- a/misc/hooks/pre-commit
+++ b/misc/hooks/pre-commit
@@ -14,7 +14,7 @@
# as this script. Hooks should return 0 if successful and nonzero to cancel the
# commit. They are executed in the order in which they are listed.
#HOOKS="pre-commit-compile pre-commit-uncrustify"
-HOOKS="pre-commit-clang-format pre-commit-black pre-commit-makerst"
+HOOKS="pre-commit-clang-format pre-commit-black pre-commit-make-rst"
###########################################################
# There should be no need to change anything below this line.
diff --git a/misc/hooks/pre-commit-black b/misc/hooks/pre-commit-black
index 76d97294da..8e22e6068e 100755
--- a/misc/hooks/pre-commit-black
+++ b/misc/hooks/pre-commit-black
@@ -14,7 +14,7 @@ DELETE_OLD_PATCHES=false
# File types to parse.
FILE_NAMES="SConstruct SCsub"
-FILE_EXTS="py"
+FILE_EXTS=".py"
# Use pygmentize instead of cat to parse diff with highlighting.
# Install it with `pip install pygments` (Linux) or `easy_install Pygments` (Mac)
diff --git a/misc/hooks/pre-commit-clang-format b/misc/hooks/pre-commit-clang-format
index 4e1fbdeb20..de5d9c3f06 100755
--- a/misc/hooks/pre-commit-clang-format
+++ b/misc/hooks/pre-commit-clang-format
@@ -74,25 +74,44 @@ else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
+# To get consistent formatting, we recommend contributors to use the same
+# clang-format version as CI.
+RECOMMENDED_CLANG_FORMAT_MAJOR_MIN="12"
+RECOMMENDED_CLANG_FORMAT_MAJOR_MAX="13"
+
if [ ! -x "$CLANG_FORMAT" ] ; then
+ message="Error: clang-format executable not found. Please install clang-format $RECOMMENDED_CLANG_FORMAT_MAJOR_MAX."
+
if [ ! -t 1 ] ; then
if [ -x "$ZENITY" ] ; then
- $ZENITY --error --title="Error" --text="Error: clang-format executable not found."
+ $ZENITY --error --title="Error" --text="$message"
exit 1
elif [ -x "$XMSG" ] ; then
- $XMSG -center -title "Error" "Error: clang-format executable not found."
+ $XMSG -center -title "Error" "$message"
exit 1
elif [ \( \( "$OSTYPE" = "msys" \) -o \( "$OSTYPE" = "win32" \) \) -a \( -x "$PWSH" \) ]; then
winmessage="$(canonicalize_filename "./.git/hooks/winmessage.ps1")"
- $PWSH -noprofile -executionpolicy bypass -file "$winmessage" -center -title "Error" --text "Error: clang-format executable not found."
+ $PWSH -noprofile -executionpolicy bypass -file "$winmessage" -center -title "Error" --text "$message"
exit 1
fi
fi
- printf "Error: clang-format executable not found.\n"
+ printf "$message\n"
printf "Set the correct path in $(canonicalize_filename "$0").\n"
exit 1
fi
+# The returned string can be inconsistent depending on where clang-format comes from.
+# Example output strings reported by `clang-format --version`:
+# - Ubuntu: "Ubuntu clang-format version 11.0.0-2"
+# - Fedora: "clang-format version 11.0.0 (Fedora 11.0.0-2.fc33)"
+CLANG_FORMAT_VERSION="$(clang-format --version | sed "s/[^0-9\.]*\([0-9\.]*\).*/\1/")"
+CLANG_FORMAT_MAJOR="$(echo "$CLANG_FORMAT_VERSION" | cut -d. -f1)"
+
+if [[ "$CLANG_FORMAT_MAJOR" -lt "$RECOMMENDED_CLANG_FORMAT_MAJOR_MIN" || "$CLANG_FORMAT_MAJOR" -gt "$RECOMMENDED_CLANG_FORMAT_MAJOR_MAX" ]]; then
+ 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)."
+ echo " Consider upgrading or downgrading clang-format as formatting may not be applied correctly."
+fi
+
# create a random filename to store our generated patch
prefix="pre-commit-clang-format"
suffix="$(date +%s)"
@@ -111,6 +130,9 @@ do
if grep -q "platform/android/java/lib/src/com" <<< $file; then
continue;
fi
+ if grep -q "\-so_wrap." <<< $file; then
+ continue;
+ fi
# ignore file if we do check for file extensions and the file
# does not match any of the extensions specified in $FILE_EXTS
@@ -124,7 +146,7 @@ do
# +++ - timestamp
# to both lines working on the same file and having a/ and b/ prefix.
# Else it can not be applied with 'git apply'.
- "$CLANG_FORMAT" -style=file "$file" | \
+ "$CLANG_FORMAT" -style=file "$file" --Wno-error=unknown | \
diff -u "$file" - | \
sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch"
done
diff --git a/misc/hooks/pre-commit-makerst b/misc/hooks/pre-commit-make-rst
index b990788b99..38b397c494 100755
--- a/misc/hooks/pre-commit-makerst
+++ b/misc/hooks/pre-commit-make-rst
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-# Git pre-commit hook that checks the class reference syntax using makerst.py.
+# Git pre-commit hook that checks the class reference syntax using make_rst.py.
# Workaround because we can't execute the .py file directly on windows
PYTHON=python
@@ -9,4 +9,4 @@ if [[ "$py_ver" != "3" ]]; then
PYTHON+=3
fi
-$PYTHON doc/tools/makerst.py doc/classes modules --dry-run
+$PYTHON doc/tools/make_rst.py doc/classes modules --dry-run
diff --git a/misc/hooks/winmessage.ps1 b/misc/hooks/winmessage.ps1
index 3672579544..3672579544 100755..100644
--- a/misc/hooks/winmessage.ps1
+++ b/misc/hooks/winmessage.ps1