blob: 55fe4ab53ae016d0c56e89054d4d4dcbed508a02 [file] [log] [blame]
Ed Warnickebe053b82016-08-05 11:43:58 -07001#!/bin/bash
2
3VPP_DIR=`dirname $0`/../../
4EXIT_CODE=0
5FIX="0"
Damjan Marion24704852016-09-07 13:10:50 +02006FULL="0"
Ed Warnickebe053b82016-08-05 11:43:58 -07007CHECKSTYLED_FILES=""
8UNCHECKSTYLED_FILES=""
9
10# If the user provides --fix, then actually fix things
11# Note: this is meant for use outside of the CI Jobs, by users cleaning things up
12
Damjan Marion24704852016-09-07 13:10:50 +020013while true; do
14 case ${1} in
15 --fix)
16 FIX="1"
17 ;;
18 --full)
19 FULL="1"
20 ;;
21 esac
22 shift || break
23done
24
25if [ "${FULL}" == "1" ]; then
26 FILELIST=$(git ls-tree -r HEAD --name-only)
27else
28 FILELIST=$((git diff HEAD~1.. --name-only; git ls-files -m ) | sort -u)
Ed Warnickebe053b82016-08-05 11:43:58 -070029fi
30
31# Check to make sure we have indent. Exit if we don't with an error message, but
32# don't *fail*.
33command -v indent > /dev/null
34if [ $? != 0 ]; then
35 echo "Cound not find required commend \"indent\". Checkstyle aborted"
36 exit ${EXIT_CODE}
37fi
38indent --version
39
40cd ${VPP_DIR}
41git status
Damjan Marion24704852016-09-07 13:10:50 +020042for i in ${FILELIST}; do
Damjan Marion757585d2017-04-20 11:42:28 +020043 if [ -f ${i} ] && [ ${i} != "build-root/scripts/checkstyle.sh" ] && [ ${i} != "extras/emacs/fix-coding-style.el" ]; then
Ed Warnickebe053b82016-08-05 11:43:58 -070044 grep -q "fd.io coding-style-patch-verification: ON" ${i}
45 if [ $? == 0 ]; then
46 CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}"
47 if [ ${FIX} == 0 ]; then
48 indent ${i} -o ${i}.out1 > /dev/null 2>&1
49 indent ${i}.out1 -o ${i}.out2 > /dev/null 2>&1
Damjan Marion607de1a2016-08-16 22:53:54 +020050 # Remove trailing whitespace
51 sed -i -e 's/[[:space:]]*$//' ${i}.out2
Ed Warnickebe053b82016-08-05 11:43:58 -070052 diff -q ${i} ${i}.out2
53 else
54 indent ${i}
55 indent ${i}
Damjan Marion607de1a2016-08-16 22:53:54 +020056 # Remove trailing whitespace
57 sed -i -e 's/[[:space:]]*$//' ${i}
Ed Warnickebe053b82016-08-05 11:43:58 -070058 fi
59 if [ $? != 0 ]; then
60 EXIT_CODE=1
61 echo
62 echo "Checkstyle failed for ${i}."
63 echo "Run indent (twice!) as shown to fix the problem:"
64 echo "indent ${VPP_DIR}${i}"
65 echo "indent ${VPP_DIR}${i}"
66 fi
67 if [ -f ${i}.out1 ]; then
68 rm ${i}.out1
69 fi
70 if [ -f ${i}.out2 ]; then
71 rm ${i}.out2
72 fi
73 else
74 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
75 fi
76 else
77 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
78 fi
79done
80
81if [ ${EXIT_CODE} == 0 ]; then
82 echo "*******************************************************************"
83 echo "* VPP CHECKSTYLE SUCCESSFULLY COMPLETED"
84 echo "*******************************************************************"
85else
86 echo "*******************************************************************"
87 echo "* VPP CHECKSTYLE FAILED"
88 echo "* CONSULT FAILURE LOG ABOVE"
89 echo "* NOTE: Running 'build-root/scripts/checkstyle.sh --fix' *MAY* fix the issue"
90 echo "*******************************************************************"
91fi
92exit ${EXIT_CODE}