build: check formatting with astyle

Change-Id: Ic09b4dd7ccccb557e8236fc0b7e3105fce1644b3
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2015-09-23 08:52:44 -07:00
parent 5abc81fd9a
commit 7004492324
3 changed files with 60 additions and 0 deletions

26
.astylerc Normal file
View File

@ -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

View File

@ -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"

32
scripts/check_format.sh Executable file
View File

@ -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