From 648d7cd0ddca1d1806ccd2dc7e2ab1c9d629f22e Mon Sep 17 00:00:00 2001 From: Steve McClure Date: Fri, 27 Mar 2026 12:39:44 -0400 Subject: [PATCH] SERVER-122861: Support `bazel coverage` to run on implicit debug targets (#50621) GitOrigin-RevId: 5b0d8fcbbf68b706678956b32684aae851b1e0e0 --- bazel/separate_debug.bzl | 25 ++++++++++++++++++- .../tasks/misc_tasks.yml | 8 +----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/bazel/separate_debug.bzl b/bazel/separate_debug.bzl index 1fa0eebd0ba..09c35b24f34 100644 --- a/bazel/separate_debug.bzl +++ b/bazel/separate_debug.bzl @@ -649,6 +649,16 @@ def extract_debuginfo_impl(ctx): elif ctx.target_platform_has_constraint(wasi_constraint): return_info = wasi_extraction(ctx, cc_toolchain, inputs) + # Forward InstrumentedFilesInfo so that `bazel coverage` can collect coverage + # data from binaries produced by this rule. This is equivalent to running against + # targets with the _with_debug suffix directly, but more natural for users. + return_info.append( + coverage_common.instrumented_files_info( + ctx, + dependency_attributes = ["binary_with_debug"], + ), + ) + tag_provider = TagInfo(tags = ctx.attr.tags) return_info.append(tag_provider) return return_info @@ -749,10 +759,23 @@ extract_debuginfo_test = rule( "_macos_constraint": attr.label(default = "@platforms//os:macos"), "_windows_constraint": attr.label(default = "@platforms//os:windows"), "_wasi_constraint": attr.label(default = "@platforms//cpu:wasm32"), + # Required for `bazel coverage` to invoke the C++ coverage collection + # script (collect_cc_coverage.sh) and merge profraw -> _cc_coverage.dat, + # matching the behavior of native cc_test. + "_lcov_merger": attr.label( + default = configuration_field(fragment = "coverage", name = "output_generator"), + executable = True, + cfg = config.exec(exec_group = "test"), + ), + "_collect_cc_coverage": attr.label( + default = "@bazel_tools//tools/test:collect_cc_coverage", + executable = True, + cfg = config.exec(exec_group = "test"), + ), }, doc = "Extract debuginfo into a separate file", toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], - fragments = ["cpp"], + fragments = ["cpp", "coverage"], executable = True, test = True, ) diff --git a/etc/evergreen_yml_components/tasks/misc_tasks.yml b/etc/evergreen_yml_components/tasks/misc_tasks.yml index 617b98a303b..afb2180e10d 100644 --- a/etc/evergreen_yml_components/tasks/misc_tasks.yml +++ b/etc/evergreen_yml_components/tasks/misc_tasks.yml @@ -928,16 +928,10 @@ tasks: - func: "get engflow creds" - func: "bazel coverage" vars: - # Running something like "bazel test //src/..." has to do a lot of preprocessing on *all* - # targets before it actually runs the much smaller fraction of test targets, unless we're - # certain that a full build has already been cached. - # It might be optimized by doing a query upfront, which uses minimal analysis: - # targets=$(bazel query 'kind(".*_test", //src/...)') - # bazel test $targets target: >- //src/mongo/... args: >- - --test_tag_filters=mongo_unittest_debug,-code_coverage_quarantine_debug + --test_tag_filters=mongo_unittest,-intermediate_debug,-code_coverage_quarantine --test_timeout=1800 --verbose_failures --instrumentation_filter=^//src/mongo[/:],-^//src/mongo/util:boost_assert_shim,-^//src/mongo/util:icu,-^//src/mongo/db/modules/enterprise/src/streams/third_party[/:]