-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathbuild-code_coverage.sh
More file actions
executable file
·71 lines (61 loc) · 3.22 KB
/
build-code_coverage.sh
File metadata and controls
executable file
·71 lines (61 loc) · 3.22 KB
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
#!/usr/bin/env bash
# spell-checker:ignore (abbrevs/acronyms) HTML gcno llvm
# spell-checker:ignore (jargon) toolchain
# spell-checker:ignore (rust) Ccodegen Cinline Coverflow Cpanic RUSTC RUSTDOCFLAGS RUSTFLAGS RUSTUP Zpanic
# spell-checker:ignore (shell) OSID OSTYPE esac
# spell-checker:ignore (utils) genhtml grcov lcov greadlink readlink sccache shellcheck uutils
FEATURES_OPTION="--features feat_os_unix"
# Use GNU coreutils for readlink on *BSD
case "$OSTYPE" in
*bsd*)
READLINK="greadlink"
;;
*)
READLINK="readlink"
;;
esac
ME="${0}"
ME_dir="$(dirname -- "$("${READLINK}" -fm -- "${ME}")")"
REPO_main_dir="$(dirname -- "${ME_dir}")"
cd "${REPO_main_dir}" &&
echo "[ \"$PWD\" ]"
#shellcheck disable=SC2086
UTIL_LIST=$("${ME_dir}"/show-utils.sh ${FEATURES_OPTION})
CARGO_INDIVIDUAL_PACKAGE_OPTIONS=""
for UTIL in ${UTIL_LIST}; do
if [ -n "${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}" ]; then CARGO_INDIVIDUAL_PACKAGE_OPTIONS="${CARGO_INDIVIDUAL_PACKAGE_OPTIONS} "; fi
CARGO_INDIVIDUAL_PACKAGE_OPTIONS="${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}-puu_${UTIL}"
done
# echo "CARGO_INDIVIDUAL_PACKAGE_OPTIONS=${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}"
# cargo clean
export CARGO_INCREMENTAL=0
export RUSTC_WRAPPER="" ## NOTE: RUSTC_WRAPPER=='sccache' breaks code coverage calculations (uu_*.gcno files are not created during build)
# export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"
export RUSTUP_TOOLCHAIN="nightly-gnu"
#shellcheck disable=SC2086
{
cargo build ${FEATURES_OPTION}
cargo test --no-run ${FEATURES_OPTION}
cargo test --quiet ${FEATURES_OPTION}
cargo test --quiet ${FEATURES_OPTION} ${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}
}
export COVERAGE_REPORT_DIR
if [ -z "${COVERAGE_REPORT_DIR}" ]; then COVERAGE_REPORT_DIR="${REPO_main_dir}/target/debug/coverage-nix"; fi
rm -r "${COVERAGE_REPORT_DIR}" 2>/dev/null
mkdir -p "${COVERAGE_REPORT_DIR}"
## NOTE: `grcov` is not accepting environment variable contents as options for `--ignore` or `--excl_br_line`
# export GRCOV_IGNORE_OPTION="--ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*'"
# export GRCOV_EXCLUDE_OPTION="--excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()'"
# * build LCOV coverage file
grcov . --output-type lcov --output-path "${COVERAGE_REPORT_DIR}/../lcov.info" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*' --excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()'
# * build HTML
# -- use `genhtml` if available for display of additional branch coverage information
if genhtml --version 2>/dev/null 1>&2; then
genhtml "${COVERAGE_REPORT_DIR}/../lcov.info" --output-directory "${COVERAGE_REPORT_DIR}" --branch-coverage --function-coverage | grep ": [0-9]"
else
grcov . --output-type html --output-path "${COVERAGE_REPORT_DIR}" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*' --excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()'
fi
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then exit 1; fi