Skip to content

Fix symlinked swift-experimental-destination invocations #6382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import var TSCBasic.localFileSystem
import var TSCBasic.stdoutStream

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

Expand All @@ -35,7 +35,7 @@ protocol DestinationCommand: AsyncParsableCommand {
buildTimeTriple: Triple,
_ destinationsDirectory: AbsolutePath,
_ observabilityScope: ObservabilityScope
) async throws
) throws
}

extension DestinationCommand {
Expand All @@ -62,7 +62,7 @@ extension DestinationCommand {
return destinationsDirectory
}

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

var commandError: Error? = nil
do {
try await self.run(buildTimeTriple: triple, destinationsDirectory, observabilityScope)
try self.run(buildTimeTriple: triple, destinationsDirectory, observabilityScope)
if observabilityScope.errorsReported {
throw ExitCode.failure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public struct InstallDestination: DestinationCommand {
buildTimeTriple: Triple,
_ destinationsDirectory: AbsolutePath,
_ observabilityScope: ObservabilityScope
) async throws {
try await DestinationBundle.install(
) throws {
try DestinationBundle.install(
bundlePathOrURL: bundlePathOrURL,
destinationsDirectory: destinationsDirectory,
self.fileSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ArgumentParser
import Basics

public struct SwiftDestinationTool: AsyncParsableCommand {
public struct SwiftDestinationTool: ParsableCommand {
public static let configuration = CommandConfiguration(
commandName: "experimental-destination",
_superCommandName: "swift",
Expand Down
37 changes: 20 additions & 17 deletions Sources/PackageModel/DestinationBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import Basics

import func TSCBasic.tsc_await
import func TSCBasic.withTemporaryDirectory
import protocol TSCBasic.FileSystem
import struct Foundation.URL
import struct TSCBasic.AbsolutePath
Expand Down Expand Up @@ -139,9 +140,8 @@ public struct DestinationBundle {
_ fileSystem: some FileSystem,
_ archiver: some Archiver,
_ observabilityScope: ObservabilityScope
) async throws {
_ = try await withTemporaryDirectory(
fileSystem: fileSystem,
) throws {
_ = try withTemporaryDirectory(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downside of this change is that non-async withTemporaryDirectory does not take a FileSystem argument, which makes it harder to test. But this is the only way until our macOS CI nodes have Xcode with support for concurrency back-deployment.

removeTreeOnDeinit: true
) { temporaryDirectory in
let bundlePath: AbsolutePath
Expand All @@ -154,18 +154,21 @@ public struct DestinationBundle {
let bundleName = bundleURL.lastPathComponent
let downloadedBundlePath = temporaryDirectory.appending(component: bundleName)

let client = HTTPClient()
var request = HTTPClientRequest.download(
let client = LegacyHTTPClient()
var request = LegacyHTTPClientRequest.download(
url: bundleURL,
fileSystem: AsyncFileSystem { fileSystem },
fileSystem: fileSystem,
destination: downloadedBundlePath
)
request.options.validResponseCodes = [200]
_ = try await client.execute(
request,
observabilityScope: observabilityScope,
progress: nil
)
_ = try tsc_await {
client.execute(
request,
observabilityScope: observabilityScope,
progress: nil,
completion: $0
)
}

bundlePath = downloadedBundlePath

Expand All @@ -179,15 +182,15 @@ public struct DestinationBundle {
throw DestinationError.invalidPathOrURL(bundlePathOrURL)
}

try await installIfValid(
try installIfValid(
bundlePath: bundlePath,
destinationsDirectory: destinationsDirectory,
temporaryDirectory: temporaryDirectory,
fileSystem,
archiver,
observabilityScope
)
}.value
}

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

guard let bundleName = bundlePath.components.last else {
Expand All @@ -229,7 +232,7 @@ public struct DestinationBundle {
return bundlePath
}

try await archiver.extract(from: bundlePath, to: temporaryDirectory)
try tsc_await { archiver.extract(from: bundlePath, to: temporaryDirectory, completion: $0) }

return temporaryDirectory.appending(component: unpackedBundleName)
}
Expand All @@ -247,8 +250,8 @@ public struct DestinationBundle {
_ fileSystem: some FileSystem,
_ archiver: some Archiver,
_ observabilityScope: ObservabilityScope
) async throws {
let unpackedBundlePath = try await unpackIfNeeded(
) throws {
let unpackedBundlePath = try unpackIfNeeded(
bundlePath: bundlePath,
destinationsDirectory: destinationsDirectory,
temporaryDirectory: temporaryDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Basics
import CrossCompilationDestinationsTool

@main
struct SwiftDestinationTool: AsyncParsableCommand {
struct SwiftDestinationTool: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "experimental-destination",
_superCommandName: "swift",
Expand Down