From: Otto Moerbeek Date: Wed, 25 Sep 2019 12:37:22 +0000 (+0200) Subject: Add script to format code, leaving the file untouched if not changed X-Git-Tag: auth-4.3.0-alpha1~26^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba5ba96c5009ccf969459d7bfaec83fb6191245d;p=thirdparty%2Fpdns.git Add script to format code, leaving the file untouched if not changed 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. --- diff --git a/Makefile.am b/Makefile.am index e26c915213..0f569682dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000000..6a4d6d10f5 --- /dev/null +++ b/build-scripts/format-code @@ -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 +