diff --git a/Sources/PackageModel/SwiftSDKBundle.swift b/Sources/PackageModel/SwiftSDKBundle.swift index 34ee2b29b64..9d4638c9e0b 100644 --- a/Sources/PackageModel/SwiftSDKBundle.swift +++ b/Sources/PackageModel/SwiftSDKBundle.swift @@ -135,8 +135,8 @@ public struct SwiftSDKBundle { _ fileSystem: some FileSystem, _ archiver: some Archiver, _ observabilityScope: ObservabilityScope - ) throws { - _ = try withTemporaryDirectory( + ) async throws { + _ = try await withTemporaryDirectory( removeTreeOnDeinit: true ) { temporaryDirectory in let bundlePath: AbsolutePath @@ -149,21 +149,18 @@ public struct SwiftSDKBundle { let bundleName = bundleURL.lastPathComponent let downloadedBundlePath = temporaryDirectory.appending(component: bundleName) - let client = LegacyHTTPClient() - var request = LegacyHTTPClientRequest.download( + let client = HTTPClient() + var request = HTTPClientRequest.download( url: bundleURL, fileSystem: fileSystem, destination: downloadedBundlePath ) request.options.validResponseCodes = [200] - _ = try temp_await { - client.execute( - request, - observabilityScope: observabilityScope, - progress: nil, - completion: $0 - ) - } + _ = try await client.execute( + request, + observabilityScope: observabilityScope, + progress: nil + ) bundlePath = downloadedBundlePath @@ -177,7 +174,7 @@ public struct SwiftSDKBundle { throw DestinationError.invalidPathOrURL(bundlePathOrURL) } - try installIfValid( + try await installIfValid( bundlePath: bundlePath, destinationsDirectory: swiftSDKsDirectory, temporaryDirectory: temporaryDirectory, @@ -204,7 +201,7 @@ public struct SwiftSDKBundle { temporaryDirectory: AbsolutePath, _ fileSystem: some FileSystem, _ archiver: some Archiver - ) throws -> AbsolutePath { + ) async throws -> AbsolutePath { let regex = try RegEx(pattern: "(.+\\.artifactbundle).*") guard let bundleName = bundlePath.components.last else { @@ -227,7 +224,7 @@ public struct SwiftSDKBundle { print("\(bundleName) is assumed to be an archive, unpacking...") - try temp_await { archiver.extract(from: bundlePath, to: temporaryDirectory, completion: $0) } + try await archiver.extract(from: bundlePath, to: temporaryDirectory) return temporaryDirectory.appending(component: unpackedBundleName) } @@ -245,7 +242,7 @@ public struct SwiftSDKBundle { _ fileSystem: some FileSystem, _ archiver: some Archiver, _ observabilityScope: ObservabilityScope - ) throws { + ) async throws { #if os(macOS) // Check the quarantine attribute on bundles downloaded manually in the browser. guard !fileSystem.hasAttribute(.quarantine, bundlePath) else { @@ -253,7 +250,7 @@ public struct SwiftSDKBundle { } #endif - let unpackedBundlePath = try unpackIfNeeded( + let unpackedBundlePath = try await unpackIfNeeded( bundlePath: bundlePath, destinationsDirectory: destinationsDirectory, temporaryDirectory: temporaryDirectory, diff --git a/Sources/SwiftSDKTool/InstallSwiftSDK.swift b/Sources/SwiftSDKTool/InstallSwiftSDK.swift index c3e72b28851..762ec89c3c5 100644 --- a/Sources/SwiftSDKTool/InstallSwiftSDK.swift +++ b/Sources/SwiftSDKTool/InstallSwiftSDK.swift @@ -39,10 +39,10 @@ public struct InstallSwiftSDK: SwiftSDKSubcommand { buildTimeTriple: Triple, _ destinationsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope - ) throws { + ) async throws { let cancellator = Cancellator(observabilityScope: observabilityScope) cancellator.installSignalHandlers() - try SwiftSDKBundle.install( + try await SwiftSDKBundle.install( bundlePathOrURL: bundlePathOrURL, swiftSDKsDirectory: destinationsDirectory, self.fileSystem, diff --git a/Sources/SwiftSDKTool/RemoveSwiftSDK.swift b/Sources/SwiftSDKTool/RemoveSwiftSDK.swift index b081ef98cca..b1a422b7eb1 100644 --- a/Sources/SwiftSDKTool/RemoveSwiftSDK.swift +++ b/Sources/SwiftSDKTool/RemoveSwiftSDK.swift @@ -35,7 +35,7 @@ public struct RemoveSwiftSDK: SwiftSDKSubcommand { buildTimeTriple: Triple, _ destinationsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope - ) throws { + ) async throws { let destinationsDirectory = try self.getOrCreateDestinationsDirectory() let artifactBundleDirectory = destinationsDirectory.appending(component: self.sdkIDOrBundleName) diff --git a/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift b/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift index 751488012dd..2c702cc6eea 100644 --- a/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift +++ b/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift @@ -19,7 +19,7 @@ import PackageModel import var TSCBasic.stdoutStream /// A protocol for functions and properties common to all destination subcommands. -protocol SwiftSDKSubcommand: ParsableCommand { +protocol SwiftSDKSubcommand: AsyncParsableCommand { /// Common locations options provided by ArgumentParser. var locations: LocationOptions { get } @@ -32,7 +32,7 @@ protocol SwiftSDKSubcommand: ParsableCommand { buildTimeTriple: Triple, _ destinationsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope - ) throws + ) async throws } extension SwiftSDKSubcommand { @@ -59,7 +59,7 @@ extension SwiftSDKSubcommand { return destinationsDirectory } - public func run() throws { + public func run() async throws { let observabilityHandler = SwiftToolObservabilityHandler(outputStream: stdoutStream, logLevel: .info) let observabilitySystem = ObservabilitySystem(observabilityHandler) let observabilityScope = observabilitySystem.topScope @@ -70,7 +70,7 @@ extension SwiftSDKSubcommand { var commandError: Error? = nil do { - try self.run(buildTimeTriple: triple, destinationsDirectory, observabilityScope) + try await self.run(buildTimeTriple: triple, destinationsDirectory, observabilityScope) if observabilityScope.errorsReported { throw ExitCode.failure } diff --git a/Sources/SwiftSDKTool/SwiftSDKTool.swift b/Sources/SwiftSDKTool/SwiftSDKTool.swift index 5989922d4ba..3b2799ac783 100644 --- a/Sources/SwiftSDKTool/SwiftSDKTool.swift +++ b/Sources/SwiftSDKTool/SwiftSDKTool.swift @@ -12,8 +12,8 @@ import ArgumentParser import Basics - -public struct SwiftSDKTool: ParsableCommand { + +public struct SwiftSDKTool: AsyncParsableCommand { public static let configuration = CommandConfiguration( commandName: "experimental-sdk", _superCommandName: "swift", diff --git a/Sources/swift-experimental-sdk/CMakeLists.txt b/Sources/swift-experimental-sdk/CMakeLists.txt index dcdd69e4a82..99a7730a71b 100644 --- a/Sources/swift-experimental-sdk/CMakeLists.txt +++ b/Sources/swift-experimental-sdk/CMakeLists.txt @@ -7,7 +7,7 @@ # See http://swift.org/CONTRIBUTORS.txt for Swift project authors add_executable(swift-experimental-sdk - SwiftSDKTool.swift) + Entrypoint.swift) target_link_libraries(swift-experimental-sdk PRIVATE SwiftSDKTool) diff --git a/Sources/swift-experimental-sdk/Entrypoint.swift b/Sources/swift-experimental-sdk/Entrypoint.swift new file mode 100644 index 00000000000..385c109192e --- /dev/null +++ b/Sources/swift-experimental-sdk/Entrypoint.swift @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftSDKTool + +@main +struct Entrypoint { + static func main() async { + await SwiftSDKTool.main() + } +} diff --git a/Sources/swift-experimental-sdk/SwiftSDKTool.swift b/Sources/swift-experimental-sdk/SwiftSDKTool.swift deleted file mode 100644 index 68247498338..00000000000 --- a/Sources/swift-experimental-sdk/SwiftSDKTool.swift +++ /dev/null @@ -1,32 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift open source project -// -// Copyright (c) 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See http://swift.org/LICENSE.txt for license information -// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -import ArgumentParser -import Basics -import SwiftSDKTool - -@main -struct SwiftSDKTool: ParsableCommand { - static let configuration = CommandConfiguration( - commandName: "experimental-sdk", - _superCommandName: "swift", - abstract: "Perform operations on Swift SDKs.", - version: SwiftVersion.current.completeDisplayString, - subcommands: [ - ConfigureSwiftSDK.self, - InstallSwiftSDK.self, - ListSwiftSDKs.self, - RemoveSwiftSDK.self, - ], - helpNames: [.short, .long, .customLong("help", withSingleDash: true)] - ) -} diff --git a/Sources/swift-package-manager/SwiftPM.swift b/Sources/swift-package-manager/SwiftPM.swift index 8502bb621ca..6231240f7b4 100644 --- a/Sources/swift-package-manager/SwiftPM.swift +++ b/Sources/swift-package-manager/SwiftPM.swift @@ -22,14 +22,14 @@ let execName = (try? AbsolutePath(validating: firstArg).basenameWithoutExt) ?? @main struct SwiftPM { - static func main() { + static func main() async { switch execName { case "swift-package": SwiftPackageTool.main() case "swift-build": SwiftBuildTool.main() case "swift-experimental-sdk": - SwiftSDKTool.main() + await SwiftSDKTool.main() case "swift-test": SwiftTestTool.main() case "swift-run": diff --git a/Tests/PackageModelTests/SwiftSDKBundleTests.swift b/Tests/PackageModelTests/SwiftSDKBundleTests.swift index 140ef9ae5e8..f7d0698b600 100644 --- a/Tests/PackageModelTests/SwiftSDKBundleTests.swift +++ b/Tests/PackageModelTests/SwiftSDKBundleTests.swift @@ -97,7 +97,7 @@ final class SwiftSDKBundleTests: XCTestCase { let archiver = MockArchiver() - try SwiftSDKBundle.install( + try await SwiftSDKBundle.install( bundlePathOrURL: bundles[0].path, swiftSDKsDirectory: swiftSDKsDirectory, fileSystem, @@ -107,7 +107,7 @@ final class SwiftSDKBundleTests: XCTestCase { let invalidPath = "foobar" do { - try SwiftSDKBundle.install( + try await SwiftSDKBundle.install( bundlePathOrURL: "foobar", swiftSDKsDirectory: swiftSDKsDirectory, fileSystem, @@ -131,7 +131,7 @@ final class SwiftSDKBundleTests: XCTestCase { } do { - try SwiftSDKBundle.install( + try await SwiftSDKBundle.install( bundlePathOrURL: bundles[0].path, swiftSDKsDirectory: swiftSDKsDirectory, fileSystem, @@ -155,7 +155,7 @@ final class SwiftSDKBundleTests: XCTestCase { } do { - try SwiftSDKBundle.install( + try await SwiftSDKBundle.install( bundlePathOrURL: bundles[1].path, swiftSDKsDirectory: swiftSDKsDirectory, fileSystem, @@ -191,7 +191,7 @@ final class SwiftSDKBundleTests: XCTestCase { let system = ObservabilitySystem.makeForTesting() for bundle in bundles { - try SwiftSDKBundle.install( + try await SwiftSDKBundle.install( bundlePathOrURL: bundle.path, swiftSDKsDirectory: swiftSDKsDirectory, fileSystem,