diff options
author | Ed Warnicke <eaw@cisco.com> | 2016-08-05 11:43:58 -0700 |
---|---|---|
committer | Ed Warnicke <eaw@cisco.com> | 2016-08-12 13:56:29 -0700 |
commit | be053b87cf321c34d780e9c79ad455513fb98395 (patch) | |
tree | 79c70c65e97db4a948abf33b7b40a0f51cb090eb | |
parent | 853e720fdd74b1ffb1168c1503cd97eb5b7f8b60 (diff) |
VPP-237: Checkstyle script to check for new checkstyle breakage
indent is... cantankerous
It sometimes happens that if you run
indent A
resulting in A'
and then
indent A'
you get back A. Since the check here is premised on being able
to run indent and not see any changed... we have to run it twice
to be sure.
Change-Id: I5b73e02f5996d8a01ec2e46741affbc6d62da6c9
Signed-off-by: Ed Warnicke <eaw@cisco.com>
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | build-root/scripts/checkstyle.sh | 73 |
2 files changed, 76 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index b5673ae07e2..250532aa97b 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,6 @@ GTAGS # Generated documentation /build-root/docs + +# indent backup files +*.BAK diff --git a/build-root/scripts/checkstyle.sh b/build-root/scripts/checkstyle.sh new file mode 100755 index 00000000000..44534d48646 --- /dev/null +++ b/build-root/scripts/checkstyle.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +VPP_DIR=`dirname $0`/../../ +EXIT_CODE=0 +FIX="0" +CHECKSTYLED_FILES="" +UNCHECKSTYLED_FILES="" + +# If the user provides --fix, then actually fix things +# Note: this is meant for use outside of the CI Jobs, by users cleaning things up + +if [ $# -gt 0 ] && [ ${1} == '--fix' ]; then + FIX="1" +fi + +# Check to make sure we have indent. Exit if we don't with an error message, but +# don't *fail*. +command -v indent > /dev/null +if [ $? != 0 ]; then + echo "Cound not find required commend \"indent\". Checkstyle aborted" + exit ${EXIT_CODE} +fi +indent --version + +cd ${VPP_DIR} +git status +for i in `git ls-tree -r HEAD --name-only`;do + if [ -f ${i} ] && [ ${i} != "build-root/scripts/checkstyle.sh" ] && [ ${i} != "build-root/emacs-lisp/fix-coding-style.el" ]; then + grep -q "fd.io coding-style-patch-verification: ON" ${i} + if [ $? == 0 ]; then + CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}" + if [ ${FIX} == 0 ]; then + indent ${i} -o ${i}.out1 > /dev/null 2>&1 + indent ${i}.out1 -o ${i}.out2 > /dev/null 2>&1 + diff -q ${i} ${i}.out2 + else + indent ${i} + indent ${i} + fi + if [ $? != 0 ]; then + EXIT_CODE=1 + echo + echo "Checkstyle failed for ${i}." + echo "Run indent (twice!) as shown to fix the problem:" + echo "indent ${VPP_DIR}${i}" + echo "indent ${VPP_DIR}${i}" + fi + if [ -f ${i}.out1 ]; then + rm ${i}.out1 + fi + if [ -f ${i}.out2 ]; then + rm ${i}.out2 + fi + else + UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}" + fi + else + UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}" + fi +done + +if [ ${EXIT_CODE} == 0 ]; then + echo "*******************************************************************" + echo "* VPP CHECKSTYLE SUCCESSFULLY COMPLETED" + echo "*******************************************************************" +else + echo "*******************************************************************" + echo "* VPP CHECKSTYLE FAILED" + echo "* CONSULT FAILURE LOG ABOVE" + echo "* NOTE: Running 'build-root/scripts/checkstyle.sh --fix' *MAY* fix the issue" + echo "*******************************************************************" +fi +exit ${EXIT_CODE} |