#!/bin/bash set -e clear cd $(dirname $0) 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 } # TODO gcovr https://gcovr.com/en/5.0/guide.html task=$1 if [ -z "$task" ]; then printHelpExit fi # tasks build=false test=false valgrind=false performance=false time=false install=false coverage=false profile=$(cat profile) # parsing if [ "$task" = "clean" ]; then rm -rf build install exit 0 elif [ "$task" = "build" ]; then build=true elif [ "$task" = "install" ]; then build=true install=true elif [ "$task" = "coverage" ]; then build=true coverage=true test=true elif [ "$task" = "test" ]; then build=true test=true elif [ "$task" = "valgrind" ]; then build=true valgrind=true elif [ "$task" = "performance" ]; then build=true performance=true elif [ "$task" = "time" ]; then build=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 if $build; then if [ ! -e build ]; then cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install \ -DCMAKE_BUILD_TYPE=$profile fi ninja -C build fi if $install; then ninja -C build install fi if $test; then cd build ./test light || true cd .. fi if $valgrind; then cd build valgrind ./test light valgrind || true cd .. fi if $performance; then cd build ./performance fi if $time; then lines=$(cat build/.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 -e test -e performance fi