server-sdk/scripts/cppcheck.sh
2019-11-06 13:37:28 +01:00

59 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# @see https://intoli.com/blog/exit-on-errors-in-bash-scripts/
set -e
trap 'LASTRES=$?; LAST=$BASH_COMMAND; if [[ "$LASTRES" -ne 0 ]]; then fail "Command: \"$LAST\" exited with exit code: $LASTRES"; elif [ "$FAIL" == "true" ]; then fail finished with error; exit 1; else pass "finished";fi' EXIT
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIRNAME="${CURRENT_DIR##*/}"
SOURCE_DIR=$PWD
exclude_dir=build
check_dir=$CURRENT_DIR/../src
suppress="--suppress=missingInclude --suppress=unusedFunction"
FAIL=0
main() {
if [ ! -d src ]; then
fail "src dir does not exists"
else
pass "src dir exits"
fi
{ ERROR="$( { cppcheck $check_dir $suppress --enable=all -i $exclude_dir; } 2>&1 1>&3 3>&- )"; } 3>&1;
if [ ! -z "$ERROR" ]; then
echo "----------------------------------"
echo "$ERROR"
echo "----------------------------------"
fail "Cppcheck finished with error"
fi
}
# ################
# Output funcitons
# ################
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
function info () {
echo -e "[${BLUE} $@ ${NC}]"
}
function pass() {
echo -e "[${GREEN}PASS${NC}] $@"
}
function fail() {
FAIL="true"; echo -e "[${RED}FAIL${NC}] $@"
exit
}
# Run main function
main "$@"