updating scripts

This commit is contained in:
Filip Bucek 2019-11-06 14:33:03 +01:00
parent 4d3c06304f
commit 08127bad50
4 changed files with 59 additions and 63 deletions

View File

@ -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"

38
scripts/common.sh Normal file
View File

@ -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}] $@"
}

View File

@ -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"
EXCLUDE_DIR=build
CHECK_DIR=$SOURCE_DIR/src
SUPPRESS="--suppress=missingInclude --suppress=unusedFunction"
FAIL=0
main() {
if [ ! -d src ]; then
info cppcheck version: `cppcheck --version`
if [ ! -d src ]; then
fail "src dir does not exists"
else
else
pass "src dir exits"
fi
fi
{ ERROR="$( { cppcheck $check_dir $suppress --enable=all -i $exclude_dir; } 2>&1 1>&3 3>&- )"; } 3>&1;
{ ERROR="$( { cppcheck $CHECK_DIR $SUPPRESS --enable=all -i $EXCLUDE_DIR; } 2>&1 1>&3 3>&- )"; } 3>&1;
if [ ! -z "$ERROR" ]; then
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 "$@"
fi

View File

@ -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"