Skip to content

Commit 26ba70c

Browse files
authored
[5.9] Fix symlinked swift-experimental-destination invocations (#6383)
`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 c41418a commit 26ba70c

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
@@ -13,6 +13,7 @@
1313
import Basics
1414

1515
import func TSCBasic.tsc_await
16+
import func TSCBasic.withTemporaryDirectory
1617
import protocol TSCBasic.FileSystem
1718
import struct Foundation.URL
1819
import struct TSCBasic.AbsolutePath
@@ -138,9 +139,8 @@ public struct DestinationBundle {
138139
_ fileSystem: some FileSystem,
139140
_ archiver: some Archiver,
140141
_ observabilityScope: ObservabilityScope
141-
) async throws {
142-
_ = try await withTemporaryDirectory(
143-
fileSystem: fileSystem,
142+
) throws {
143+
_ = try withTemporaryDirectory(
144144
removeTreeOnDeinit: true
145145
) { temporaryDirectory in
146146
let bundlePath: AbsolutePath
@@ -153,18 +153,21 @@ public struct DestinationBundle {
153153
let bundleName = bundleURL.lastPathComponent
154154
let downloadedBundlePath = temporaryDirectory.appending(component: bundleName)
155155

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

169172
bundlePath = downloadedBundlePath
170173

@@ -178,15 +181,15 @@ public struct DestinationBundle {
178181
throw DestinationError.invalidPathOrURL(bundlePathOrURL)
179182
}
180183

181-
try await installIfValid(
184+
try installIfValid(
182185
bundlePath: bundlePath,
183186
destinationsDirectory: destinationsDirectory,
184187
temporaryDirectory: temporaryDirectory,
185188
fileSystem,
186189
archiver,
187190
observabilityScope
188191
)
189-
}.value
192+
}
190193

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

211214
guard let bundleName = bundlePath.components.last else {
@@ -228,7 +231,7 @@ public struct DestinationBundle {
228231
return bundlePath
229232
}
230233

231-
try await archiver.extract(from: bundlePath, to: temporaryDirectory)
234+
try tsc_await { archiver.extract(from: bundlePath, to: temporaryDirectory, completion: $0) }
232235

233236
return temporaryDirectory.appending(component: unpackedBundleName)
234237
}
@@ -246,8 +249,8 @@ public struct DestinationBundle {
246249
_ fileSystem: some FileSystem,
247250
_ archiver: some Archiver,
248251
_ observabilityScope: ObservabilityScope
249-
) async throws {
250-
let unpackedBundlePath = try await unpackIfNeeded(
252+
) throws {
253+
let unpackedBundlePath = try unpackIfNeeded(
251254
bundlePath: bundlePath,
252255
destinationsDirectory: destinationsDirectory,
253256
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)