2020-06-01 21:42:02 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
SCRIPT_DIR=$(dirname "$0")
|
|
|
|
case $SCRIPT_DIR in
|
|
|
|
"/"*)
|
|
|
|
;;
|
|
|
|
".")
|
|
|
|
SCRIPT_DIR=$(pwd)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
SCRIPT_DIR=$(pwd)/$(dirname "$0")
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
LOG_FILE=/tmp/cppcheck_qgis.txt
|
|
|
|
|
|
|
|
rm -f ${LOG_FILE}
|
|
|
|
echo "Checking ${SCRIPT_DIR}/../src ..."
|
|
|
|
|
|
|
|
cppcheck --library=qt.cfg --inline-suppr \
|
|
|
|
--template='{file}:{line},{severity},{id},{message}' \
|
|
|
|
--enable=all --inconclusive --std=c++11 \
|
|
|
|
-DPROJ_VERSION_MAJOR=6 \
|
|
|
|
-USIP_RUN \
|
|
|
|
-DSIP_TRANSFER= \
|
|
|
|
-DSIP_TRANSFERTHIS= \
|
|
|
|
-DSIP_INOUT= \
|
|
|
|
-DSIP_OUT= \
|
2020-06-14 15:57:20 +02:00
|
|
|
-DSIP_FACTORY= \
|
2020-06-13 20:07:28 +02:00
|
|
|
-DCMAKE_SOURCE_DIR="/foo/bar" \
|
2020-06-01 21:42:02 +02:00
|
|
|
-j $(nproc) \
|
|
|
|
${SCRIPT_DIR}/../src \
|
|
|
|
>>${LOG_FILE} 2>&1 &
|
|
|
|
|
|
|
|
PID=$!
|
|
|
|
while kill -0 $PID 2>/dev/null; do
|
|
|
|
printf "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo " done"
|
|
|
|
if ! wait $PID; then
|
|
|
|
echo "cppcheck failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ret_code=0
|
|
|
|
|
2020-06-13 20:07:28 +02:00
|
|
|
cat ${LOG_FILE} | grep -v -e "syntaxError," -e "cppcheckError," > ${LOG_FILE}.tmp
|
|
|
|
mv ${LOG_FILE}.tmp ${LOG_FILE}
|
|
|
|
|
|
|
|
for category in "style" "performance" "portability"; do
|
2020-06-01 21:42:02 +02:00
|
|
|
if grep "${category}," ${LOG_FILE} >/dev/null; then
|
|
|
|
echo "INFO: Issues in '${category}' category found, but not considered as making script to fail:"
|
2020-06-27 21:25:22 +02:00
|
|
|
grep "${category}," ${LOG_FILE} | grep -v -e "clarifyCalculation," -e "duplicateExpressionTernary," -e "redundantCondition," -e "unusedPrivateFunction," -e "postfixOperator,"
|
2020-06-01 21:42:02 +02:00
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-06-14 15:57:20 +02:00
|
|
|
# unusedPrivateFunction not reliable enough in cppcheck 1.72 of Ubuntu 16.04
|
|
|
|
if test "$(cppcheck --version)" = "Cppcheck 1.72"; then
|
|
|
|
UNUSED_PRIVATE_FUNCTION=""
|
|
|
|
else
|
|
|
|
UNUSED_PRIVATE_FUNCTION="unusedPrivateFunction"
|
|
|
|
fi
|
|
|
|
|
2020-06-27 21:25:22 +02:00
|
|
|
for category in "error" "warning" "clarifyCalculation" "duplicateExpressionTernary" "redundantCondition" "postfixOperator" "${UNUSED_PRIVATE_FUNCTION}"; do
|
2020-06-14 15:57:20 +02:00
|
|
|
if test "${category}" != ""; then
|
|
|
|
if grep "${category}," ${LOG_FILE} >/dev/null; then
|
|
|
|
echo "ERROR: Issues in '${category}' category found:"
|
|
|
|
grep "${category}," ${LOG_FILE}
|
|
|
|
echo ""
|
|
|
|
echo "${category} check failed !"
|
|
|
|
ret_code=1
|
|
|
|
fi
|
2020-06-02 00:39:17 +02:00
|
|
|
fi
|
|
|
|
done
|
2020-06-01 21:42:02 +02:00
|
|
|
|
|
|
|
if [ ${ret_code} = 0 ]; then
|
|
|
|
echo "cppcheck succeeded"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit ${ret_code}
|