Skip to content

Commit

Permalink
Ditch cargo-cov
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Dec 18, 2018
1 parent 319e569 commit afe6ca5
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 82 deletions.
86 changes: 4 additions & 82 deletions ci/test-nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -e

cd "$(dirname "$0")/.."


if ci/is-pr.sh; then
affectedFiles="$(buildkite-agent meta-data get affected_files)"
echo "Affected files in this PR: $affectedFiles"
Expand All @@ -15,94 +14,17 @@ if ci/is-pr.sh; then
fi
fi


source ci/upload-ci-artifact.sh
ci/version-check.sh stable
export RUST_BACKTRACE=1

_() {
echo "--- $*"
"$@"
}

# Uncomment this to run nightly test suit
# _ cargo test --all --verbose --features=unstable -- --test-threads=1

cargo_install_unless() {
declare crate=$1
shift

"$@" > /dev/null 2>&1 || \
_ cargo install "$crate"
}

cargo_install_unless cargo-cov cargo cov --help

_ cargo cov clean
_ cargo cov build --all --verbose
_ cargo cov test --all --lib --verbose
_ ./scripts/fetch-grcov.sh
ci/version-check.sh nightly

# TODO:
######## find . -name "*.gcda" | xargs ls -lh

echo "--- grcov"
./grcov . -t lcov > lcov.info

echo "--- filter_non_local_files_from_lcov"
filter_non_local_files_from_lcov() {
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
# Skip relative paths that don't exist
declare file="${BASH_REMATCH[1]}"
if [[ -r $file ]]; then
skip=false
else
skip=true
fi
fi
[[ $skip = true ]] || echo "$line"
done
}

filter_non_local_files_from_lcov < lcov.info > lcov_local.info
scripts/coverage.sh

echo "--- codecov.io report"
if [[ -z "$CODECOV_TOKEN" ]]; then
echo "^^^ +++"
echo CODECOV_TOKEN undefined, codecov.io upload skipped
else
bash <(curl -s https://codecov.io/bash) -X gcov -f lcov_info.info
bash <(curl -s https://codecov.io/bash) -X gcov -f lcov.info
fi


echo "--- html report"
: "${BUILDKITE_COMMIT:=local}"
reportName="report-lcov-${BUILDKITE_COMMIT:0:9}"

# Tip: genhtml comes from |brew install lcov| or |apt-get install lcov|
genhtml \
--output-directory target/cov/$reportName \
--show-details \
--highlight \
--ignore-errors source \
--legend \
--prefix "$PWD" \
lcov_local.info

ls -l target/cov/$reportName/index.html
(
set -x
cd target/cov
tar zcf $reportName.tar.gz $reportName
)
_ upload-ci-artifact "target/cov/$reportName.tar.gz"

gzip lcov.info
_ upload-ci-artifact "lcov.info.gz"

gzip lcov_local.info
_ upload-ci-artifact "lcov_local.info.gz"
_ upload-ci-artifact target/cov/report.tar.gz
82 changes: 82 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash
#
# Runs all tests and collects code coverage
#
# Warning: this process is a little slow
#

set -e
cd "$(dirname "$0")"

_() {
echo "--- $*"
"$@"
}

: "${BUILDKITE_COMMIT:=local}"
reportName="lcov-${BUILDKITE_COMMIT:0:9}"

export RUSTFLAGS="
-Zprofile
-Zno-landing-pads
-Ccodegen-units=1
-Cinline-threshold=0
-Coverflow-checks=off
"
export CARGO_INCREMENTAL=0 # TODO: why does |cargo cov| not require this?
export RUST_BACKTRACE=1

echo "--- remove old coverage results"

if [[ -d target/cov ]]; then
find target/cov -name \*.gcda -print0 | xargs -0 rm -f
fi
rm -rf target/cov/$reportName

# TODO: why does |cargo cov| "appear" to work on stable?
_ cargo +nightly build --target-dir target/cov --all
# TODO: why does |test| cause a partial rebuild?
_ cargo +nightly test --target-dir target/cov --lib --all

_ scripts/fetch-grcov.sh
echo "--- grcov"
./grcov target/cov/debug/deps/ > target/cov/lcov_full.info

echo "--- filter_non_local_files_from_lcov"
filter_non_local_files_from_lcov() {
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
# Skip relative paths that don't exist
declare file="${BASH_REMATCH[1]}"
if [[ -r $file ]]; then
skip=false
else
skip=true
fi
fi
[[ $skip = true ]] || echo "$line"
done
}

filter_non_local_files_from_lcov < target/cov/lcov_full.info > target/cov/lcov.info

echo "--- html report"

# Pro Tip: genhtml comes from |brew install lcov| or |apt-get install lcov|
genhtml --output-directory target/cov/$reportName \
--show-details \
--highlight \
--ignore-errors source \
--prefix "$PWD" \
--legend \
target/cov/lcov.info

(
cd target/cov
tar zcf report.tar.gz $reportName
)

ls -l target/cov/$reportName/index.html

0 comments on commit afe6ca5

Please sign in to comment.