Skip to content

Commit 04904e2

Browse files
committed
[SwiftSDK] Prepend custom toolchain into root paths to give it priority
1 parent d7f50e0 commit 04904e2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ public struct SwiftSDK: Equatable {
698698
)
699699
}
700700

701-
swiftSDK.append(toolsetRootPath: binDir.appending(components: "usr", "bin"))
701+
// `--tooolchain` should override existing anything in the SDK and search paths.
702+
swiftSDK.prepend(toolsetRootPath: binDir.appending(components: "usr", "bin"))
702703
}
703704
if let sdk = customCompileSDK {
704705
swiftSDK.pathsConfiguration.sdkRootPath = sdk
@@ -727,7 +728,20 @@ public struct SwiftSDK: Equatable {
727728
self.toolset.knownTools[.swiftCompiler] = properties
728729
}
729730

731+
/// Prepends a path to the array of toolset root paths.
732+
///
733+
/// Note: Use this operation if you want new root path to take priority over existing paths.
734+
///
735+
/// - Parameter toolsetRootPath: new path to add to Swift SDK's toolset.
736+
public mutating func prepend(toolsetRootPath path: AbsolutePath) {
737+
self.toolset.rootPaths.insert(path, at: 0)
738+
}
739+
730740
/// Appends a path to the array of toolset root paths.
741+
///
742+
/// Note: The paths are evaluated in insertion order which means that newly added path would
743+
/// have a lower priority vs. existing paths.
744+
///
731745
/// - Parameter toolsetRootPath: new path to add to Swift SDK's toolset.
732746
public mutating func append(toolsetRootPath: AbsolutePath) {
733747
self.toolset.rootPaths.append(toolsetRootPath)

Tests/PackageModelTests/SwiftSDKBundleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ final class SwiftSDKBundleTests: XCTestCase {
424424
fileSystem: fileSystem
425425
)
426426
// With toolset in the target SDK, it should contain the host toolset roots at the end.
427-
XCTAssertEqual(targetSwiftSDK.toolset.rootPaths, hostSwiftSDK.toolset.rootPaths + [toolsetRootPath])
427+
XCTAssertEqual(targetSwiftSDK.toolset.rootPaths, [toolsetRootPath] + hostSwiftSDK.toolset.rootPaths)
428428
}
429429

430430
do {

0 commit comments

Comments
 (0)