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