Skip to content

Commit 4390010

Browse files
allevatoswiple-rules-gardener
authored andcommitted
Support -debug-prefix-map for Xcode 10.2 (Swift 5.0) and higher.
RELNOTES: When building with Xcode 10.2 (Swift 5.0) or higher, the compiler now passes `-debug-prefix-map` to the compiler to remap the working directory to `"."`, removing absolute source paths from the generated debug info. PiperOrigin-RevId: 244941132
1 parent c420d7d commit 4390010

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

swift/internal/api.bzl

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ load(
5555
"SWIFT_FEATURE_AUTOLINK_EXTRACT",
5656
"SWIFT_FEATURE_COVERAGE",
5757
"SWIFT_FEATURE_DBG",
58+
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
5859
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
5960
"SWIFT_FEATURE_ENABLE_TESTING",
6061
"SWIFT_FEATURE_FASTBUILD",
@@ -520,6 +521,12 @@ def _compile_as_objects(
520521
else:
521522
wrapper_args.add("-Xwrapped-swift=-ephemeral-module-cache")
522523

524+
if swift_common.is_enabled(
525+
feature_configuration = feature_configuration,
526+
feature_name = SWIFT_FEATURE_DEBUG_PREFIX_MAP,
527+
):
528+
wrapper_args.add("-Xwrapped-swift=-debug-prefix-pwd-is-dot")
529+
523530
compile_args = actions.args()
524531
if swift_common.is_enabled(
525532
feature_configuration = feature_configuration,

swift/internal/xcode_swift_toolchain.bzl

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ load(
2828
":features.bzl",
2929
"SWIFT_FEATURE_AUTOLINK_EXTRACT",
3030
"SWIFT_FEATURE_BUNDLED_XCTESTS",
31+
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
3132
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
3233
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
3334
"SWIFT_FEATURE_USE_RESPONSE_FILES",
@@ -496,7 +497,9 @@ def _xcode_swift_toolchain_impl(ctx):
496497
requested_features.append(SWIFT_FEATURE_ENABLE_BATCH_MODE)
497498
requested_features.append(SWIFT_FEATURE_USE_RESPONSE_FILES)
498499

499-
# TODO(#35): Add SWIFT_FEATURE_DEBUG_PREFIX_MAP based on Xcode version.
500+
# Xcode 10.2 implies Swift 5.0.
501+
if _is_xcode_at_least_version(xcode_config, "10.2"):
502+
requested_features.append(SWIFT_FEATURE_DEBUG_PREFIX_MAP)
500503

501504
command_line_copts = _command_line_objc_copts(ctx.fragments.objc) + ctx.fragments.swift.copts()
502505

tools/wrappers/swift_wrapper.sh

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ for ARG in "$@" ; do
7070
--persistent_worker)
7171
USE_WORKER=1
7272
;;
73+
-Xwrapped-swift=-debug-prefix-pwd-is-dot)
74+
ARGS+=(-debug-prefix-map "$PWD=.")
75+
;;
7376
-Xwrapped-swift=-ephemeral-module-cache)
7477
MODULE_CACHE_DIR="$(mktemp -d "${TMPDIR%/}/wrapped_swift_module_cache.XXXXXXXXXX")"
7578
ARGS+=(-module-cache-path "$MODULE_CACHE_DIR")

0 commit comments

Comments
 (0)