Skip to content

Commit 1b2f2a6

Browse files
committed
fix wd_test
1 parent 8d45d41 commit 1b2f2a6

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

.bazelrc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,18 @@ build:coverage --test_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1
421421
# GCOV is used by rules_cc to merge raw profile data (.profraw) into indexed profile data (.profdata)
422422
build:coverage --action_env=GCOV=llvm-profdata
423423
build:coverage --test_env=GCOV=llvm-profdata
424-
# COVERAGE_GCOV_PATH is passed through from the environment. Users must set this to the absolute path
425-
# of llvm-profdata (used by collect_cc_coverage.sh for merging .profraw files).
426-
# Example: export COVERAGE_GCOV_PATH=$(which llvm-profdata)
427-
build:coverage --action_env=COVERAGE_GCOV_PATH
428-
build:coverage --test_env=COVERAGE_GCOV_PATH
424+
# COVERAGE_GCOV_PATH is used by collect_cc_coverage.sh for merging .profraw files.
425+
# Set to absolute path of llvm-profdata (resolving symlinks for sandbox compatibility).
426+
build:coverage --action_env=COVERAGE_GCOV_PATH=/usr/lib/llvm-20/bin/llvm-profdata
427+
build:coverage --test_env=COVERAGE_GCOV_PATH=/usr/lib/llvm-20/bin/llvm-profdata
429428
# BAZEL_LLVM_COV is used by rules_cc to generate coverage reports from profile data
430429
build:coverage --action_env=BAZEL_LLVM_COV=llvm-cov
431430
build:coverage --test_env=BAZEL_LLVM_COV=llvm-cov
432431
# LLVM_COV is used by collect_cc_coverage.sh for generating LCOV output
433432
build:coverage --test_env=LLVM_COV=llvm-cov
433+
# GENERATE_LLVM_LCOV=1 tells collect_cc_coverage.sh to use llvm-cov export to generate LCOV format
434+
# instead of just outputting raw profdata. LLVM_COV specifies the llvm-cov binary to use.
435+
build:coverage --test_env=GENERATE_LLVM_LCOV=1
434436
build:coverage --experimental_use_llvm_covmap
435437
build:coverage --experimental_generate_llvm_lcov
436438
# Ensure that we fetch coverage data from remote cache

build/wd_test.bzl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,28 @@ def _wd_test_impl(ctx):
234234
if default_runfiles:
235235
runfiles = runfiles.merge(default_runfiles)
236236

237+
# Create runtime_objects_list.txt for LLVM coverage.
238+
# This file tells collect_cc_coverage.sh where to find the instrumented binary
239+
# so llvm-cov can export coverage data in LCOV format.
240+
runtime_objects_list = ctx.actions.declare_file(ctx.label.name + "runtime_objects_list.txt")
241+
workerd_file = ctx.file.workerd
242+
ctx.actions.write(
243+
output = runtime_objects_list,
244+
content = workerd_file.path + "\n",
245+
is_executable = False,
246+
)
247+
237248
# IMPORTANT: The workerd binary must be listed in dependency_attributes
238249
# to ensure its transitive dependencies (all the C++ source files) are
239250
# included in the coverage instrumentation. Without this, coverage data
240251
# won't be collected for the actual workerd implementation code.
252+
# The runtime_objects_list.txt and workerd binary are included in metadata_files
253+
# so that collect_cc_coverage.sh can find them for LLVM LCOV generation.
241254
instrumented_files_info = coverage_common.instrumented_files_info(
242255
ctx,
243256
source_attributes = ["src", "data"],
244257
dependency_attributes = ["workerd", "sidecar", "sidecar_supervisor"],
245-
# Include all file types that might contain testable code
246-
extensions = ["cc", "c++", "cpp", "cxx", "c", "h", "hh", "hpp", "hxx", "inc", "js", "ts", "mjs", "wd-test", "capnp"],
258+
metadata_files = [runtime_objects_list, workerd_file],
247259
)
248260
environment = dict(ctx.attr.env)
249261
if ctx.attr.python_snapshot_test:
@@ -282,11 +294,14 @@ _wd_test = rule(
282294
),
283295
# Source file
284296
"src": attr.label(allow_single_file = True),
285-
# The workerd executable is used to run all tests
297+
# The workerd executable is used to run all tests.
298+
# Using cfg = "target" instead of "exec" ensures workerd is built with coverage
299+
# instrumentation when running `bazel coverage`. With cfg = "exec", the binary
300+
# would be built in exec configuration which doesn't include coverage flags.
286301
"workerd": attr.label(
287302
allow_single_file = True,
288303
executable = True,
289-
cfg = "exec",
304+
cfg = "target",
290305
default = "//src/workerd/server:workerd_cross",
291306
),
292307
# A list of files that this test requires to be present in order to run.

0 commit comments

Comments
 (0)