From 7004492324352780e5b702497f1df643dbb04192 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 23 Sep 2015 08:52:44 -0700 Subject: [PATCH] build: check formatting with astyle Change-Id: Ic09b4dd7ccccb557e8236fc0b7e3105fce1644b3 Signed-off-by: Daniel Verkamp --- .astylerc | 26 ++++++++++++++++++++++++++ autobuild.sh | 2 ++ scripts/check_format.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 .astylerc create mode 100755 scripts/check_format.sh diff --git a/.astylerc b/.astylerc new file mode 100644 index 0000000000..2c3b9de44d --- /dev/null +++ b/.astylerc @@ -0,0 +1,26 @@ +# Bracket Style +style=kr # K&R brackets + +# Indentation +indent=force-tab=8 # Use tabs for indentation, spaces for minor alignment +min-conditional-indent=0 + +# Padding +unpad-paren # Remove all spaces with parens that aren't requested below +pad-oper # Put spaces around operators +pad-header # Put spaces between if/while/for etc. and the first paren + +# Pointers +align-pointer=name # Align the * next to the variable name + +# Line wrapping +max-code-length=100 # 100 character line limit +break-after-logical # For if statements, wrap to the next line after logical operator + +# Line endings +lineend=linux # LF line endings + +# General options +suffix=none +recursive +formatted diff --git a/autobuild.sh b/autobuild.sh index a63e2bc251..c7c9035aa4 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -10,6 +10,8 @@ DPDK_DIR=/usr/local/dpdk-2.1.0/x86_64-native-linuxapp-gcc cd $src +./scripts/check_format.sh + scanbuild='' if hash scan-build; then scanbuild="scan-build -o $out/scan-build-tmp --status-bugs" diff --git a/scripts/check_format.sh b/scripts/check_format.sh new file mode 100755 index 0000000000..9ac9485e39 --- /dev/null +++ b/scripts/check_format.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +readonly BASEDIR=$(readlink -f $(dirname $0))/.. +cd $BASEDIR + +# exit on errors +set -e + +if hash astyle; then + echo -n "Checking coding style..." + rm -f astyle.log + touch astyle.log + astyle --options=.astylerc "*.c" >> astyle.log + astyle --options=.astylerc "*.h" >> astyle.log + if grep -q "^Formatted" astyle.log; then + echo " errors detected" + sed -i -e 's/ / /g' astyle.log + grep --color=auto "^Formatted.*" astyle.log + echo "Incorrect code style detected in one or more files." + echo "The files have been automatically formatted." + echo "Remember to add the files to your commit." + rm -f astyle.log + exit 1 + fi + echo " OK" + rm -f astyle.log +else + echo "You do not have astyle installed so your code style is not being checked!" + exit 0 +fi + +exit 0