Improve clang-format checking script

coverity_clang_test
ζeh Matt 2 years ago
parent cd7fe60134
commit afa1b0077d
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0

@ -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…
Cancel
Save