26
26
# first (MacOS):
27
27
# ```
28
28
# rustup toolchain install nightly # for -Zprofile
29
+ # rustup component add llvm-tools-preview
29
30
# cargo install grcov
30
31
# brew install lcov # for genhtml
31
32
# ```
@@ -37,32 +38,84 @@ if [[ ! -f Cargo.toml ]] ; then
37
38
exit -1
38
39
fi
39
40
41
+ usage() {
42
+ exitcode="$1"
43
+ cat << USAGE >&2
44
+ Usage:
45
+ $cmdname [options]
46
+ -d Run dirty (don't clean): only use this if you
47
+ haven't run cargo at all since the last rustcov.
48
+ -h Show this message
49
+ USAGE
50
+ exit "$exitcode"
51
+ }
52
+
53
+ # Get our options
54
+ dirty=0
55
+ while getopts "dh" opt ; do
56
+ case $opt in
57
+ d) dirty=1 ;;
58
+ h) usage 0 ;;
59
+ esac
60
+ done
61
+
40
62
# Assume that the name of the project is the same as `pwd`
41
63
pname=$(basename `pwd`)
42
64
uname=$(echo $pname | tr - _)
43
65
tdir=target/coverage
44
66
45
- if [[ $pname = $uname ]] ; then
46
- echo "running tests/coverage for ${pname}"
47
- else
48
- echo "running tests/coverage for ${pname} (${uname})"
49
- fi
67
+ cargo_targets=$(
68
+ IFS=$'\n'
69
+ meta=`cargo +nightly metadata --format-version 1`
70
+ for m in `jq -r '.workspace_members[]' <<< "$meta"` ; do
71
+ jq -r ".packages[] | select(.id == \"$m\") | .targets[] | select(.kind[0] != \"custom-build\") | .name" <<< "$meta" | tr - _
72
+ done
73
+ )
74
+ cargo_targets=$(xargs echo <<< "$cargo_targets")
75
+
76
+ workspace_members=$(
77
+ cargo +nightly metadata --format-version 1 | jq -r '.workspace_members[]' | cut -d' ' -f1
78
+ )
79
+ workspace_members=$(xargs echo <<< "$workspace_members")
80
+
81
+ echo "running tests/coverage for ${cargo_targets}"
50
82
51
83
export CARGO_INCREMENTAL=0
52
- export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"
84
+ export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
85
+ export RUSTDOCFLAGS="-Cpanic=abort"
86
+
87
+ # Inelegent, but effective. We use --target on the cargo command to
88
+ # prevent build scripts from seeing RUSTFLAGS (this is a
89
+ # perhaps-temporarily intention of cargo). Some build scripts like
90
+ # etcd-rs end up using panic/unwind, which panic=abort will cause to
91
+ # fail.
92
+ target=$(rustup show | grep default | sed -e "s/^[^-]*-\(.*\) .*/\1/")
53
93
54
94
# Painful, but we need a complete build to coverage check.
55
- cargo clean
95
+ if [ $dirty == "0" ] ; then
96
+ for w in "$workspace_members" ; do
97
+ cargo +nightly clean -p "$w" --target ${target}
98
+ done
99
+ find target -name '*.gc*' -delete
100
+ else
101
+ find target -name '*.gcda' -delete
102
+ fi
56
103
rm -rf ${tdir}
57
104
58
- cargo +nightly build --verbose
59
- cargo +nightly test --verbose
105
+ # Actually ( build and then) run tests
106
+ cargo +nightly test --target ${target} "${@:$OPTIND}"
60
107
61
108
mkdir -p ${tdir}
62
109
63
- zip -0 ${tdir}/ccov.zip `find . \( -name "${uname}*.gc*" \) -print`
64
- grcov ${tdir}/ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing \
65
- --ignore "/*" --ignore '*system*' -o ${tdir}/lcov.info
110
+ # zip -0 ${tdir}/ccov.zip `find . \( -name "${uname}*.gc*" \) -print`
111
+ # grcov ${tdir}/ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing \
112
+ # --ignore 'target/*' --ignore "/*" --ignore '*system*' \
113
+ # -o ${tdir}/lcov.info
114
+
115
+ grcov . -s . -t lcov --llvm --branch --ignore-not-existing \
116
+ --ignore 'target/*' --ignore "/*" --ignore '*system*' \
117
+ -o ${tdir}/lcov.info
118
+
66
119
genhtml -o ${tdir}/report/ --show-details --highlight --ignore-errors source \
67
120
--legend ${tdir}/lcov.info | tee ${tdir}/output
68
121
0 commit comments