Skip to content

Commit 36be463

Browse files
committed
[6.2] Ensure the path to Swift Testing's macro plugin is specified correctly when using a non-default Xcode toolchain
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://152088164
1 parent 17b53a4 commit 36be463

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
@@ -4274,17 +4274,20 @@ private class SettingsBuilder {
42744274
}
42754275

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

42814283
enum ToolchainStyle {
4282-
case xcodeDefault
4284+
case xcode(isDefault: Bool)
42834285
case other
42844286

42854287
init(_ toolchain: Toolchain) {
4286-
if toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier {
4287-
self = .xcodeDefault
4288+
if toolchain.identifier.hasPrefix(ToolchainRegistry.appleToolchainIdentifierPrefix) {
4289+
let isDefault = toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier
4290+
self = .xcode(isDefault: isDefault)
42884291
} else {
42894292
self = .other
42904293
}
@@ -4293,11 +4296,12 @@ private class SettingsBuilder {
42934296

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

0 commit comments

Comments
 (0)