summaryrefslogtreecommitdiffhomepage
path: root/run-show-coverage.sh
blob: cdd7503c4fd21837cdd047ab5fe79330a058beee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh

set -e

case "$OS" in
    Windows_NT) export PATH="$PATH:/usr/bin" ;;
esac

self="$(basename -- "$1")"

usage() {
    echo "usage: ${self} <all|compile|run|generate|open>..." >&2
    exit 64
}

if test -z "$1"; then
    usage
fi

compile=0
run=0
generate=0
open=0

while test $# -gt 0; do
    case "$1" in
        all) compile=1; run=1; generate=1; open=1 ;;
        compile) compile=1 ;;
        run) compile=1; run=1 ;;
        generate) generate=1 ;;
        open) open=1 ;;
        *) echo "error: invalid command-line argument '$1'" >&2; usage ;;
    esac
    shift
done

#find build directory
build="build-coverage"
if test -f CMakeLists.txt && test -f resources.conf; then
    cd ./"${build}"
elif test -d bin; then
    cd ../../"${build}"
elif test -x floormat-editor || test -x floormat-editor.exe; then
    cd ../../"${build}"
elif test -d install/bin && test -d install/share/floormat; then
    cd ../"${build}"
elif test "./CMakeCache.txt"; then
    cd ../"${build}"
else
    echo "error: can't find build directory!" >&2
    exit 65
fi

if ! test -f "./CMakeCache.txt"; then
    echo "error: no CMakeCache.txt in build directory!"
    exit 65
fi

exe=
for i in ./install/bin/floormat-editor.exe ./install/bin/floormat-editor; do
    if test -x "$i"; then
        exe="$i"
        break
    fi
done


prof=coverage

if test $compile -gt 0; then
    rm -f -- ./"${prof}".profraw ./"${prof}".profdata ../"${prof}".lcov
    cmake -DFLOORMAT_WITH-COVERAGE:BOOL=1 .
    cmake --build . --target install
fi

if test $run -gt 0; then
    if ! test -n "$exe"; then
        echo "error: no 'floormat-editor' executable" >&2
        exit 65
    fi
    case "$OS" in
        Windows_NT) profdir="$(cygpath -m -- "$PWD")" ;;
        *) profdir="$PWD" ;;
    esac
    LLVM_PROFILE_FILE="$profdir/${prof}.profraw" "$exe" --gpu-debug full --vsync on
fi

if test $generate -gt 0; then
    llvm-profdata merge -sparse "./${prof}".profraw -o "./${prof}".profdata
    llvm-cov export --format=lcov --instr-profile="./${prof}".profdata -- "$exe" > "./${prof}".lcov
    if test -e "./${prof}"; then
        rm -rf -- "./${prof}/"
    fi
    genhtml -o "./${prof}" -s "./${prof}.lcov"
fi

if test $open -gt 0; then
    if command -v xdg-open >/dev/null; then
        xdg-open "./${prof}/index.html"
    else
        start "./${prof}/index.html"
    fi
fi

exit 0