summaryrefslogtreecommitdiff
path: root/tools/cmake-format
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2019-01-24 08:56:19 +0100
committerRalf Habacker <ralf.habacker@freenet.de>2019-01-24 09:07:45 +0100
commitf4032b05ed9bd69c26e17a705b49af6da5e003e3 (patch)
tree8e974cdb25b29763a5a3d0e62dfff9ad1a7873fd /tools/cmake-format
parent904fa97a1b83217a57bf230f233ccd30d0e44f5b (diff)
downloaddbus-f4032b05ed9bd69c26e17a705b49af6da5e003e3.tar.gz
tools/cmake-format: Add option --check-indents to check indentations independently from other options
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Diffstat (limited to 'tools/cmake-format')
-rwxr-xr-xtools/cmake-format25
1 files changed, 21 insertions, 4 deletions
diff --git a/tools/cmake-format b/tools/cmake-format
index 1e5f46fb..9ccf1653 100755
--- a/tools/cmake-format
+++ b/tools/cmake-format
@@ -22,6 +22,7 @@ if test -z "$1"; then
echo " --keyword-spaces remove spaces between keyword and opening bracket"
echo " --tabs replace tabs by 4 spaces"
echo " --trailing-spaces remove trailing spaces"
+ echo " --check-indents check indents"
exit 1
fi
@@ -99,11 +100,27 @@ root=$(realpath $s/..)
#echo $exp
#echo $root
-echo "locations with unusual indention level changes, please inspect"
+if test "$1" = "--check-indents"; then
+ echo "locations with unusual indention level changes, please inspect"
+fi
+
+# script for checking indents
+awk='BEGIN { debug=0; indent=0 }
+$0 ~ /^ {0}/ && $0 !~ /^$/{ indent=0; }
+$0 ~ /^ {4}/ { indent=1; }
+$0 ~ /^ {8}/ { indent=2; }
+$0 ~ /^ {12}/ { indent=3; }
+debug == 1 { print FILENAME "[" NR "]:" indent " " oldindent ": " $0; }
+{ if (indent - oldindent > 1) print FILENAME ":" NR ":" $0; }
+{ oldindent = indent;}
+'
+
# apply to cmake related files
for i in $(find $root -name 'CMakeLists.txt' -o -name '*.cmake' | grep -v README.cmake | grep -v config.h.cmake | grep -v bat.cmake | grep -v '/Find'); do
# apply style
- sed -i "$exp" $i
- # show unusual indention changes
- gawk 'BEGIN { indent=0 } $0 ~ /^ {0}/ && $0 !~ /^$/{ indent=0; } $0 ~ /^ {4}/ { indent=1; } $0 ~ /^ {8}/ { indent=2; } $0 ~ /^ {12}/ { indent=3; } { if (indent - oldindent > 1) print FILENAME ":" NR ":" $0; oldindent=indent;}' $i
+ if ! test "$1" = "--check-indents"; then
+ sed -i "$exp" $i
+ else
+ gawk "$awk" $i
+ fi
done