From 08127bad506422d5e9aa003e93d9da8d2c40bff2 Mon Sep 17 00:00:00 2001 From: Filip Bucek Date: Wed, 6 Nov 2019 14:33:03 +0100 Subject: [PATCH] updating scripts --- scripts/codecoverage.sh | 9 ++---- scripts/common.sh | 38 +++++++++++++++++++++++ scripts/cppcheck.sh | 67 +++++++++++------------------------------ scripts/doc.sh | 8 +---- 4 files changed, 59 insertions(+), 63 deletions(-) create mode 100644 scripts/common.sh diff --git a/scripts/codecoverage.sh b/scripts/codecoverage.sh index 3b3694e..c007de0 100755 --- a/scripts/codecoverage.sh +++ b/scripts/codecoverage.sh @@ -1,13 +1,8 @@ #!/bin/bash -# @see https://intoli.com/blog/exit-on-errors-in-bash-scripts/ -set -e +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source $CURRENT_DIR/common.sh -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 - - -SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -DIRNAME="${SRCDIR##*/}" SOURCE_DIR=$PWD BUILDPATH=$SOURCE_DIR"/build/testcc" diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..7557f8d --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,38 @@ +# @see https://intoli.com/blog/exit-on-errors-in-bash-scripts/ +set -e + +function exit_function() { + LASTRES=$?; LAST=$BASH_COMMAND; # save last command and status + if [[ "$LASTRES" -ne 0 ]]; then + fail "Command: \"$LAST\" exited with exit code: $LASTRES"; + exit 1; + elif [ "$FAIL" == "true" ]; then + fail finished with error; + exit 1; + else + pass "finished"; + fi +} + +trap exit_function EXIT + +# ################ +# 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}] $@" +} + diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index 1733d22..ad3da2a 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -1,58 +1,27 @@ #!/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 $CURRENT_DIR/common.sh + SOURCE_DIR=$PWD -exclude_dir=build -check_dir=$SOURCE_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 -} +EXCLUDE_DIR=build +CHECK_DIR=$SOURCE_DIR/src +SUPPRESS="--suppress=missingInclude --suppress=unusedFunction" -# ################ -# Output funcitons -# ################ -RED='\033[0;31m' -GREEN='\033[0;32m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color +info cppcheck version: `cppcheck --version` +if [ ! -d src ]; then + fail "src dir does not exists" +else + pass "src dir exits" +fi -function info () { - echo -e "[${BLUE} $@ ${NC}]" -} +{ ERROR="$( { cppcheck $CHECK_DIR $SUPPRESS --enable=all -i $EXCLUDE_DIR; } 2>&1 1>&3 3>&- )"; } 3>&1; -function pass() { - echo -e "[${GREEN}PASS${NC}] $@" -} - -function fail() { - FAIL="true"; echo -e "[${RED}FAIL${NC}] $@" - exit -} - - -# Run main function -main "$@" +if [ ! -z "$ERROR" ]; then + echo "----------------------------------" + echo "$ERROR" + echo "----------------------------------" + fail "Cppcheck finished with error" +fi diff --git a/scripts/doc.sh b/scripts/doc.sh index 62fe130..7ee7a03 100755 --- a/scripts/doc.sh +++ b/scripts/doc.sh @@ -1,14 +1,8 @@ #!/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 )" -DIR_NAME="${CURRENT_DIR##*/}" +source $CURRENT_DIR/common.sh -FAIL=0 SOURCE_DIR=$PWD BUILD_DIR=$SOURCE_DIR"/build" DOC_DIR=$BUILD_DIR"/doc"