2019-10-17 14:30:31 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-10-21 12:33:12 +08:00
|
|
|
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
|
|
|
|
CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION:-}
|
2019-10-17 16:41:16 +08:00
|
|
|
|
2019-10-21 12:33:12 +08:00
|
|
|
if ! type $CLANG_FORMAT >/dev/null || \
|
|
|
|
! $CLANG_FORMAT --version | grep -q "version ${CLANG_FORMAT_VERSION}"; then
|
|
|
|
# If running tests, mark this test as skipped.
|
2019-10-20 01:46:34 +08:00
|
|
|
exit 77
|
|
|
|
fi
|
|
|
|
|
2019-10-17 14:30:31 +08:00
|
|
|
errors=0
|
2019-10-21 12:33:12 +08:00
|
|
|
paths=$(git ls-files | grep '\.[ch]$')
|
2019-10-17 14:30:31 +08:00
|
|
|
for path in $paths; do
|
|
|
|
in=$(cat $path)
|
2019-10-21 12:33:12 +08:00
|
|
|
out=$($CLANG_FORMAT $path)
|
2019-10-17 14:30:31 +08:00
|
|
|
|
|
|
|
if [ "$in" != "$out" ]; then
|
|
|
|
diff -u -L $path -L "$path.formatted" $path - <<<$out
|
|
|
|
errors=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $errors -ne 0 ]; then
|
|
|
|
echo "Formatting errors detected, run ./scripts/clang-format to fix!"
|
|
|
|
exit 1
|
|
|
|
fi
|