aboutsummaryrefslogtreecommitdiff
path: root/etc/format-check.sh
diff options
context:
space:
mode:
Diffstat (limited to 'etc/format-check.sh')
-rwxr-xr-xetc/format-check.sh48
1 files changed, 40 insertions, 8 deletions
diff --git a/etc/format-check.sh b/etc/format-check.sh
index 4a779080..889b498e 100755
--- a/etc/format-check.sh
+++ b/etc/format-check.sh
@@ -18,30 +18,62 @@ mydir=`dirname $0`
srcdir=${mydir}/../src
failed=
-clang-format -version > /dev/null
+vers=$(clang-format -version)
if [ $? -ne 0 ]; then
- echo "clang-format not found. Skipping checks."
+ echo "clang format not found? Skipping checks."
exit 0
fi
+versno=${vers#clang-format version }
+prefix=${vers%${versno}}
+
+if [ "$prefix" != "clang-format version " ]
+then
+ echo "clang-format version misparsed. Skipping checks."
+ exit 0
+fi
+
+# strip off any -ubuntu suffix
+versno=${versno%%-*}
+maj=${versno%%.*}
+rem=${versno#*.}
+min=${rem%%.*}
+
+if [ "${maj}" -lt 3 ]; then
+ echo "clang-format is too old. Skipping checks."
+ exit 0
+fi
+if [ "${maj}" -eq 3 -a "${min}" -lt 5 ]; then
+ echo "clang-format is too old. Skipping checks."
+ exit 0
+fi
+echo "VERSION is $versno MAJOR $maj MINOR $min}"
+
+
mytmpdir=`mktemp -d`
+diffprog=${DIFF:-diff}
+if [ -t 1 ]; then
+ if colordiff -q /dev/null /dev/null; then
+ diffprog=${DIFF:-colordiff}
+ fi
+fi
+
cd ${srcdir}
for file in `find . -name '*.[ch]' -print`
do
ext=${file##*.}
oldf=${file}
newf=${mytmpdir}/new.${ext}
- clang-format -style=file ${oldf} > ${newf}
+ # If we do not understand the format file, then do nothing
+ # Our style requires a relatively modern clang-format, which is
+ # older than is found on some Linux distros.
+ clang-format -fallback-style=none -style=file ${oldf} > ${newf}
cmp -s ${oldf} ${newf}
if [ $? -ne 0 ]
then
echo "${file} style changes"
- if [ -t 1 ]; then
- colordiff -u $oldf $newf
- else
- diff -u $oldf $newf
- fi
+ ${diffprog} -u $oldf $newf
failed=1
fi
done