Skip to content

Commit 26d2d7e

Browse files
author
Tamas Vajk
committed
Set --instrumentation_filter for coverage in .bazelrc and CI
Without an explicit --instrumentation_filter, Bazel's default filter may not match workspace targets, causing ctx.coverage_instrumented() to return False and producing empty Rust coverage reports. Add coverage --instrumentation_filter=^// to both .bazelrc and all CI coverage tasks. Projects with vendored dependencies should narrow this, e.g.: coverage --instrumentation_filter=^//,-^//third_party
1 parent 718558f commit 26d2d7e

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ split_coverage_postprocessing_shell_commands: &split_coverage_postprocessing_she
9898
- echo "coverage --experimental_fetch_all_coverage_outputs" >> user.bazelrc
9999
- echo "coverage --experimental_split_coverage_postprocessing" >> user.bazelrc
100100
- echo "build --//rust/settings:experimental_use_coverage_metadata_files" >> user.bazelrc
101+
coverage_flags: &coverage_flags
102+
- "--instrumentation_filter=^//"
101103
rbe_coverage_flags: &rbe_coverage_flags
102104
# https://github.com/bazelbuild/bazel/issues/20578
103105
- "--strategy=CoverageReport=local"
106+
- "--instrumentation_filter=^//"
104107
tasks:
105108
ubuntu2204:
106109
build_targets: *default_linux_targets
107110
test_targets: *default_linux_targets
108111
coverage_targets: *default_linux_targets
112+
coverage_flags: *coverage_flags
109113
post_shell_commands: *coverage_validation_post_shell_commands
110114
run_targets:
111115
- //test:query_test_binary
@@ -123,6 +127,7 @@ tasks:
123127
build_targets: *default_macos_targets
124128
test_targets: *default_macos_targets
125129
coverage_targets: *default_macos_targets
130+
coverage_flags: *coverage_flags
126131
post_shell_commands: *coverage_validation_post_shell_commands
127132
windows:
128133
build_targets: *default_windows_targets
@@ -135,6 +140,7 @@ tasks:
135140
build_targets: *default_linux_targets
136141
test_targets: *default_linux_targets
137142
coverage_targets: *default_linux_targets
143+
coverage_flags: *coverage_flags
138144
post_shell_commands: *coverage_validation_post_shell_commands
139145
run_targets:
140146
- //test:query_test_binary
@@ -156,6 +162,7 @@ tasks:
156162
build_targets: *default_macos_targets
157163
test_targets: *default_macos_targets
158164
coverage_targets: *default_macos_targets
165+
coverage_flags: *coverage_flags
159166
post_shell_commands: *coverage_validation_post_shell_commands
160167
windows_no_bzlmod:
161168
name: No Bzlmod
@@ -177,12 +184,14 @@ tasks:
177184
platform: ubuntu2204
178185
shell_commands: *split_coverage_postprocessing_shell_commands
179186
coverage_targets: *default_linux_targets
187+
coverage_flags: *coverage_flags
180188
post_shell_commands: *coverage_validation_post_shell_commands
181189
macos_split_coverage_postprocessing:
182190
name: Split Coverage Postprocessing
183191
platform: macos_arm64
184192
shell_commands: *split_coverage_postprocessing_shell_commands
185193
coverage_targets: *default_macos_targets
194+
coverage_flags: *coverage_flags
186195
post_shell_commands: *coverage_validation_post_shell_commands
187196
ubuntu2204_opt:
188197
name: Opt Mode
@@ -218,6 +227,7 @@ tasks:
218227
build_targets: *default_linux_targets
219228
test_targets: *default_linux_targets
220229
coverage_targets: *default_linux_targets
230+
coverage_flags: *coverage_flags
221231
post_shell_commands: *coverage_validation_post_shell_commands
222232
rbe_ubuntu2204_with_aspects:
223233
name: With Aspects
@@ -252,6 +262,7 @@ tasks:
252262
build_targets: *default_macos_targets
253263
test_targets: *default_macos_targets
254264
coverage_targets: *default_macos_targets
265+
coverage_flags: *coverage_flags
255266
post_shell_commands: *coverage_validation_post_shell_commands
256267
macos_rolling_with_aspects:
257268
name: "Macos Rolling Bazel Version With Aspects"
@@ -260,6 +271,7 @@ tasks:
260271
build_targets: *default_macos_targets
261272
test_targets: *default_macos_targets
262273
coverage_targets: *default_macos_targets
274+
coverage_flags: *coverage_flags
263275
post_shell_commands: *coverage_validation_post_shell_commands
264276
soft_fail: yes
265277
bazel: "rolling"
@@ -356,6 +368,7 @@ tasks:
356368
build_targets: *default_linux_targets
357369
test_targets: *default_linux_targets
358370
coverage_targets: *default_linux_targets
371+
coverage_flags: *coverage_flags
359372
post_shell_commands: *coverage_validation_post_shell_commands
360373
ubuntu1804_with_aspects:
361374
name: "Min Bazel Version With Aspects"
@@ -366,6 +379,7 @@ tasks:
366379
test_targets: *default_linux_targets
367380
build_flags: *aspects_flags
368381
coverage_targets: *default_linux_targets
382+
coverage_flags: *coverage_flags
369383
post_shell_commands: *coverage_validation_post_shell_commands
370384
ubuntu2204_min_rust_version:
371385
name: "Min Rust Version"
@@ -432,6 +446,7 @@ tasks:
432446
build_targets: *default_linux_targets
433447
test_targets: *default_linux_targets
434448
coverage_targets: *default_linux_targets
449+
coverage_flags: *coverage_flags
435450
post_shell_commands: *coverage_validation_post_shell_commands
436451
linux_docs:
437452
name: Docs

.bazelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ coverage --combined_report=lcov
2020
coverage --experimental_fetch_all_coverage_outputs
2121
coverage --experimental_split_coverage_postprocessing
2222

23+
# Instrument all workspace targets for coverage. Without this, the default
24+
# --instrumentation_filter may not match workspace targets, resulting in
25+
# empty coverage reports. Projects should adjust this to exclude vendored
26+
# dependencies, e.g.: coverage --instrumentation_filter=^//,-^//third_party
27+
coverage --instrumentation_filter=^//
28+
2329
# Required for some of the tests
2430
# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library
2531
common --experimental_cc_shared_library

0 commit comments

Comments
 (0)