Skip to content

Use async HTTPClient in BinaryArtifactsManager #8087

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 6 commits into from
Nov 4, 2024
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
6 changes: 6 additions & 0 deletions Sources/Basics/Concurrency/ThreadSafeBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public final class ThreadSafeBox<Value> {
self.underlying = value
}
}

public func mutate(body: (inout Value?) throws -> ()) rethrows {
try self.lock.withLock {
try body(&self.underlying)
}
}

@discardableResult
public func memoize(body: () throws -> Value) rethrows -> Value {
Expand Down
46 changes: 27 additions & 19 deletions Sources/Workspace/Diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,59 +123,67 @@ extension Basics.Diagnostic {
static func customDependencyMissing(packageName: String) -> Self {
.warning("dependency '\(packageName)' is missing; retrieving again")
}
}

struct BinaryArtifactsManagerError: Error, CustomStringConvertible {
let description: String

private init(description: String) {
self.description = description
}

static func artifactInvalidArchive(artifactURL: URL, targetName: String) -> Self {
.error(
"invalid archive returned from '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)'"
.init(
description: "invalid archive returned from '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)'"
)
}

static func artifactChecksumChanged(targetName: String) -> Self {
.error(
"artifact of binary target '\(targetName)' has changed checksum; this is a potential security risk so the new artifact won't be downloaded"
.init(
description: "artifact of binary target '\(targetName)' has changed checksum; this is a potential security risk so the new artifact won't be downloaded"
)
}

static func artifactInvalidChecksum(targetName: String, expectedChecksum: String, actualChecksum: String?) -> Self {
.error(
"checksum of downloaded artifact of binary target '\(targetName)' (\(actualChecksum ?? "none")) does not match checksum specified by the manifest (\(expectedChecksum))"
.init(
description: "checksum of downloaded artifact of binary target '\(targetName)' (\(actualChecksum ?? "none")) does not match checksum specified by the manifest (\(expectedChecksum))"
)
}

static func artifactFailedDownload(artifactURL: URL, targetName: String, reason: String) -> Self {
.error(
"failed downloading '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)': \(reason)"
.init(
description: "failed downloading '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)': \(reason)"
)
}

static func artifactFailedValidation(artifactURL: URL, targetName: String, reason: String) -> Self {
.error(
"failed validating archive from '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)': \(reason)"
.init(
description: "failed validating archive from '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)': \(reason)"
)
}

static func remoteArtifactFailedExtraction(artifactURL: URL, targetName: String, reason: String) -> Self {
.error(
"failed extracting '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)': \(reason)"
.init(
description: "failed extracting '\(artifactURL.absoluteString)' which is required by binary target '\(targetName)': \(reason)"
)
}

static func localArtifactFailedExtraction(artifactPath: AbsolutePath, targetName: String, reason: String) -> Self {
.error("failed extracting '\(artifactPath)' which is required by binary target '\(targetName)': \(reason)")
.init(description: "failed extracting '\(artifactPath)' which is required by binary target '\(targetName)': \(reason)")
}

static func remoteArtifactNotFound(artifactURL: URL, targetName: String) -> Self {
.error(
"downloaded archive of binary target '\(targetName)' from '\(artifactURL.absoluteString)' does not contain a binary artifact."
.init(
description: "downloaded archive of binary target '\(targetName)' from '\(artifactURL.absoluteString)' does not contain a binary artifact."
)
}

static func localArchivedArtifactNotFound(archivePath: AbsolutePath, targetName: String) -> Self {
.error("local archive of binary target '\(targetName)' at '\(archivePath)' does not contain a binary artifact.")
.init(description: "local archive of binary target '\(targetName)' at '\(archivePath)' does not contain a binary artifact.")
}

static func localArtifactNotFound(artifactPath: AbsolutePath, targetName: String) -> Self {
.error("local binary target '\(targetName)' at '\(artifactPath)' does not contain a binary artifact.")
.init(description: "local binary target '\(targetName)' at '\(artifactPath)' does not contain a binary artifact.")
}

static func exhaustedAttempts(missing: [PackageReference]) -> Self {
Expand All @@ -189,8 +197,8 @@ extension Basics.Diagnostic {
return "'\($0.identity)' at \(path)"
}
}
return .error(
"exhausted attempts to resolve the dependencies graph, with the following dependencies unresolved:\n* \(missing.joined(separator: "\n* "))"
return .init(
description: "exhausted attempts to resolve the dependencies graph, with the following dependencies unresolved:\n* \(missing.joined(separator: "\n* "))"
)
}
}
Expand Down
Loading