| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | #!/bin/bashset -eclearcd $(dirname $0)compiler="gcc"if [ -e compiler ]; then    compiler=$(cat compiler)    echo "compiling with $compiler"fiprintHelpExit() {    echo "$0 clean           | remove build results"    echo "$0 build <type>    | build everything"    echo "$0 install         | move build results into the install folder"    echo "$0 test <type>     | run the tests"    echo "$0 valgrind <type> | run the tests with valgrind"    echo "$0 coverage        | generate code coverage"    echo "$0 performance     | run the performance tests"    echo "$0 macro           | find macros without CORE"     echo "$0 time            | check build time"    exit 0}task=$1if [ -z "$task" ]; then    printHelpExitfi# task varsbuild_debug=falsebuild_release=falsetest_debug=falsetest_release=falsevalgrind=""performance=falsetime=falseinstall=falsecoverage=falseexport CMAKE_EXPORT_COMPILE_COMMANDS=true# parsingif [ "$task" = "clean" ]; then    rm -rf build_debug build_release installelif [ "$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    fielif [ "$task" = "install" ]; then    build_release=true    install=trueelif [ "$task" = "coverage" ]; then    build_debug=true    test_debug=true    coverage=trueelif [ "$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    fielif [ "$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=trueelif [ "$task" = "time" ]; then    build_release=true    time=trueelif [ "$task" = "macro" ]; then    grep -r "#define" src include | grep -v " CORE" || true    exit 0else    echo "unknown task"    printHelpExitfi# task executionbuildProfile() {    folder=$1    shift 1    if [ ! -e "$folder" ]; then         cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=./install $@    fi    ninja -C "$folder"}if $build_debug; then    buildProfile build_debug -DCMAKE_BUILD_TYPE=Debugfiif $build_release; then    buildProfile build_release -DCMAKE_BUILD_TYPE=Releasefiif $install; then    ninja -C build_release installfifunction runTests() {    echo "--------------Invalid alloc exit----------------"    LLVM_PROFILE_FILE="alloc.profraw" $valgrind ./test alloc $valgrind || true    echo "--------------Invalid realloc exit--------------"    LLVM_PROFILE_FILE="realloc.profraw" $valgrind ./test realloc $valgrind || true    echo "--------------Pre canary detection--------------"    LLVM_PROFILE_FILE="pre_canary.profraw" $valgrind ./test pre_canary $valgrind || true    echo "--------------Post canary detection-------------"    LLVM_PROFILE_FILE="post_canary.profraw" $valgrind ./test post_canary $valgrind || true    echo "--------------Default run-----------------------"    LLVM_PROFILE_FILE="default.profraw" $valgrind ./test light $valgrind || true}if $test_debug; then    cd build_debug    runTests    cd ..fiif $test_release; then    cd build_release    runTests    cd ..fiif $performance; then    cd build_release    ./performance    cd ..fiif $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 -nfiif $coverage; then    if [ $compiler = "gcc" ]; then        gcovr -r . build_debug -e test -e performance \            --exclude-lines-by-pattern ".*CoverageIgnore.*"    else        files=$(find build_debug -name *.profraw)        llvm-profdata-16 merge -sparse $files -o build_debug/default.profdata        llvm-cov-16 show ./build_debug/test -instr-profile=build_debug/default.profdata --ignore-filename-regex="test/" -line-coverage-lt=100    fifi 
 |