blob: 44534d4864632b9abfd1aec972b4204ab8bc71a8 [file] [log] [blame]
Ed Warnickebe053b82016-08-05 11:43:58 -07001#!/bin/bash
2
3VPP_DIR=`dirname $0`/../../
4EXIT_CODE=0
5FIX="0"
6CHECKSTYLED_FILES=""
7UNCHECKSTYLED_FILES=""
8
9# If the user provides --fix, then actually fix things
10# Note: this is meant for use outside of the CI Jobs, by users cleaning things up
11
12if [ $# -gt 0 ] && [ ${1} == '--fix' ]; then
13 FIX="1"
14fi
15
16# Check to make sure we have indent. Exit if we don't with an error message, but
17# don't *fail*.
18command -v indent > /dev/null
19if [ $? != 0 ]; then
20 echo "Cound not find required commend \"indent\". Checkstyle aborted"
21 exit ${EXIT_CODE}
22fi
23indent --version
24
25cd ${VPP_DIR}
26git status
27for i in `git ls-tree -r HEAD --name-only`;do
28 if [ -f ${i} ] && [ ${i} != "build-root/scripts/checkstyle.sh" ] && [ ${i} != "build-root/emacs-lisp/fix-coding-style.el" ]; then
29 grep -q "fd.io coding-style-patch-verification: ON" ${i}
30 if [ $? == 0 ]; then
31 CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}"
32 if [ ${FIX} == 0 ]; then
33 indent ${i} -o ${i}.out1 > /dev/null 2>&1
34 indent ${i}.out1 -o ${i}.out2 > /dev/null 2>&1
35 diff -q ${i} ${i}.out2
36 else
37 indent ${i}
38 indent ${i}
39 fi
40 if [ $? != 0 ]; then
41 EXIT_CODE=1
42 echo
43 echo "Checkstyle failed for ${i}."
44 echo "Run indent (twice!) as shown to fix the problem:"
45 echo "indent ${VPP_DIR}${i}"
46 echo "indent ${VPP_DIR}${i}"
47 fi
48 if [ -f ${i}.out1 ]; then
49 rm ${i}.out1
50 fi
51 if [ -f ${i}.out2 ]; then
52 rm ${i}.out2
53 fi
54 else
55 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
56 fi
57 else
58 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
59 fi
60done
61
62if [ ${EXIT_CODE} == 0 ]; then
63 echo "*******************************************************************"
64 echo "* VPP CHECKSTYLE SUCCESSFULLY COMPLETED"
65 echo "*******************************************************************"
66else
67 echo "*******************************************************************"
68 echo "* VPP CHECKSTYLE FAILED"
69 echo "* CONSULT FAILURE LOG ABOVE"
70 echo "* NOTE: Running 'build-root/scripts/checkstyle.sh --fix' *MAY* fix the issue"
71 echo "*******************************************************************"
72fi
73exit ${EXIT_CODE}