mirror of https://github.com/OpenMW/openmw.git
Simplify script to check clang-format
* Check only files from the git repository * Support paths with spaces * Do check in parallelcoverity_clang_test
parent
d2d1036d26
commit
a46d61c45c
@ -1,33 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -ex
|
||||||
|
|
||||||
CLANG_FORMAT="${CLANG_FORMAT:-clang-format}"
|
set -o pipefail
|
||||||
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
|
|
||||||
find "$path" -type f -name "*" | while read item;
|
|
||||||
do
|
|
||||||
if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then
|
|
||||||
check_format_file "$item"
|
|
||||||
fi;
|
|
||||||
done;
|
|
||||||
}
|
|
||||||
|
|
||||||
check_format "./apps"
|
CLANG_FORMAT="${CLANG_FORMAT:-clang-format}"
|
||||||
check_format "./components"
|
git ls-files |
|
||||||
|
grep -v '^extern/' |
|
||||||
if [[ $HAS_DIFFS -eq 1 ]]; then
|
grep -P '\.(cpp|hpp|h)$' |
|
||||||
echo "clang-format differences detected"
|
xargs -I '{}' -P $(nproc) bash -ec "\"${CLANG_FORMAT:?}\" --dry-run -Werror \"\${0:?}\" &> /dev/null || \"${CLANG_FORMAT:?}\" \"\${0:?}\" | git diff --color=always --no-index \"\${0:?}\" -" '{}' ||
|
||||||
exit 1
|
( echo "clang-format differences detected"; exit -1 )
|
||||||
fi;
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
Loading…
Reference in New Issue