Skip to content

Commit 559437e

Browse files
committed
fix: rustcov improvements
1 parent 1dfef6c commit 559437e

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

rustcov

+65-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# first (MacOS):
2727
# ```
2828
# rustup toolchain install nightly # for -Zprofile
29+
# rustup component add llvm-tools-preview
2930
# cargo install grcov
3031
# brew install lcov # for genhtml
3132
# ```
@@ -37,32 +38,84 @@ if [[ ! -f Cargo.toml ]] ; then
3738
exit -1
3839
fi
3940

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+
4062
# Assume that the name of the project is the same as `pwd`
4163
pname=$(basename `pwd`)
4264
uname=$(echo $pname | tr - _)
4365
tdir=target/coverage
4466

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}"
5082

5183
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/")
5393

5494
# 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
56103
rm -rf ${tdir}
57104

58-
cargo +nightly build --verbose
59-
cargo +nightly test --verbose
105+
# Actually (build and then) run tests
106+
cargo +nightly test --target ${target} "${@:$OPTIND}"
60107

61108
mkdir -p ${tdir}
62109

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+
66119
genhtml -o ${tdir}/report/ --show-details --highlight --ignore-errors source \
67120
--legend ${tdir}/lcov.info | tee ${tdir}/output
68121

0 commit comments

Comments
 (0)