diff options
author | Pascal Bühler <pabuhler@cisco.com> | 2017-10-09 10:47:27 +0200 |
---|---|---|
committer | Pascal Bühler <pabuhler@cisco.com> | 2017-10-11 16:23:12 +0200 |
commit | 6aef9c0f82a7c0f8e87122769f2f040be89ccdc3 (patch) | |
tree | 1f91f0aff008d64d60648c71ee001c5874dfaf6a | |
parent | a6eda52042365fb91c3696a5edfe5b491c2d3cc5 (diff) | |
download | libsrtp2-6aef9c0f82a7c0f8e87122769f2f040be89ccdc3.tar.gz |
Add clang-format check in traivs
If formatting is required the build will fail and
the required diff printed
Currently works against clang-format-3.9.
All linux configurations will run the check on travis,
should consider making a specific configuration for format
checking and letting normal builds finish.
-rw-r--r-- | .travis.yml | 5 | ||||
-rwxr-xr-x | format.sh | 27 |
2 files changed, 28 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml index e4e595d..e289bdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ sudo: false language: c cache: ccache osx_image: xcode8.2 +addons: + apt: + packages: + - clang-format-3.9 compiler: - clang - gcc @@ -18,6 +22,7 @@ matrix: env: CONFIGURE_FLAGS=--enable-openssl before_script: - if [ $TRAVIS_OS_NAME == osx ]; then brew install ccache; fi + - if [ $TRAVIS_OS_NAME == linux ]; then ./format.sh -d; fi script: - ./configure $CONFIGURE_FLAGS - make @@ -3,14 +3,33 @@ # format.sh # # run clang-format on each .c & .h file +# +# assumes git tree is clean when reporting status if [ -z "${CLANG_FORMAT}" ]; then CLANG_FORMAT=clang-format fi -a=`git ls-files | grep "\.h$\|\.c$"` +a=`git ls-files '*.h' '*.c'` for x in $a; do - if [ $x != "config_in.h" ]; then - $CLANG_FORMAT -i -style=file $x - fi + if [ $x != "config_in.h" ]; then + $CLANG_FORMAT -i -style=file $x + fi done + +m=`git ls-files -m` +if [ -n "$m" ]; then + v=`$CLANG_FORMAT -version` + echo "Fromatting required when checking with $v" + echo + echo "The following files required formatting:" + for f in $m; do + echo $f + done + if [ "$1" = "-d" ]; then + echo + git diff + fi + exit 1 +fi +exit 0 |