aboutsummaryrefslogtreecommitdiff
path: root/etc/format-check.sh
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-10 15:02:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-10 15:02:38 -0700
commit795aebbee77bb74d8792df96dfe1aa79ec9548fc (patch)
tree58c16424c16b9e71cebdceaee4507ab6608f80da /etc/format-check.sh
parentde90f97167d2df6739db47b2c6aad85f06250270 (diff)
downloadnng-795aebbee77bb74d8792df96dfe1aa79ec9548fc.tar.gz
nng-795aebbee77bb74d8792df96dfe1aa79ec9548fc.tar.bz2
nng-795aebbee77bb74d8792df96dfe1aa79ec9548fc.zip
Give up on uncrustify; switch to clang-format.
Diffstat (limited to 'etc/format-check.sh')
-rwxr-xr-xetc/format-check.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/etc/format-check.sh b/etc/format-check.sh
new file mode 100755
index 00000000..ea9bd2f2
--- /dev/null
+++ b/etc/format-check.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# Copyright 2016 Garrett D'Amore <garrett@damore.org>
+#
+# This software is supplied under the terms of the MIT License, a
+# copy of which should be located in the distribution where this
+# file was obtained (LICENSE.txt). A copy of the license may also be
+# found online at https://opensource.org/licenses/MIT.
+#
+
+#
+# This script is used to run uncrustify and report files that don't match.
+# It looks for .c and .h files, located in ../src, and uses the config file
+# uncrustify.cfg located in the same directory as this script. It only handles
+# C language at this point.
+#
+mydir=`dirname $0`
+srcdir=${mydir}/../src
+failed=
+
+clang-format -version > /dev/null
+if [ $? -ne 0 ]; then
+ echo "clang-format not found. Skipping checks."
+ exit 0
+fi
+
+mytmpdir=`mktemp -d`
+
+for file in `find ${srcdir} -name '*.[ch]' -print`
+do
+ ext=${file##*.}
+ oldf=${file}
+ newf=${mytmpdir}/new.${ext}
+ clang-format -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
+ failed=1
+ fi
+done
+rm -rf $mytmpdir
+if [ -n "$failed" ]
+then
+ echo "Format differences found!" 1>&2
+ # Sadly, there are different versions of Uncrustify, and they don't
+ # seem to universally agree. So let's not trigger a build error on
+ # this -- but instead just emit it to standard output.
+ exit 0
+fi