Skip to content

Commit 979f34d

Browse files
author
Tamas Vajk
committed
Add RUST_COVERAGE_IGNORE_REGEX for configurable coverage filtering
The llvm-cov export step hardcodes two ignore patterns (external/, /tmp/). Projects often need additional filters for third-party C code, generated files, or stdlib sources, but editing the coverage script is not practical. Add support for the RUST_COVERAGE_IGNORE_REGEX environment variable: a comma-separated list of additional -ignore-filename-regex patterns passed to llvm-cov. Users can set this via --test_env in .bazelrc: coverage --test_env=RUST_COVERAGE_IGNORE_REGEX=.*third_party/.*,^bazel-out/
1 parent f31db8b commit 979f34d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

util/collect_coverage/collect_coverage.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,20 @@ fn main() {
190190
.arg("-instr-profile")
191191
.arg(&profdata_file)
192192
.arg("-ignore-filename-regex=.*external/.+")
193-
.arg("-ignore-filename-regex=/tmp/.+")
193+
.arg("-ignore-filename-regex=/tmp/.+");
194+
195+
// Allow additional ignore patterns via RUST_COVERAGE_IGNORE_REGEX env var
196+
// (comma-separated list of regexes passed to llvm-cov -ignore-filename-regex).
197+
if let Ok(extra) = env::var("RUST_COVERAGE_IGNORE_REGEX") {
198+
for pattern in extra.split(',') {
199+
let pattern = pattern.trim();
200+
if !pattern.is_empty() {
201+
llvm_cov_cmd.arg(format!("-ignore-filename-regex={}", pattern));
202+
}
203+
}
204+
}
205+
206+
llvm_cov_cmd
194207
.arg(format!("-path-equivalence=.,{}", execroot.display()))
195208
.arg(test_binary)
196209
.stdout(process::Stdio::piped())

0 commit comments

Comments
 (0)