Skip to content

Commit 03e7bed

Browse files
committed
Add support for LLVM coverage collection to swift_test.
Bazel's coverage collection script will be augmented to honor the `TEST_BINARIES_FOR_LLVM_COV` environment variable, which is a semicolon-delimited list of binary paths (runfiles-relative) that must be passed to `llvm-cov` so that coverage data can be mapped back to the binaries. RELNOTES: None. PiperOrigin-RevId: 222090124
1 parent 3e3a270 commit 03e7bed

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

swift/internal/swift_binary_test.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ def _swift_test_impl(ctx):
262262
additional_test_outputs = []
263263
executable = binary
264264

265+
test_environment = dicts.add(
266+
toolchain.action_environment,
267+
{"TEST_BINARIES_FOR_LLVM_COV": binary.short_path},
268+
)
269+
265270
# TODO(b/79527231): Replace `instrumented_files` with a declared provider when it is available.
266271
return struct(
267272
instrumented_files = struct(
@@ -277,9 +282,13 @@ def _swift_test_impl(ctx):
277282
collect_data = True,
278283
collect_default = True,
279284
files = ctx.files.data + additional_test_outputs,
285+
# _coverage_support is a private attribute added by Bazel to all test targets
286+
# (see https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java).
287+
transitive_files = ctx.attr._coverage_support.files,
280288
),
281289
),
282290
testing.ExecutionInfo(toolchain.execution_requirements),
291+
testing.TestEnvironment(test_environment),
283292
],
284293
)
285294

0 commit comments

Comments
 (0)