Skip to content

Commit b2d7a82

Browse files
authored
Fix symlinked swift-experimental-destination invocations (#6382)
`swift experimental-destination` subcommands no longer work and always display help output. This is a regression introduced in #6362 after making `SwiftDestinationTool` conform to `AsyncParsableCommand` instead of `ParsableCommand` but not updating `swift-package-manager` command sources to call `async` overload of `main()` function on `SwiftDestinationTool`. rdar://107618266
1 parent e21df87 commit b2d7a82

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

Sources/CrossCompilationDestinationsTool/DestinationCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import var TSCBasic.localFileSystem
2222
import var TSCBasic.stdoutStream
2323

2424
/// A protocol for functions and properties common to all destination subcommands.
25-
protocol DestinationCommand: AsyncParsableCommand {
25+
protocol DestinationCommand: ParsableCommand {
2626
/// Common locations options provided by ArgumentParser.
2727
var locations: LocationOptions { get }
2828

@@ -35,7 +35,7 @@ protocol DestinationCommand: AsyncParsableCommand {
3535
buildTimeTriple: Triple,
3636
_ destinationsDirectory: AbsolutePath,
3737
_ observabilityScope: ObservabilityScope
38-
) async throws
38+
) throws
3939
}
4040

4141
extension DestinationCommand {
@@ -62,7 +62,7 @@ extension DestinationCommand {
6262
return destinationsDirectory
6363
}
6464

65-
public func run() async throws {
65+
public func run() throws {
6666
let observabilityHandler = SwiftToolObservabilityHandler(outputStream: stdoutStream, logLevel: .info)
6767
let observabilitySystem = ObservabilitySystem(observabilityHandler)
6868
let observabilityScope = observabilitySystem.topScope
@@ -73,7 +73,7 @@ extension DestinationCommand {
7373

7474
var commandError: Error? = nil
7575
do {
76-
try await self.run(buildTimeTriple: triple, destinationsDirectory, observabilityScope)
76+
try self.run(buildTimeTriple: triple, destinationsDirectory, observabilityScope)
7777
if observabilityScope.errorsReported {
7878
throw ExitCode.failure
7979
}

Sources/CrossCompilationDestinationsTool/InstallDestination.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public struct InstallDestination: DestinationCommand {
4242
buildTimeTriple: Triple,
4343
_ destinationsDirectory: AbsolutePath,
4444
_ observabilityScope: ObservabilityScope
45-
) async throws {
46-
try await DestinationBundle.install(
45+
) throws {
46+
try DestinationBundle.install(
4747
bundlePathOrURL: bundlePathOrURL,
4848
destinationsDirectory: destinationsDirectory,
4949
self.fileSystem,

Sources/CrossCompilationDestinationsTool/SwiftDestinationTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import ArgumentParser
1414
import Basics
1515

16-
public struct SwiftDestinationTool: AsyncParsableCommand {
16+
public struct SwiftDestinationTool: ParsableCommand {
1717
public static let configuration = CommandConfiguration(
1818
commandName: "experimental-destination",
1919
_superCommandName: "swift",

Sources/PackageModel/DestinationBundle.swift

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import Basics
1515

1616
import func TSCBasic.tsc_await
17+
import func TSCBasic.withTemporaryDirectory
1718
import protocol TSCBasic.FileSystem
1819
import struct Foundation.URL
1920
import struct TSCBasic.AbsolutePath
@@ -139,9 +140,8 @@ public struct DestinationBundle {
139140
_ fileSystem: some FileSystem,
140141
_ archiver: some Archiver,
141142
_ observabilityScope: ObservabilityScope
142-
) async throws {
143-
_ = try await withTemporaryDirectory(
144-
fileSystem: fileSystem,
143+
) throws {
144+
_ = try withTemporaryDirectory(
145145
removeTreeOnDeinit: true
146146
) { temporaryDirectory in
147147
let bundlePath: AbsolutePath
@@ -154,18 +154,21 @@ public struct DestinationBundle {
154154
let bundleName = bundleURL.lastPathComponent
155155
let downloadedBundlePath = temporaryDirectory.appending(component: bundleName)
156156

157-
let client = HTTPClient()
158-
var request = HTTPClientRequest.download(
157+
let client = LegacyHTTPClient()
158+
var request = LegacyHTTPClientRequest.download(
159159
url: bundleURL,
160-
fileSystem: AsyncFileSystem { fileSystem },
160+
fileSystem: fileSystem,
161161
destination: downloadedBundlePath
162162
)
163163
request.options.validResponseCodes = [200]
164-
_ = try await client.execute(
165-
request,
166-
observabilityScope: observabilityScope,
167-
progress: nil
168-
)
164+
_ = try tsc_await {
165+
client.execute(
166+
request,
167+
observabilityScope: observabilityScope,
168+
progress: nil,
169+
completion: $0
170+
)
171+
}
169172

170173
bundlePath = downloadedBundlePath
171174

@@ -179,15 +182,15 @@ public struct DestinationBundle {
179182
throw DestinationError.invalidPathOrURL(bundlePathOrURL)
180183
}
181184

182-
try await installIfValid(
185+
try installIfValid(
183186
bundlePath: bundlePath,
184187
destinationsDirectory: destinationsDirectory,
185188
temporaryDirectory: temporaryDirectory,
186189
fileSystem,
187190
archiver,
188191
observabilityScope
189192
)
190-
}.value
193+
}
191194

192195
print("Destination artifact bundle at `\(bundlePathOrURL)` successfully installed.")
193196
}
@@ -206,7 +209,7 @@ public struct DestinationBundle {
206209
temporaryDirectory: AbsolutePath,
207210
_ fileSystem: some FileSystem,
208211
_ archiver: some Archiver
209-
) async throws -> AbsolutePath {
212+
) throws -> AbsolutePath {
210213
let regex = try RegEx(pattern: "(.+\\.artifactbundle).*")
211214

212215
guard let bundleName = bundlePath.components.last else {
@@ -229,7 +232,7 @@ public struct DestinationBundle {
229232
return bundlePath
230233
}
231234

232-
try await archiver.extract(from: bundlePath, to: temporaryDirectory)
235+
try tsc_await { archiver.extract(from: bundlePath, to: temporaryDirectory, completion: $0) }
233236

234237
return temporaryDirectory.appending(component: unpackedBundleName)
235238
}
@@ -247,8 +250,8 @@ public struct DestinationBundle {
247250
_ fileSystem: some FileSystem,
248251
_ archiver: some Archiver,
249252
_ observabilityScope: ObservabilityScope
250-
) async throws {
251-
let unpackedBundlePath = try await unpackIfNeeded(
253+
) throws {
254+
let unpackedBundlePath = try unpackIfNeeded(
252255
bundlePath: bundlePath,
253256
destinationsDirectory: destinationsDirectory,
254257
temporaryDirectory: temporaryDirectory,

Sources/swift-experimental-destination/SwiftDestinationTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Basics
1515
import CrossCompilationDestinationsTool
1616

1717
@main
18-
struct SwiftDestinationTool: AsyncParsableCommand {
18+
struct SwiftDestinationTool: ParsableCommand {
1919
static let configuration = CommandConfiguration(
2020
commandName: "experimental-destination",
2121
_superCommandName: "swift",

0 commit comments

Comments
 (0)