Skip to content

Commit ad60247

Browse files
committed
WIP: cov: ensure we use host llvm version and clear coverage data
1 parent e49a9bb commit ad60247

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.github/workflows/github-cxx-qt-tests.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ jobs:
7171
steps:
7272
- name: Checkout repository
7373
uses: actions/checkout@v4
74+
# Note we need to match the LLVM and Rust versions
75+
#
76+
# See versions from the table in this link
77+
# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary
78+
- name: Install llvm 17
79+
run: |
80+
sudo apt-get update && sudo apt-get install -y llvm-17
81+
test -d /usr/lib/llvm-17/bin/
7482
- name: Setup toolchain
7583
run: |
84+
# Note that the llvm version needs to match, see the link above
7685
rustup default 1.77.2
7786
cargo install grcov
78-
rustup component add llvm-tools rustfmt
87+
rustup component add rustfmt
88+
# Ensure we do not have any existing coverage files
89+
- run: rm -f coverage/*.profraw
7990
- name: build
8091
env:
8192
RUSTFLAGS: -Cinstrument-coverage
@@ -87,7 +98,7 @@ jobs:
8798
LLVM_PROFILE_FILE: coverage/coverage_data-%p-%m.profraw
8899
run: cargo test --lib --package cxx-qt-gen
89100
- name: generate-report
90-
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
101+
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
91102
- name: upload-report
92103
uses: codecov/codecov-action@v5
93104
with:

scripts/grcov_cxx_qt.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
#
66
# SPDX-License-Identifier: MIT OR Apache-2.0
77

8-
# Assumes you have grcov and llvm-tools
8+
# Assumes you have grcov and llvm in a system path
99
# Install:
1010
# cargo install grcov
11-
# rustup component add llvm-tools
1211
set -ex
12+
1313
# Ensure we are in the right directory
1414
SCRIPT=$(realpath "$0")
1515
SCRIPTPATH=$(dirname "$SCRIPT")
1616
cd "$SCRIPTPATH/../"
1717

18+
# Ensure coverage folder is cleared
19+
rm -f "$SCRIPTPATH"/coverage/*.profraw
20+
21+
# Check that the llvm path exists
22+
#
23+
# We can use rustup component add llvm-tools but this can be out of sync
24+
# See versions from the table in this link
25+
# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary
26+
if [ ! -d /usr/lib/llvm-17/bin/ ]; then
27+
echo "LLVM 17 not found"
28+
fi
29+
1830
export RUSTFLAGS="-Cinstrument-coverage"
1931
export LLVM_PROFILE_FILE="$SCRIPTPATH/coverage/coverage_data-%p-%m.profraw"
2032
cargo build --package cxx-qt-gen
2133
cargo test --package cxx-qt-gen
22-
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
23-
echo "Coverage html report generated in $(realpath "$SCRIPTPATH"/../target/debug/html)"
34+
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
35+
echo "Coverage html report generated in $(realpath "$SCRIPTPATH"/../target/debug/html)"

0 commit comments

Comments
 (0)