Skip to content

[6.2] Ensure the path to Swift Testing's macro plugin is specified correctly when using a non-default Xcode toolchain #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Sources/SWBCore/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4274,17 +4274,20 @@ private class SettingsBuilder {
}

let toolchainPath = Path(scope.evaluateAsString(BuiltinMacros.TOOLCHAIN_DIR))
guard let toolchain = core.toolchainRegistry.toolchains.first(where: { $0.path == toolchainPath }) else {
guard let toolchain = core.toolchainRegistry.toolchains.first(where: { $0.path == toolchainPath }),
let defaultToolchain = core.toolchainRegistry.defaultToolchain
else {
return []
}

enum ToolchainStyle {
case xcodeDefault
case xcode(isDefault: Bool)
case other

init(_ toolchain: Toolchain) {
if toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier {
self = .xcodeDefault
if toolchain.identifier.hasPrefix(ToolchainRegistry.appleToolchainIdentifierPrefix) {
let isDefault = toolchain.identifier == ToolchainRegistry.defaultToolchainIdentifier
self = .xcode(isDefault: isDefault)
} else {
self = .other
}
Expand All @@ -4293,11 +4296,12 @@ private class SettingsBuilder {

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