From 020b13d80ceec7f8ac8cffeae80e8b1162c17f60 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 14 Dec 2020 11:55:36 -0800 Subject: [PATCH] Fix coverage on macOS --- coverage.sh | 53 +++++++++-------------------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/coverage.sh b/coverage.sh index f75214e7..e21e0fc9 100755 --- a/coverage.sh +++ b/coverage.sh @@ -10,12 +10,12 @@ if ! which grcov; then echo "Error: grcov not found. Try |cargo install grcov|" exit 1 fi -if ! which genhtml; then - echo "Error: genthml not found. Try |brew install lcov| or |apt-get install lcov|" + +if [[ ! "$(grcov --version)" =~ "0.6.1" ]]; then + echo Error: Required grcov version not installed exit 1 fi - : "${CI_COMMIT:=local}" reportName="lcov-${CI_COMMIT:0:9}" @@ -27,13 +27,14 @@ if [[ -z $1 ]]; then token-swap/program ) else - programs=( "$@" ) + programs=("$@") fi coverageFlags=(-Zprofile) # Enable coverage coverageFlags+=("-Clink-dead-code") # Dead code should appear red in the report coverageFlags+=("-Ccodegen-units=1") # Disable code generation parallelism which is unsupported under -Zprofile (see [rustc issue #51705]). coverageFlags+=("-Cinline-threshold=0") # Disable inlining, which complicates control flow. +coverageFlags+=("-Copt-level=0") # coverageFlags+=("-Coverflow-checks=off") # Disable overflow checks, which create unnecessary branches. export RUSTFLAGS="${coverageFlags[*]} $RUSTFLAGS" @@ -78,47 +79,11 @@ find target/cov -type f -name '*.gcda' -newer target/cov/before-test ! -newer ta ln -sf "../../../$gcno_file" "target/cov/tmp/$(basename "$gcno_file")" done) -grcov target/cov/tmp > target/cov/lcov-full.info - -echo "--- filter-files-from-lcov" - -# List of directories to remove from the coverage report -ignored_filepaths="build\.rs" - -filter-files-from-lcov() { - # this function is too noisy for casual bash -x - set +x - declare skip=false - while read -r line; do - if [[ $line =~ ^SF:/ ]]; then - skip=true # Skip all absolute paths as these are references into ~/.cargo - elif [[ $line =~ ^SF:(.*) ]]; then - declare file="${BASH_REMATCH[1]}" - if [[ $file =~ $ignored_filepaths ]]; then - skip=true # Skip paths into ignored locations - elif [[ -r $file ]]; then - skip=false - else - skip=true # Skip relative paths that don't exist - fi - fi - [[ $skip = true ]] || echo "$line" - done -} - -filter-files-from-lcov < target/cov/lcov-full.info > target/cov/lcov.info - -echo "--- html report" - -genhtml --output-directory target/cov/$reportName \ - --show-details \ - --highlight \ - --ignore-errors source \ - --prefix "$PWD" \ - --legend \ - target/cov/lcov.info - ( + set -x + grcov target/cov/tmp --llvm -t html -o target/cov/$reportName + grcov target/cov/tmp --llvm -t lcov -o target/cov/lcov.info + cd target/cov tar zcf report.tar.gz $reportName )