Skip to content

Commit ac0ac36

Browse files
committed
Use renamed async versions of the new methods
1 parent 8bac989 commit ac0ac36

File tree

17 files changed

+251
-81
lines changed

17 files changed

+251
-81
lines changed

Sources/CoreCommands/SwiftCommandState.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,17 +851,17 @@ public final class SwiftCommandState {
851851
return hostToolchain
852852
}
853853

854-
return try await UserToolchain(swiftSDK: swiftSDK, environment: self.environment, fileSystem: self.fileSystem)
854+
return try await UserToolchain.create(swiftSDK: swiftSDK, environment: self.environment, fileSystem: self.fileSystem)
855855
}
856856

857857
public func getHostToolchain() async throws -> UserToolchain {
858-
var hostSwiftSDK = try await SwiftSDK.hostSwiftSDK(
858+
var hostSwiftSDK = try await SwiftSDK.hostSwiftSDKAsync(
859859
environment: self.environment,
860860
observabilityScope: self.observabilityScope
861861
)
862862
hostSwiftSDK.targetTriple = self.hostTriple
863863

864-
return try await UserToolchain(
864+
return try await UserToolchain.create(
865865
swiftSDK: hostSwiftSDK,
866866
environment: self.environment,
867867
customTargetInfo: targetInfo,

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import TSCBasic
1616

1717
import class Basics.AsyncProcess
1818

19+
1920
import struct TSCUtility.Version
2021

2122
/// Errors related to Swift SDKs.
@@ -520,17 +521,16 @@ public struct SwiftSDK: Equatable {
520521
}
521522

522523
/// The Swift SDK describing the host platform.
523-
@available(*, deprecated, renamed: "hostSwiftSDK")
524+
@available(*, deprecated, renamed: "hostSwiftSDKAsync")
524525
public static func hostDestination(
525526
_ binDir: Basics.AbsolutePath? = nil,
526527
originalWorkingDirectory: Basics.AbsolutePath? = nil,
527528
environment: Environment
528529
) async throws -> SwiftSDK {
529-
try await self.hostSwiftSDK(binDir, environment: environment)
530+
try await self.hostSwiftSDKAsync(binDir, environment: environment)
530531
}
531532

532-
/// The Swift SDK for the host platform.
533-
@available(*, deprecated, message: "Use the async alternative")
533+
/// The Swift SDK for the host platform (synchronous version).
534534
public static func hostSwiftSDK(
535535
_ binDir: Basics.AbsolutePath? = nil,
536536
environment: Environment = .current,
@@ -545,8 +545,8 @@ public struct SwiftSDK: Equatable {
545545
)
546546
}
547547

548-
/// The Swift SDK for the host platform.
549-
public static func hostSwiftSDK(
548+
/// The Swift SDK for the host platform (asynchronous version).
549+
public static func hostSwiftSDKAsync(
550550
_ binDir: Basics.AbsolutePath? = nil,
551551
environment: Environment = .current,
552552
observabilityScope: ObservabilityScope? = nil,
@@ -624,7 +624,7 @@ public struct SwiftSDK: Equatable {
624624
)
625625
}
626626

627-
/// Helper to get the SDK path for a Darwin platform (async version).
627+
/// Helper to get the SDK path for a Darwin platform (sync version).
628628
private static func getSDKPath(
629629
for darwinPlatform: DarwinPlatform,
630630
environment: Environment
@@ -847,7 +847,54 @@ public struct SwiftSDK: Equatable {
847847
return nil
848848
}
849849

850-
/// Computes the target Swift SDK for the given options.
850+
/// Computes the target Swift SDK for the given options (synchronous version).
851+
@available(*, deprecated, message: "Use the async alternative")
852+
public static func deriveTargetSwiftSDK(
853+
hostSwiftSDK: SwiftSDK,
854+
hostTriple: Triple,
855+
customToolsets: [Basics.AbsolutePath] = [],
856+
customCompileDestination: Basics.AbsolutePath? = nil,
857+
customCompileTriple: Triple? = nil,
858+
customCompileToolchain: Basics.AbsolutePath? = nil,
859+
customCompileSDK: Basics.AbsolutePath? = nil,
860+
swiftSDKSelector: String? = nil,
861+
architectures: [String] = [],
862+
store: SwiftSDKBundleStore,
863+
observabilityScope: ObservabilityScope,
864+
fileSystem: FileSystem
865+
) throws -> SwiftSDK {
866+
let semaphore = DispatchSemaphore(value: 0)
867+
var result: Result<SwiftSDK, Error>!
868+
869+
Task {
870+
do {
871+
let sdk = try await deriveTargetSwiftSDK(
872+
hostSwiftSDK: hostSwiftSDK,
873+
hostTriple: hostTriple,
874+
customToolsets: customToolsets,
875+
customCompileDestination: customCompileDestination,
876+
customCompileTriple: customCompileTriple,
877+
customCompileToolchain: customCompileToolchain,
878+
customCompileSDK: customCompileSDK,
879+
swiftSDKSelector: swiftSDKSelector,
880+
architectures: architectures,
881+
store: store,
882+
observabilityScope: observabilityScope,
883+
fileSystem: fileSystem
884+
)
885+
result = .success(sdk)
886+
} catch {
887+
result = .failure(error)
888+
}
889+
semaphore.signal()
890+
}
891+
892+
semaphore.wait()
893+
return try result.get()
894+
}
895+
896+
/// Computes the target Swift SDK for the given options (async version).
897+
@_disfavoredOverload
851898
public static func deriveTargetSwiftSDK(
852899
hostSwiftSDK: SwiftSDK,
853900
hostTriple: Triple,

0 commit comments

Comments
 (0)