3 VPP_DIR=`dirname $0`/../../
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
25 if [ "${FULL}" == "1" ]; then
26 FILELIST=$(git ls-tree -r HEAD --name-only)
28 FILELIST=$((git diff HEAD~1.. --name-only; git ls-files -m ) | sort -u)
31 # Check to make sure we have indent. Exit if we don't with an error message, but
33 command -v indent > /dev/null
35 echo "Cound not find required command \"indent\". Checkstyle aborted"
40 # Check to make sure we have clang-format. Exit if we don't with an error message, but
42 command -v clang-format > /dev/null
44 echo "Could not find command \"clang-format\". Checking C++ files will cause abort"
48 clang-format --version
53 for i in ${FILELIST}; do
54 if [ -f ${i} ] && [ ${i} != "build-root/scripts/checkstyle.sh" ] && [ ${i} != "extras/emacs/fix-coding-style.el" ]; then
55 grep -q "fd.io coding-style-patch-verification: ON" ${i}
57 EXTENSION=`basename ${i} | sed 's/^\w\+.//'`
61 if [ ${HAVE_CLANG_FORMAT} == 0 ]; then
62 echo "C++ file detected. Abort. (missing clang-format)"
70 CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}"
71 if [ ${FIX} == 0 ]; then
72 if [ "${CMD}" == "clang-format" ]
74 clang-format ${i} > ${i}.out2
76 indent ${i} -o ${i}.out1 > /dev/null 2>&1
77 indent ${i}.out1 -o ${i}.out2 > /dev/null 2>&1
79 # Remove trailing whitespace
80 sed -i -e 's/[[:space:]]*$//' ${i}.out2
81 diff -q ${i} ${i}.out2
83 if [ "${CMD}" == "clang-format" ]; then
84 clang-format -i ${i} > /dev/null 2>&1
89 # Remove trailing whitespace
90 sed -i -e 's/[[:space:]]*$//' ${i}
95 echo "Checkstyle failed for ${i}."
96 if [ "${CMD}" == "clang-format" ]; then
97 echo "Run clang-format as shown to fix the problem:"
98 echo "clang-format -i ${VPP_DIR}${i}"
100 echo "Run indent (twice!) as shown to fix the problem:"
101 echo "indent ${VPP_DIR}${i}"
102 echo "indent ${VPP_DIR}${i}"
105 if [ -f ${i}.out1 ]; then
108 if [ -f ${i}.out2 ]; then
112 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
115 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
119 if [ ${EXIT_CODE} == 0 ]; then
120 echo "*******************************************************************"
121 echo "* VPP CHECKSTYLE SUCCESSFULLY COMPLETED"
122 echo "*******************************************************************"
124 echo "*******************************************************************"
125 echo "* VPP CHECKSTYLE FAILED"
126 echo "* CONSULT FAILURE LOG ABOVE"
127 echo "* NOTE: Running 'build-root/scripts/checkstyle.sh --fix' *MAY* fix the issue"
128 echo "*******************************************************************"