Skip to content

Commit e7f3381

Browse files
Merge pull request #41388 from adrian-prantl/85224717
Darwin: introduce a global override for debug prefix map entries
2 parents bac3b67 + 5956b6b commit e7f3381

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

include/swift/Driver/ToolChain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ class ToolChain {
235235
/// set to match the behavior of Clang.
236236
virtual bool shouldStoreInvocationInDebugInfo() const { return false; }
237237

238+
/// Specific toolchains should override this to provide additional
239+
/// -debug-prefix-map entries. For example, Darwin has an RC_DEBUG_PREFIX_MAP
240+
/// environment variable that is also understood by Clang.
241+
virtual std::string getGlobalDebugPathRemapping() const { return {}; }
242+
238243
/// Gets the response file path and command line argument for an invocation
239244
/// if the tool supports response files and if the command line length would
240245
/// exceed system limits.

lib/Driver/DarwinToolChains.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,14 @@ bool toolchains::Darwin::shouldStoreInvocationInDebugInfo() const {
859859
return false;
860860
}
861861

862+
std::string toolchains::Darwin::getGlobalDebugPathRemapping() const {
863+
// This matches the behavior in Clang (see
864+
// clang/lib/driver/ToolChains/Darwin.cpp).
865+
if (const char *S = ::getenv("RC_DEBUG_PREFIX_MAP"))
866+
return S;
867+
return {};
868+
}
869+
862870
static void validateLinkObjcRuntimeARCLiteLib(const toolchains::Darwin &TC,
863871
DiagnosticEngine &diags,
864872
const llvm::opt::ArgList &args) {

lib/Driver/ToolChains.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
306306
inputArgs.AddAllArgs(arguments, options::OPT_debug_prefix_map);
307307
inputArgs.AddAllArgs(arguments, options::OPT_coverage_prefix_map);
308308

309+
std::string globalRemapping = getGlobalDebugPathRemapping();
310+
if (!globalRemapping.empty()) {
311+
arguments.push_back("-debug-prefix-map");
312+
arguments.push_back(inputArgs.MakeArgString(globalRemapping));
313+
}
314+
309315
// Pass through the values passed to -Xfrontend.
310316
inputArgs.AddAllArgValues(arguments, options::OPT_Xfrontend);
311317

lib/Driver/ToolChains.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
7373
std::string findProgramRelativeToSwiftImpl(StringRef name) const override;
7474

7575
bool shouldStoreInvocationInDebugInfo() const override;
76-
76+
std::string getGlobalDebugPathRemapping() const override;
77+
7778
/// Retrieve the target SDK version for the given target triple.
7879
Optional<llvm::VersionTuple>
7980
getTargetSDKVersion(const llvm::Triple &triple) const ;

test/Driver/debug-prefix-map.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %target-swiftc_driver -### -debug-prefix-map old=new %s 2>&1 | %FileCheck %s -check-prefix CHECK-SIMPLE
33
// RUN: %target-swiftc_driver -### -debug-prefix-map old=n=ew %s 2>&1 | %FileCheck %s -check-prefix CHECK-COMPLEX
44
// RUN: %target-swiftc_driver -### -debug-prefix-map old= %s 2>&1 | %FileCheck %s -check-prefix CHECK-EMPTY
5+
// RUN: env RC_DEBUG_PREFIX_MAP=old=new %target-swiftc_driver -target arm64-apple-macos12 -### %s 2>&1 | %FileCheck %s -check-prefix CHECK-SIMPLE
56

67
// CHECK-INVALID: error: values for '-debug-prefix-map' must be in the format 'original=remapped', but 'old' was provided
78
// CHECK-SIMPLE: debug-prefix-map old=new

0 commit comments

Comments
 (0)