Add RUST_COVERAGE_IGNORE_REGEX for configurable coverage filtering#3999
Add RUST_COVERAGE_IGNORE_REGEX for configurable coverage filtering#3999tamasvajk wants to merge 1 commit intobazelbuild:mainfrom
RUST_COVERAGE_IGNORE_REGEX for configurable coverage filtering#3999Conversation
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/
be1b0e8 to
979f34d
Compare
UebelAndre
left a comment
There was a problem hiding this comment.
Thanks! Is there any prior-art for this in other rules? I'm wondering if a custom environment variable is really needed
I couldn't find direct prior art in other Bazel rule sets — C++ coverage in Bazel uses The env var approach was chosen because the filtering happens at runtime (in the An alternative would be to add a build setting like |
Summary
Add
RUST_COVERAGE_IGNORE_REGEXenvironment variable for configurablellvm-cov exportfiltering.Problem
The
collect_coverage.rsscript hardcodes two-ignore-filename-regexpatterns (.*external/.+and/tmp/.+) passed tollvm-cov export. Projects often need additional filters — for example, to exclude vendored C/C++ code or generated files — but there's no way to add them without patching the script.Fix
Read an optional
RUST_COVERAGE_IGNORE_REGEXenvironment variable: a comma-separated list of additional regex patterns passed as-ignore-filename-regexarguments tollvm-cov. The existing hardcoded patterns are preserved as defaults.Users can set this via
--test_envin.bazelrc: