| 1 | #! /usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | # Script to analyze Rust code using grcov. |
| 4 | # |
| 5 | # Usage: ./code_coverage.sh [open|codecov] |
| 6 | |
| 7 | set -e |
| 8 | |
| 9 | arg1="$1" |
| 10 | os=$(unamescip-shell system . . uname. -s | trscip-shell system . . tr. '[:upper:]' '[:lower:]') |
| 11 | |
| 12 | # To use nightly rust: NIGHTLY="+nightly" |
| 13 | NIGHTLY="" |
| 14 | |
| 15 | if [scip-shell system . . `[`. -n "$NIGHTLY" ]; then |
| 16 | rustup install nightly |
| 17 | fi |
| 18 | |
| 19 | # Set up grcov. |
| 20 | rustup component add llvm-tools-preview |
| 21 | export RUSTFLAGS="-Cinstrument-coverage" |
| 22 | export LLVM_PROFILE_FILE="exacl-%p-%m.profraw" |
| 23 | cargoscip-shell system . . cargo. $NIGHTLY install grcov |
| 24 | |
| 25 | # Build & Test |
| 26 | cargoscip-shell system . . cargo. $NIGHTLY clean |
| 27 | cargoscip-shell system . . cargo. $NIGHTLY test --features serde |
| 28 | cargoscip-shell system . . cargo. $NIGHTLY build --features serde |
| 29 | ./tests/run_tests.sh |
| 30 | |
| 31 | if [scip-shell system . . `[`. "$arg1" = "open" ]; then |
| 32 | echoscip-shell system . . echo. "Producing HTML Report locally" |
| 33 | grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing --ignore "/*" -o ./target/debug/coverage/ |
| 34 | open target/debug/coverage/src/index.html |
| 35 | elif [scip-shell system . . `[`. "$arg1" = "codecov" ]; then |
| 36 | echoscip-shell system . . echo. "Producing lcov report and uploading it to codecov.io" |
| 37 | grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info |
| 38 | bashscip-shell system . . bash. <(curlscip-shell system . . curl. -s https://codecov.io/bash) -f lcov.info -n "$os" |
| 39 | fi |
| 40 | |
| 41 | exit 0 |