summaryrefslogtreecommitdiff
path: root/ci/gen-coverage.sh
blob: 328c9b4e618ab4869011806dfe6fe0e80ae8fff7 (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
#!/bin/sh

set -eu

mkdir -p public

call_grcov() {
    output_type=$1
    output_path=$2

    # Explanation of the options below:
    # grcov coverage-profiles _build               - paths where to find .rawprof (llvm) and .gcda (gcc) files, respectively
    #       --binary-path ./_build/target/debug/   - where the Rust test binaries are located
    #       --source-dir .                         - toplevel source directory
    #       --prefix-dir ../../                    - prefix to remove from C source files, since they are relative to builddir
    #       --branch                               - compute branch coverage if possible
    #       --ignore build.rs                      - https://github.com/mozilla/grcov/issues/845
    #       --ignore '**/build/markup5ever*'       - ignore generated code from dependencies
    #       --ignore '**/build/cssparser*'         - ignore generated code from dependencies
    #       --ignore 'cargo_cache/*'               - ignore code from dependencies
    #       --output-type $output_type
    #       --output-path $output_path

    grcov coverage-profiles _build               \
          --binary-path ./_build/target/debug/   \
          --source-dir .                         \
          --prefix-dir ../../                    \
          --branch                               \
          --ignore build.rs                      \
          --ignore '**/build/markup5ever*'       \
          --ignore '**/build/cssparser*'         \
          --ignore 'cargo_cache/*'               \
          --output-type $output_type             \
          --output-path $output_path
}

call_grcov html public/coverage

# Disable the cobertura report for now; it is only used for showing coverage
# in the diff view of merge requests.
#
# After switching to gcov-based instrumentation (-Zprofile in .gitlab-ci.yml), this
# coverage.xml is almost 500 MB and causes gitlab's redis to OOM.
#
# call_grcov cobertura coverage.xml

# Print "Coverage: 42.42" so .gitlab-ci.yml will pick it up with a regex
#
# grep -Eo 'line-rate="[^"]+"' coverage.xml | head -n 1 | grep -Eo '[0-9.]+' | awk '{ print "Coverage:", $1 * 100 }'