Skip to content

Commit f174ab8

Browse files
authored
Enable swift.file_prefix_map by default if supported (#1014)
We already enable debug and coverage prefix maps, this one supersedes those and potentially handles more cases in the future.
1 parent 1bc3e29 commit f174ab8

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

swift/internal/swift_autoconfiguration.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ load(
3030
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
3131
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
3232
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
33+
"SWIFT_FEATURE_FILE_PREFIX_MAP",
3334
"SWIFT_FEATURE_LLD_GC_WORKAROUND",
3435
"SWIFT_FEATURE_MODULE_MAP_NO_PRIVATE_HEADERS",
3536
"SWIFT_FEATURE_NO_EMBED_DEBUG_MODULE",
@@ -91,6 +92,16 @@ def _check_skip_function_bodies(repository_ctx, swiftc_path, _temp_dir):
9192
"-experimental-skip-non-inlinable-function-bodies",
9293
)
9394

95+
def _check_file_prefix_map(repository_ctx, swiftc_path, _temp_dir):
96+
"""Returns True if `swiftc` supports -file-prefix-map."""
97+
return _swift_succeeds(
98+
repository_ctx,
99+
swiftc_path,
100+
"-version",
101+
"-file-prefix-map",
102+
"foo=bar",
103+
)
104+
94105
def _check_enable_bare_slash_regex(repository_ctx, swiftc_path, _temp_dir):
95106
"""Returns True if `swiftc` supports debug prefix mapping."""
96107
return _swift_succeeds(
@@ -209,6 +220,7 @@ def _compute_feature_values(repository_ctx, swiftc_path):
209220
_FEATURE_CHECKS = {
210221
SWIFT_FEATURE_ENABLE_BATCH_MODE: _check_enable_batch_mode,
211222
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES: _check_skip_function_bodies,
223+
SWIFT_FEATURE_FILE_PREFIX_MAP: _check_file_prefix_map,
212224
SWIFT_FEATURE_LLD_GC_WORKAROUND: _check_supports_lld_gc_workaround,
213225
SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX: _check_enable_bare_slash_regex,
214226
SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS: _check_supports_private_deps,

swift/internal/xcode_swift_toolchain.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ def _xcode_swift_toolchain_impl(ctx):
635635

636636
# Xcode 14 implies Swift 5.7.
637637
if _is_xcode_at_least_version(xcode_config, "14.0"):
638+
requested_features.append(SWIFT_FEATURE_FILE_PREFIX_MAP)
638639
requested_features.append(SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX)
639640

640641
env = _xcode_env(target_triple = target_triple, xcode_config = xcode_config)

test/features_tests.bzl

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,10 @@ opt_no_wmo_test = make_action_command_line_test_rule(
2121
},
2222
)
2323

24-
file_prefix_map_test = make_action_command_line_test_rule(
24+
disabled_file_prefix_map_test = make_action_command_line_test_rule(
2525
config_settings = {
2626
"//command_line_option:features": [
27-
"swift.file_prefix_map",
28-
],
29-
},
30-
)
31-
32-
file_prefix_xcode_remap_test = make_action_command_line_test_rule(
33-
config_settings = {
34-
"//command_line_option:features": [
35-
"swift.file_prefix_map",
36-
"swift.remap_xcode_path",
27+
"-swift.file_prefix_map",
3728
],
3829
},
3930
)
@@ -83,26 +74,23 @@ def features_test_suite(name):
8374
expected_argv = [
8475
"-emit-object",
8576
"-I$(BIN_DIR)/test/fixtures/basic",
86-
],
87-
not_expected_argv = [
88-
"-file-prefix-map",
8977
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
9078
],
9179
mnemonic = "SwiftCompile",
9280
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:second",
9381
)
9482

95-
file_prefix_map_test(
83+
disabled_file_prefix_map_test(
9684
name = "{}_file_prefix_map_test".format(name),
9785
tags = [name],
98-
expected_argv = [
86+
not_expected_argv = [
9987
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
10088
],
10189
mnemonic = "SwiftCompile",
10290
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
10391
)
10492

105-
file_prefix_xcode_remap_test(
93+
default_test(
10694
name = "{}_file_prefix_xcode_remap_test".format(name),
10795
tags = [name],
10896
expected_argv = [

0 commit comments

Comments
 (0)