Skip to content

Commit 3bc16fa

Browse files
authored
[6.2] Ensure the path to Swift Testing's macro plugin is specified correctly when using a non-default Xcode toolchain (#606)
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 2dda86e commit 3bc16fa

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
@@ -4279,17 +4279,20 @@ private class SettingsBuilder {
42794279
}
42804280

42814281
let toolchainPath = Path(scope.evaluateAsString(BuiltinMacros.TOOLCHAIN_DIR))
4282-
guard let toolchain = core.toolchainRegistry.toolchains.first(where: { $0.path == toolchainPath }) else {
4282+
guard let toolchain = core.toolchainRegistry.toolchains.first(where: { $0.path == toolchainPath }),
4283+
let defaultToolchain = core.toolchainRegistry.defaultToolchain
4284+
else {
42834285
return []
42844286
}
42854287

42864288
enum ToolchainStyle {
4287-
case xcodeDefault
4289+
case xcode(isDefault: Bool)
42884290
case other
42894291

42904292
init(_ toolchain: Toolchain) {
4291-
if toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier {
4292-
self = .xcodeDefault
4293+
if toolchain.identifier.hasPrefix(ToolchainRegistry.appleToolchainIdentifierPrefix) {
4294+
let isDefault = toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier
4295+
self = .xcode(isDefault: isDefault)
42934296
} else {
42944297
self = .other
42954298
}
@@ -4298,11 +4301,12 @@ private class SettingsBuilder {
42984301

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

0 commit comments

Comments
 (0)