Skip to content

Commit

Permalink
WIP: cov: ensure we use host llvm version and clear coverage data
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Jan 27, 2025
1 parent e49a9bb commit ad60247
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/github-cxx-qt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,22 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Note we need to match the LLVM and Rust versions
#
# See versions from the table in this link
# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary
- name: Install llvm 17
run: |
sudo apt-get update && sudo apt-get install -y llvm-17
test -d /usr/lib/llvm-17/bin/
- name: Setup toolchain
run: |
# Note that the llvm version needs to match, see the link above
rustup default 1.77.2
cargo install grcov
rustup component add llvm-tools rustfmt
rustup component add rustfmt
# Ensure we do not have any existing coverage files
- run: rm -f coverage/*.profraw
- name: build
env:
RUSTFLAGS: -Cinstrument-coverage
Expand All @@ -87,7 +98,7 @@ jobs:
LLVM_PROFILE_FILE: coverage/coverage_data-%p-%m.profraw
run: cargo test --lib --package cxx-qt-gen
- name: generate-report
run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./target/debug/lcov.info --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP
run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing --llvm --llvm-path /usr/lib/llvm-17/bin/ -o ./target/debug/lcov.info --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP
- name: upload-report
uses: codecov/codecov-action@v5
with:
Expand Down
20 changes: 16 additions & 4 deletions scripts/grcov_cxx_qt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@
#
# SPDX-License-Identifier: MIT OR Apache-2.0

# Assumes you have grcov and llvm-tools
# Assumes you have grcov and llvm in a system path
# Install:
# cargo install grcov
# rustup component add llvm-tools
set -ex

# Ensure we are in the right directory
SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
cd "$SCRIPTPATH/../"

# Ensure coverage folder is cleared
rm -f "$SCRIPTPATH"/coverage/*.profraw

# Check that the llvm path exists
#
# We can use rustup component add llvm-tools but this can be out of sync
# See versions from the table in this link
# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary
if [ ! -d /usr/lib/llvm-17/bin/ ]; then
echo "LLVM 17 not found"
fi

export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE="$SCRIPTPATH/coverage/coverage_data-%p-%m.profraw"
cargo build --package cxx-qt-gen
cargo test --package cxx-qt-gen
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/ --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP
echo "Coverage html report generated in $(realpath "$SCRIPTPATH"/../target/debug/html)"
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing --llvm --llvm-path=/usr/lib/llvm-17/bin/ -o ./target/debug/ --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP
echo "Coverage html report generated in $(realpath "$SCRIPTPATH"/../target/debug/html)"

0 comments on commit ad60247

Please sign in to comment.