#!/bin/bash set -e clear cd $(dirname $0) compiler="g++" if [ -e compiler ]; then compiler=$(cat compiler) echo "compiling with $compiler" fi printHelpExit() { echo "$0 clean | remove build results" echo "$0 build | build everything" echo "$0 install | move build results into the install folder" echo "$0 test | run the tests" echo "$0 valgrind | run the tests with valgrind" echo "$0 coverage | generate code coverage" echo "$0 performance | run the performance tests" echo "$0 final | find classes / structs which are not final" echo "$0 macro | find macros without CORE" echo "$0 include | find system includes" echo "$0 time | check build time" exit 0 } task=$1 if [ -z "$task" ]; then printHelpExit fi # task vars build_debug=false build_release=false test_debug=false test_release=false valgrind="" performance=false time=false install=false coverage=false export CMAKE_EXPORT_COMPILE_COMMANDS=true # parsing if [ "$task" = "clean" ]; then rm -rf build_debug build_release install elif [ "$task" = "build" ]; then type=$2 if [ "$type" = "debug" ]; then build_debug=true elif [ "$type" = "release" ]; then build_release=true elif [ "$type" = "all" ]; then build_debug=true build_release=true else echo "Valid build types are: debug, release, all" printHelpExit fi elif [ "$task" = "install" ]; then build_release=true install=true elif [ "$task" = "coverage" ]; then build_debug=true test_debug=true coverage=true elif [ "$task" = "test" ]; then type=$2 if [ "$type" = "debug" ]; then build_debug=true test_debug=true elif [ "$type" = "release" ]; then build_release=true test_release=true elif [ "$type" = "all" ]; then build_debug=true test_debug=true build_release=true test_release=true else echo "Valid test types are: debug, release, all" printHelpExit fi elif [ "$task" = "valgrind" ]; then type=$2 if [ "$type" = "debug" ]; then build_debug=true test_debug=true elif [ "$type" = "release" ]; then build_release=true test_release=true elif [ "$type" = "all" ]; then build_debug=true test_debug=true build_release=true test_release=true else echo "Valid valgrind types are: debug, release, all" printHelpExit fi valgrind="valgrind" elif [ "$task" = "performance" ]; then build_release=true performance=true elif [ "$task" = "time" ]; then build_release=true time=true elif [ "$task" = "final" ]; then grep -r " class" src include | grep -v -E 'final|enum|.git' || true grep -r " struct" src include | grep -v -E 'final|enum|.git' || true exit 0 elif [ "$task" = "macro" ]; then grep -r "#define" src include | grep -v " CORE" || true exit 0 elif [ "$task" = "include" ]; then echo "System includes in header files:" grep -r "#include <" src include | grep "\.hpp" || true echo "-------------------------------------------------" echo "System includes in source files:" grep -r "#include <" src include | grep "\.cpp" || true exit 0 else echo "unknown task" printHelpExit fi # task execution buildProfile() { folder=$1 shift 1 if [ ! -e "$folder" ]; then cmake -B "$folder" -S . -G Ninja -DCMAKE_CXX_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=./install $@ fi ninja -C "$folder" } if $build_debug; then buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug fi if $build_release; then buildProfile build_release -DCMAKE_BUILD_TYPE=Release fi if $install; then ninja -C build_release install fi if $test_debug; then cd build_debug $valgrind ./test light $valgrind || true cd .. fi if $test_release; then cd build_release $valgrind ./test light $valgrind || true cd .. fi if $performance; then cd build_release ./performance cd .. fi if $time; then lines=$(cat build_release/.ninja_log | grep "^[0-9]") startMillis=0 endMillis=0 name="" i=0 output="" for arg in $lines; do if [ $i == 0 ]; then startMillis=$arg elif [ $i == 1 ]; then endMillis=$arg elif [ $i == 3 ]; then name=$arg diff=$(expr $endMillis - $startMillis) output="${output}\n$diff $name" fi i=$(expr $(expr $i + 1) % 5) && true done printf "$output" | sort -n fi if $coverage; then gcovr -r . build_debug -e test -e performance \ --exclude-lines-by-pattern ".*CoverageIgnore.*" fi