Skip to content

Commit bead123

Browse files
DavidGoldmanswiple-rules-gardener
authored andcommitted
Add -file-prefix-map support
We can use -file-prefix-map instead of -debug-prefix-map starting in Xcode 14. This has the main benefit of remapping debugging, indexing, and coverage paths, all with a single flag. Keeping this opt-in for now, we'll test this out locally before a further rollout. PiperOrigin-RevId: 477010867
1 parent 5a6aedb commit bead123

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

swift/internal/feature_names.bzl

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS = "swift.bitcode_embedded_markers"
4444
# the note above about not depending on the C++ features.)
4545
SWIFT_FEATURE_COVERAGE = "swift.coverage"
4646

47+
# If enabled, builds will use the `-file-prefix-map` feature to remap the
48+
# current working directory to `.`, which permits debugging remote or sandboxed
49+
# builds as well as hermetic index and coverage information. This requires
50+
# Xcode 14 or newer.
51+
SWIFT_FEATURE_FILE_PREFIX_MAP = "swift.file_prefix_map"
52+
4753
# If enabled, debug builds will use the `-debug-prefix-map` feature to remap the
4854
# current working directory to `.`, which permits debugging remote or sandboxed
4955
# builds.

swift/toolchains/config/compile_config.bzl

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ load(
3434
"SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION",
3535
"SWIFT_FEATURE_ENABLE_TESTING",
3636
"SWIFT_FEATURE_FASTBUILD",
37+
"SWIFT_FEATURE_FILE_PREFIX_MAP",
3738
"SWIFT_FEATURE_FULL_DEBUG_INFO",
3839
"SWIFT_FEATURE_INDEX_SYSTEM_MODULES",
3940
"SWIFT_FEATURE_INDEX_WHILE_BUILDING",
@@ -340,6 +341,17 @@ def compile_action_configs(
340341
[SWIFT_FEATURE_DEBUG_PREFIX_MAP, SWIFT_FEATURE_FASTBUILD],
341342
[SWIFT_FEATURE_DEBUG_PREFIX_MAP, SWIFT_FEATURE_FULL_DEBUG_INFO],
342343
],
344+
not_features = [SWIFT_FEATURE_FILE_PREFIX_MAP],
345+
),
346+
ActionConfigInfo(
347+
actions = [
348+
SWIFT_ACTION_COMPILE,
349+
SWIFT_ACTION_PRECOMPILE_C_MODULE,
350+
],
351+
configurators = [
352+
add_arg("-Xwrapped-swift=-file-prefix-pwd-is-dot"),
353+
],
354+
features = [SWIFT_FEATURE_FILE_PREFIX_MAP],
343355
),
344356
]
345357

test/debug_settings_tests.bzl

+26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ DBG_CONFIG_SETTINGS = {
2626
],
2727
}
2828

29+
FILE_PREFIX_MAP_CONFIG_SETTINGS = {
30+
"//command_line_option:compilation_mode": "dbg",
31+
"//command_line_option:features": [
32+
"swift.debug_prefix_map",
33+
"swift.file_prefix_map",
34+
],
35+
}
36+
2937
CACHEABLE_DBG_CONFIG_SETTINGS = {
3038
"//command_line_option:compilation_mode": "dbg",
3139
"//command_line_option:features": [
@@ -62,6 +70,10 @@ dbg_action_command_line_test = make_action_command_line_test_rule(
6270
config_settings = DBG_CONFIG_SETTINGS,
6371
)
6472

73+
file_prefix_map_command_line_test = make_action_command_line_test_rule(
74+
config_settings = FILE_PREFIX_MAP_CONFIG_SETTINGS,
75+
)
76+
6577
cacheable_dbg_action_command_line_test = make_action_command_line_test_rule(
6678
config_settings = CACHEABLE_DBG_CONFIG_SETTINGS,
6779
)
@@ -107,6 +119,20 @@ def debug_settings_test_suite(name, tags = []):
107119
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
108120
)
109121

122+
# Verify that the build is remapping paths with a file prefix map.
123+
file_prefix_map_command_line_test(
124+
name = "{}_file_prefix_map_build".format(name),
125+
expected_argv = [
126+
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
127+
],
128+
not_expected_argv = [
129+
"-Xwrapped-swift=-debug-prefix-pwd-is-dot",
130+
],
131+
mnemonic = "SwiftCompile",
132+
tags = all_tags,
133+
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
134+
)
135+
110136
# Verify that `-c dbg` builds with `swift.cacheable_modules` do NOT
111137
# serialize debugging options, but are otherwise the same as regular `dbg`
112138
# builds.

tools/worker/swift_runner.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,21 @@ bool SwiftRunner::ProcessArgument(
235235
absl::string_view trimmed_arg = arg;
236236
if (absl::ConsumePrefix(&trimmed_arg, "-Xwrapped-swift=")) {
237237
if (trimmed_arg == "-debug-prefix-pwd-is-dot") {
238-
// Get the actual current working directory (the workspace root), which
238+
// Get the actual current working directory (the execution root), which
239239
// we didn't know at analysis time.
240240
consumer("-debug-prefix-map");
241241
consumer(GetCurrentDirectory() + "=.");
242242
return true;
243243
}
244244

245+
if (trimmed_arg == "-file-prefix-pwd-is-dot") {
246+
// Get the actual current working directory (the execution root), which
247+
// we didn't know at analysis time.
248+
consumer("-file-prefix-map");
249+
consumer(GetCurrentDirectory() + "=.");
250+
return true;
251+
}
252+
245253
if (trimmed_arg == "-ephemeral-module-cache") {
246254
// Create a temporary directory to hold the module cache, which will be
247255
// deleted after compilation is finished.

tools/worker/swift_runner.h

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ namespace bazel_rules_swift {
4545
// applied here because we do not know the current working directory at
4646
// analysis time when the argument list is constructed.
4747
//
48+
// -Xwrapped-swift=-file-prefix-pwd-is-dot
49+
// When specified, the Swift compiler will be directed to remap the current
50+
// directory's path to the string "." in debug, coverage, and index info.
51+
// This remapping must be applied here because we do not know the current
52+
// working directory at analysis time when the argument list is constructed.
53+
//
4854
// -Xwrapped-swift=-ephemeral-module-cache
4955
// When specified, the spawner will create a new temporary directory, pass
5056
// that to the Swift compiler using `-module-cache-path`, and then delete

0 commit comments

Comments
 (0)