|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +SCRIPT_DIR=$(dirname "$0") |
| 6 | +case $SCRIPT_DIR in |
| 7 | + "/"*) |
| 8 | + ;; |
| 9 | + ".") |
| 10 | + SCRIPT_DIR=$(pwd) |
| 11 | + ;; |
| 12 | + *) |
| 13 | + SCRIPT_DIR=$(pwd)/$(dirname "$0") |
| 14 | + ;; |
| 15 | +esac |
| 16 | + |
| 17 | +LOG_FILE=/tmp/cppcheck_libdxfrw.txt |
| 18 | + |
| 19 | +rm -f ${LOG_FILE} |
| 20 | +echo "Checking ${SCRIPT_DIR}/../src ..." |
| 21 | + |
| 22 | +cppcheck --inline-suppr \ |
| 23 | + --template='{file}:{line},{severity},{id},{message}' \ |
| 24 | + --enable=all --inconclusive --std=c++11 \ |
| 25 | + -j $(nproc) \ |
| 26 | + ${SCRIPT_DIR}/../src \ |
| 27 | + >>${LOG_FILE} 2>&1 & |
| 28 | + |
| 29 | +PID=$! |
| 30 | +while kill -0 $PID 2>/dev/null; do |
| 31 | + printf "." |
| 32 | + sleep 1 |
| 33 | +done |
| 34 | +echo " done" |
| 35 | +if ! wait $PID; then |
| 36 | + echo "cppcheck failed" |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +ret_code=0 |
| 41 | + |
| 42 | +cat ${LOG_FILE} | grep -v -e "syntaxError," -e "cppcheckError," > ${LOG_FILE}.tmp |
| 43 | +mv ${LOG_FILE}.tmp ${LOG_FILE} |
| 44 | + |
| 45 | +for category in "style" "performance" "portability" "warning"; do |
| 46 | + if grep "${category}," ${LOG_FILE} >/dev/null; then |
| 47 | + echo "INFO: Issues in '${category}' category found, but not considered as making script to fail:" |
| 48 | + grep "${category}," ${LOG_FILE} | grep -v -e "clarifyCalculation," -e "duplicateExpressionTernary," -e "redundantCondition," -e "unusedPrivateFunction," -e "postfixOperator," |
| 49 | + echo "" |
| 50 | + fi |
| 51 | +done |
| 52 | + |
| 53 | +# unusedPrivateFunction not reliable enough in cppcheck 1.72 of Ubuntu 16.04 |
| 54 | +if test "$(cppcheck --version)" = "Cppcheck 1.72"; then |
| 55 | + UNUSED_PRIVATE_FUNCTION="" |
| 56 | +else |
| 57 | + UNUSED_PRIVATE_FUNCTION="unusedPrivateFunction" |
| 58 | +fi |
| 59 | + |
| 60 | +for category in "error" "clarifyCalculation" "duplicateExpressionTernary" "redundantCondition" "postfixOperator" "${UNUSED_PRIVATE_FUNCTION}"; do |
| 61 | + if test "${category}" != ""; then |
| 62 | + if grep "${category}," ${LOG_FILE} >/dev/null; then |
| 63 | + echo "ERROR: Issues in '${category}' category found:" |
| 64 | + grep "${category}," ${LOG_FILE} |
| 65 | + echo "" |
| 66 | + echo "${category} check failed !" |
| 67 | + ret_code=1 |
| 68 | + fi |
| 69 | + fi |
| 70 | +done |
| 71 | + |
| 72 | +if [ ${ret_code} = 0 ]; then |
| 73 | + echo "cppcheck succeeded" |
| 74 | +fi |
| 75 | + |
| 76 | +exit ${ret_code} |
0 commit comments