Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swift.remap_xcode_path feature #511

Merged
merged 3 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,7 @@ SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION = "swift.split_derived_files_genera
# If enabled the skip function bodies frontend flag is passed when using derived
# files generation. This requires Swift 5.2
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES = "swift.skip_function_bodies_for_derived_files"

# If enabled remap the absolute path to Xcode in debug info. When used with
# swift.coverage_prefix_map also remap the path in coverage data.
SWIFT_REMAP_XCODE_PATH = "swift.remap_xcode_path"
keith marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ load(
"SWIFT_FEATURE_BITCODE_EMBEDDED",
"SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS",
"SWIFT_FEATURE_BUNDLED_XCTESTS",
"SWIFT_FEATURE_COVERAGE",
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
Expand All @@ -40,6 +42,7 @@ load(
"SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION",
"SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS",
"SWIFT_FEATURE_USE_RESPONSE_FILES",
"SWIFT_REMAP_XCODE_PATH",
)
load(":features.bzl", "features_for_build_modes")
load(":toolchain_config.bzl", "swift_toolchain_config")
Expand Down Expand Up @@ -334,6 +337,42 @@ def _all_action_configs(
],
features = [SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS],
),

# Xcode path remapping
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
],
configurators = [
swift_toolchain_config.add_arg(
"-debug-prefix-map",
"__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR",
),
],
features = [
[SWIFT_REMAP_XCODE_PATH, SWIFT_FEATURE_DEBUG_PREFIX_MAP],
],
),
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
],
configurators = [
swift_toolchain_config.add_arg(
"-coverage-prefix-map",
"__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR",
),
],
features = [
[
SWIFT_REMAP_XCODE_PATH,
SWIFT_FEATURE_COVERAGE_PREFIX_MAP,
SWIFT_FEATURE_COVERAGE,
],
],
),
]

if needs_resource_directory:
Expand Down
24 changes: 24 additions & 0 deletions test/coverage_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ coverage_prefix_map_test = make_action_command_line_test_rule(
},
)

coverage_xcode_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",
"swift.remap_xcode_path",
],
},
)

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

Expand Down Expand Up @@ -51,3 +61,17 @@ def coverage_settings_test_suite(name = "coverage_settings"):
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

coverage_xcode_prefix_map_test(
name = "{}_xcode_prefix_map".format(name),
tags = [name],
expected_argv = select({
"//test:linux": [],
"//conditions:default": [
"-coverage-prefix-map",
"__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR",
],
}),
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)
24 changes: 24 additions & 0 deletions test/debug_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ cacheable_opt_action_command_line_test = make_action_command_line_test_rule(
config_settings = CACHEABLE_OPT_CONFIG_SETTINGS,
)

xcode_remap_command_line_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:compilation_mode": "dbg",
"//command_line_option:features": [
"swift.debug_prefix_map",
"swift.remap_xcode_path",
],
},
)

def debug_settings_test_suite(name = "debug_settings"):
"""Test suite for serializing debugging options.

Expand Down Expand Up @@ -213,6 +223,20 @@ def debug_settings_test_suite(name = "debug_settings"):
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

xcode_remap_command_line_test(
name = "{}_remap_xcode_path".format(name),
expected_argv = select({
"//test:linux": [],
"//conditions:default": [
"-debug-prefix-map",
"__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR",
],
}),
mnemonic = "SwiftCompile",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

native.test_suite(
name = name,
tags = [name],
Expand Down