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
43 command -v clang-format > /dev/null
45 echo "Could not find command \"clang-format\". Checking C++ files will cause abort"
47 clang-format --version
48 x=$(echo "" | clang-format 2>&1)
49 if [[ "$x" == "" ]]; then
52 echo "Output produced while formatting empty file (expected empty string):"
54 echo "Could not find working \"clang-format\". Checking C++ files will cause abort"
60 for i in ${FILELIST}; do
61 if [ -f ${i} ] && [ ${i} != "build-root/scripts/checkstyle.sh" ] && [ ${i} != "extras/emacs/fix-coding-style.el" ]; then
62 grep -q "fd.io coding-style-patch-verification: ON" ${i}
64 EXTENSION=`basename ${i} | sed 's/^\w\+.//'`
68 if [ ${HAVE_CLANG_FORMAT} == 0 ]; then
69 echo "C++ file detected. Abort. (missing clang-format)"
77 CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}"
78 if [ ${FIX} == 0 ]; then
79 if [ "${CMD}" == "clang-format" ]
81 clang-format ${i} > ${i}.out2
83 indent ${i} -o ${i}.out1 > /dev/null 2>&1
84 indent ${i}.out1 -o ${i}.out2 > /dev/null 2>&1
86 # Remove trailing whitespace
87 sed -i -e 's/[[:space:]]*$//' ${i}.out2
88 diff -q ${i} ${i}.out2
90 if [ "${CMD}" == "clang-format" ]; then
91 clang-format -i ${i} > /dev/null 2>&1
96 # Remove trailing whitespace
97 sed -i -e 's/[[:space:]]*$//' ${i}
102 echo "Checkstyle failed for ${i}."
103 if [ "${CMD}" == "clang-format" ]; then
104 echo "Run clang-format as shown to fix the problem:"
105 echo "clang-format -i ${VPP_DIR}${i}"
107 echo "Run indent (twice!) as shown to fix the problem:"
108 echo "indent ${VPP_DIR}${i}"
109 echo "indent ${VPP_DIR}${i}"
112 if [ -f ${i}.out1 ]; then
115 if [ -f ${i}.out2 ]; then
119 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
122 UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
126 if [ ${EXIT_CODE} == 0 ]; then
127 echo "*******************************************************************"
128 echo "* VPP CHECKSTYLE SUCCESSFULLY COMPLETED"
129 echo "*******************************************************************"
131 echo "*******************************************************************"
132 echo "* VPP CHECKSTYLE FAILED"
133 echo "* CONSULT FAILURE LOG ABOVE"
134 echo "* NOTE: Running 'build-root/scripts/checkstyle.sh --fix' *MAY* fix the issue"
135 echo "*******************************************************************"