From 5908aaef1a045737c25bdcbb40e4584fbe863a62 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 16 Jul 2017 12:34:28 -0700 Subject: Better support for checking clang-format version and colordiff. --- etc/format-check.sh | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'etc') 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 -- cgit v1.2.3-70-g09d2