ci-cppcheck.sh 1.46 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash

# Exit script on any error
set -e 

#=====================================
# Color Settings:
#=====================================
NC='\033[0m'
OUTPUT='\033[0;32m'
WARNING='\033[0;93m'

13 14 15 16 17 18
BUILDPATH="build-cppcheck"
mkdir -p "${BUILDPATH}"
cd "${BUILDPATH}"
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
cd ..

Jan Möbius's avatar
Jan Möbius committed
19 20 21
echo -e "${OUTPUT}"
echo "=============================================================================="
echo "Running cppcheck"
22 23
echo -n "Version: "
cppcheck --version
Jan Möbius's avatar
Jan Möbius committed
24 25 26 27 28
echo "=============================================================================="
echo -e "${NC}"
echo "Please Wait ..."

# Run cppcheck and output into file
29 30 31 32 33 34 35 36 37
# we do not enable 'style' and 'unusedFunction' (the latter gives false positive
# for the public library interface)
cppcheck \
    --project=${BUILDPATH}/compile_commands.json \
    --enable=warning,performance,portability,information,missingInclude \
    --suppress=missingIncludeSystem \
    --inline-suppr \
    --quiet \
    2>&1 | tee cppcheck.log
Jan Möbius's avatar
Jan Möbius committed
38 39 40 41 42 43 44 45 46

COUNT=$(wc -l < cppcheck.log )

echo -e "${OUTPUT}"
echo "=============================================================================="
echo "CPPCHECK Summary"
echo "=============================================================================="
echo -e "${NC}"

47
if [ $COUNT -gt 5 ]; then
Jan Möbius's avatar
Jan Möbius committed
48 49 50 51 52 53 54 55 56
  echo -e ${WARNING}
  echo "Total CPPCHECK error Count is $COUNT, which is too High! CPPCHECK Run failed";
  echo -e "${NC}"
  exit 1;
else
  echo "Total CPPCHECK error Count is $COUNT ... OK"
fi