Skip to content

Commit e357809

Browse files
authored
Ensure the path to Swift Testing's macro plugin is specified correctly when using a non-default Xcode toolchain (swiftlang#574)
This resolves an issue which can occur when using Xcode 26 Beta with the downloadable Metal toolchain installed, if a target imports Swift Testing. A toolchain override is specified in this scenario, and this causes the existing logic modified by this PR to incorrectly believe it's using a non-Xcode toolchain, which in turn causes the wrong Swift macro plugin flags to be passed, ultimately leading to a failure locating the `TestingMacros` plugin. The fix is to recognize all toolchains which have Xcode's prefix, and ensure the default toolchain prefix is used whenever any Xcode toolchain is in use. Fixes rdar://152440128
1 parent 50e386e commit e357809

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Sources/SWBCore/Settings/Settings.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,17 +4273,20 @@ private class SettingsBuilder {
42734273
}
42744274

42754275
let toolchainPath = Path(scope.evaluateAsString(BuiltinMacros.TOOLCHAIN_DIR))
4276-
guard let toolchain = core.toolchainRegistry.toolchains.first(where: { $0.path == toolchainPath }) else {
4276+
guard let toolchain = core.toolchainRegistry.toolchains.first(where: { $0.path == toolchainPath }),
4277+
let defaultToolchain = core.toolchainRegistry.defaultToolchain
4278+
else {
42774279
return []
42784280
}
42794281

42804282
enum ToolchainStyle {
4281-
case xcodeDefault
4283+
case xcode(isDefault: Bool)
42824284
case other
42834285

42844286
init(_ toolchain: Toolchain) {
4285-
if toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier {
4286-
self = .xcodeDefault
4287+
if toolchain.identifier.hasPrefix(ToolchainRegistry.appleToolchainIdentifierPrefix) {
4288+
let isDefault = toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier
4289+
self = .xcode(isDefault: isDefault)
42874290
} else {
42884291
self = .other
42894292
}
@@ -4292,11 +4295,12 @@ private class SettingsBuilder {
42924295

42934296
let testingPluginsPath = "/usr/lib/swift/host/plugins/testing"
42944297
switch (ToolchainStyle(toolchain)) {
4295-
case .xcodeDefault:
4296-
// This target is building using the same toolchain as the one used
4297-
// to build the testing libraries which it is using, so it can use
4298-
// non-external plugin flags.
4299-
return ["-plugin-path", "$(TOOLCHAIN_DIR)\(testingPluginsPath)"]
4298+
case let .xcode(isDefault):
4299+
// This target is using a built-in Xcode toolchain, and that should
4300+
// match the toolchain which was used to build the testing libraries
4301+
// this target is using, so it can use non-external plugin flags.
4302+
let toolchainPathPrefix = isDefault ? "$(TOOLCHAIN_DIR)" : defaultToolchain.path.str
4303+
return ["-plugin-path", "\(toolchainPathPrefix)\(testingPluginsPath)"]
43004304
case .other:
43014305
// This target is using the testing libraries from Xcode,
43024306
// which were built using the XcodeDefault toolchain, but it's using

0 commit comments

Comments
 (0)