Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ load(
"SWIFT_FEATURE_CACHEABLE_SWIFTMODULES",
"SWIFT_FEATURE_COMPILE_STATS",
"SWIFT_FEATURE_COVERAGE",
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP",
"SWIFT_FEATURE_DBG",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_EMIT_C_MODULE",
Expand Down Expand Up @@ -293,6 +294,19 @@ def compile_action_configs():
[SWIFT_FEATURE_DEBUG_PREFIX_MAP, SWIFT_FEATURE_FULL_DEBUG_INFO],
],
),

# Make paths written into coverage info workspace-relative.
swift_toolchain_config.action_config(
actions = [swift_action_names.COMPILE],
configurators = [
swift_toolchain_config.add_arg(
"-Xwrapped-swift=-coverage-prefix-pwd-is-dot",
),
],
features = [
[SWIFT_FEATURE_COVERAGE_PREFIX_MAP, SWIFT_FEATURE_COVERAGE],
],
),
]

#### Coverage and sanitizer instrumentation flags
Expand Down
5 changes: 5 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ SWIFT_FEATURE_COMPILE_STATS = "swift.compile_stats"
# builds.
SWIFT_FEATURE_DEBUG_PREFIX_MAP = "swift.debug_prefix_map"

# If enabled, coverage builds will use the `-coverage-prefix-map` feature to
# remap the current working directory to `.`, which increases reproducibility
# of remote builds.
SWIFT_FEATURE_COVERAGE_PREFIX_MAP = "swift.coverage_prefix_map"

# If enabled, C and Objective-C libraries that are direct or transitive
# dependencies of a Swift library will emit explicit precompiled modules that
# are compatible with Swift's ClangImporter and propagate them up the build
Expand Down
3 changes: 3 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":debug_settings_tests.bzl", "debug_settings_test_suite")
load(":coverage_settings_tests.bzl", "coverage_settings_test_suite")
load(":generated_header_tests.bzl", "generated_header_test_suite")
load(":private_deps_tests.bzl", "private_deps_test_suite")
load(":swift_through_non_swift_tests.bzl", "swift_through_non_swift_test_suite")
Expand All @@ -8,6 +9,8 @@ licenses(["notice"])

debug_settings_test_suite()

coverage_settings_test_suite()

generated_header_test_suite()

private_deps_test_suite()
Expand Down
53 changes: 53 additions & 0 deletions test/coverage_settings_tests.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Tests for coverage-related command line flags under various configs."""

load(
"@build_bazel_rules_swift//test/rules:action_command_line_test.bzl",
"make_action_command_line_test_rule",
)

default_coverage_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:collect_code_coverage": "true",
},
)

coverage_prefix_map_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:collect_code_coverage": "true",
"//command_line_option:features": [
"swift.coverage_prefix_map",
],
},
)

def coverage_settings_test_suite(name = "coverage_settings"):
"""Test suite for coverage options.

Args:
name: The name prefix for all the nested tests
"""
default_coverage_test(
name = "{}_default_coverage".format(name),
tags = [name],
expected_argv = [
"-profile-generate",
"-profile-coverage-mapping",
],
not_expected_argv = [
"-Xwrapped-swift=-coverage-prefix-pwd-is-dot",
],
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

coverage_prefix_map_test(
name = "{}_prefix_map".format(name),
tags = [name],
expected_argv = [
"-profile-generate",
"-profile-coverage-mapping",
"-Xwrapped-swift=-coverage-prefix-pwd-is-dot",
],
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)
6 changes: 6 additions & 0 deletions tools/worker/swift_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ bool SwiftRunner::ProcessArgument(
consumer("-debug-prefix-map");
consumer(GetCurrentDirectory() + "=.");
changed = true;
} else if (arg == "-Xwrapped-swift=-coverage-prefix-pwd-is-dot") {
// Get the actual current working directory (the workspace root), which we
// didn't know at analysis time.
consumer("-coverage-prefix-map");
consumer(GetCurrentDirectory() + "=.");
changed = true;
} else if (arg == "-Xwrapped-swift=-ephemeral-module-cache") {
// Create a temporary directory to hold the module cache, which will be
// deleted after compilation is finished.
Expand Down