]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add script to format code, leaving the file untouched if not changed
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 25 Sep 2019 12:37:22 +0000 (14:37 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 25 Sep 2019 12:37:22 +0000 (14:37 +0200)
and report if it was changed.

Callable as separate script or with `make format-code` in toplevel
to reformat .cc and .hh files in the modules and pdns dirs.

Makefile.am
build-scripts/format-code [new file with mode: 0755]

index e26c915213ad876fc7da89ea10655f337abf0a9f..0f569682dcb68c1eec604b2a2e0b51e04b2baaf6 100644 (file)
@@ -14,3 +14,7 @@ EXTRA_DIST = \
 ACLOCAL_AMFLAGS = -I m4
 
 dvi: # do nothing to build dvi
+
+format-code:
+       ./build-scripts/format-code `find modules pdns -type f -name '*.[ch][ch]'`
+
diff --git a/build-scripts/format-code b/build-scripts/format-code
new file mode 100755 (executable)
index 0000000..6a4d6d1
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+#
+# Reformat code, but do not touch if no changes.
+# Report if a files was changed.
+#
+
+if [ "$0" != "./build-scripts/format-code" ]; then
+    echo "Please run me from the root checkout dir"
+    exit 1
+fi
+
+if [ ! -e .clang-format ]; then
+    echo "No .clang-format file found in .";
+    exit 1
+fi
+
+for file in "${@}"; do
+    if ! clang-format -style=file "$file" > "$file.xxx"; then
+        rm "$file.xxx"
+    else
+        if ! cmp -s "$file" "$file.xxx"; then
+            echo "$file reformatted"
+            mv "$file.xxx" "$file"
+        else
+            rm "$file.xxx"
+        fi
+    fi
+done
+