Skip to content

Commit

Permalink
Enable swift.file_prefix_map by default if supported (#1014)
Browse files Browse the repository at this point in the history
We already enable debug and coverage prefix maps, this one supersedes
those and potentially handles more cases in the future.
  • Loading branch information
keith authored Feb 17, 2023
1 parent 1bc3e29 commit f174ab8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
12 changes: 12 additions & 0 deletions swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ load(
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
"SWIFT_FEATURE_FILE_PREFIX_MAP",
"SWIFT_FEATURE_LLD_GC_WORKAROUND",
"SWIFT_FEATURE_MODULE_MAP_NO_PRIVATE_HEADERS",
"SWIFT_FEATURE_NO_EMBED_DEBUG_MODULE",
Expand Down Expand Up @@ -91,6 +92,16 @@ def _check_skip_function_bodies(repository_ctx, swiftc_path, _temp_dir):
"-experimental-skip-non-inlinable-function-bodies",
)

def _check_file_prefix_map(repository_ctx, swiftc_path, _temp_dir):
"""Returns True if `swiftc` supports -file-prefix-map."""
return _swift_succeeds(
repository_ctx,
swiftc_path,
"-version",
"-file-prefix-map",
"foo=bar",
)

def _check_enable_bare_slash_regex(repository_ctx, swiftc_path, _temp_dir):
"""Returns True if `swiftc` supports debug prefix mapping."""
return _swift_succeeds(
Expand Down Expand Up @@ -209,6 +220,7 @@ def _compute_feature_values(repository_ctx, swiftc_path):
_FEATURE_CHECKS = {
SWIFT_FEATURE_ENABLE_BATCH_MODE: _check_enable_batch_mode,
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES: _check_skip_function_bodies,
SWIFT_FEATURE_FILE_PREFIX_MAP: _check_file_prefix_map,
SWIFT_FEATURE_LLD_GC_WORKAROUND: _check_supports_lld_gc_workaround,
SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX: _check_enable_bare_slash_regex,
SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS: _check_supports_private_deps,
Expand Down
1 change: 1 addition & 0 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ def _xcode_swift_toolchain_impl(ctx):

# Xcode 14 implies Swift 5.7.
if _is_xcode_at_least_version(xcode_config, "14.0"):
requested_features.append(SWIFT_FEATURE_FILE_PREFIX_MAP)
requested_features.append(SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX)

env = _xcode_env(target_triple = target_triple, xcode_config = xcode_config)
Expand Down
22 changes: 5 additions & 17 deletions test/features_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,10 @@ opt_no_wmo_test = make_action_command_line_test_rule(
},
)

file_prefix_map_test = make_action_command_line_test_rule(
disabled_file_prefix_map_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.file_prefix_map",
],
},
)

file_prefix_xcode_remap_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.file_prefix_map",
"swift.remap_xcode_path",
"-swift.file_prefix_map",
],
},
)
Expand Down Expand Up @@ -83,26 +74,23 @@ def features_test_suite(name):
expected_argv = [
"-emit-object",
"-I$(BIN_DIR)/test/fixtures/basic",
],
not_expected_argv = [
"-file-prefix-map",
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
],
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:second",
)

file_prefix_map_test(
disabled_file_prefix_map_test(
name = "{}_file_prefix_map_test".format(name),
tags = [name],
expected_argv = [
not_expected_argv = [
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
],
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

file_prefix_xcode_remap_test(
default_test(
name = "{}_file_prefix_xcode_remap_test".format(name),
tags = [name],
expected_argv = [
Expand Down

0 comments on commit f174ab8

Please sign in to comment.