mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 17:15:34 +00:00
Improve clang-format checking script
This commit is contained in:
parent
cd7fe60134
commit
afa1b0077d
2 changed files with 14 additions and 14 deletions
|
@ -127,6 +127,8 @@ Clang_Format:
|
|||
key: Ubuntu_Clang_Format.ubuntu_22.04.v1
|
||||
paths:
|
||||
- apt-cache/
|
||||
variables:
|
||||
CLANG_FORMAT: clang-format-14
|
||||
before_script:
|
||||
- CI/install_debian_deps.sh openmw-clang-format
|
||||
script:
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
CLANG_FORMAT="clang-format-14"
|
||||
CLANG_FORMAT="${CLANG_FORMAT:-clang-format}"
|
||||
HAS_DIFFS=0
|
||||
|
||||
check_format_file() {
|
||||
local item=$1
|
||||
"$CLANG_FORMAT" --dry-run -Werror "$item" &>/dev/null
|
||||
if [[ $? = 1 ]]; then
|
||||
"${CLANG_FORMAT}" "${item}" | git diff --color=always --no-index "${item}" -
|
||||
HAS_DIFFS=1
|
||||
fi
|
||||
}
|
||||
|
||||
check_format() {
|
||||
local path=$1
|
||||
for item in $(find $path -type f -name "*");
|
||||
for item in $(find "$path" -type f -name "*");
|
||||
do
|
||||
if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then
|
||||
echo "Checking code formatting on $item"
|
||||
$CLANG_FORMAT --dry-run -Werror "$item"
|
||||
if [[ $? = 1 ]]; then
|
||||
local tempfile=$(mktemp)
|
||||
# Avoid having different modes in the diff.
|
||||
chmod --reference="$item" "$tempfile"
|
||||
# Generate diff
|
||||
$CLANG_FORMAT "$item" > "$tempfile"
|
||||
git diff --color=always --no-index $item $tempfile
|
||||
rm -f "$tempfile"
|
||||
HAS_DIFFS=1
|
||||
fi
|
||||
check_format_file "$item" &
|
||||
fi;
|
||||
done;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue