Skip to content

WIP: Make PackageRegistry module optional #5870

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

Closed
wants to merge 1 commit into from
Closed
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: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ let package = Package(
dependencies: [
"Basics",
"PackageFingerprint",
"PackageGraph",
"PackageLoading",
"PackageModel"
],
exclude: ["CMakeLists.txt"]
]
),

.target(
Expand Down Expand Up @@ -247,7 +247,6 @@ let package = Package(
"Basics",
"PackageLoading",
"PackageModel",
"PackageRegistry",
"SourceControl"
],
exclude: ["CMakeLists.txt", "README.md"]
Expand Down Expand Up @@ -333,6 +332,7 @@ let package = Package(
"Basics",
"PackageFingerprint",
"PackageGraph",
"PackageRegistry",
"PackageModel",
"SourceControl",
"SPMBuildCore",
Expand Down
1 change: 0 additions & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ add_subdirectory(PackageGraph)
add_subdirectory(PackageLoading)
add_subdirectory(PackageModel)
add_subdirectory(PackagePlugin)
add_subdirectory(PackageRegistry)
add_subdirectory(SPMBuildCore)
add_subdirectory(SPMLLBuild)
add_subdirectory(SourceControl)
Expand Down
3 changes: 3 additions & 0 deletions Sources/PackageGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ add_library(PackageGraph
Pubgrub/PartialSolution.swift
Pubgrub/PubgrubDependencyResolver.swift
Pubgrub/Term.swift
Registry/ClientInterface.swift
Registry/Registry.swift
Registry/RegistryConfiguration.swift
ResolvedPackage.swift
ResolvedProduct.swift
ResolvedTarget.swift
Expand Down
215 changes: 215 additions & 0 deletions Sources/PackageGraph/Registry/ClientInterface.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2022 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 Basics
import Dispatch
import Foundation
import PackageModel

import struct TSCBasic.AbsolutePath
import protocol TSCBasic.FileSystem
import protocol TSCBasic.HashAlgorithm

// MARK: - Registry downloads manager

public struct RegistryDownloads {
/// Additional information about a fetch
public struct FetchDetails: Equatable {
/// Indicates if the repository was fetched from the cache or from the remote.
public let fromCache: Bool
/// Indicates wether the wether the repository was already present in the cache and updated or if a clean fetch was performed.
public let updatedCache: Bool

public init(fromCache: Bool, updatedCache: Bool) {
self.fromCache = fromCache
self.updatedCache = updatedCache
}
}
}

/// Delegate to notify clients about actions being performed by RegistryManager.
public protocol RegistryDownloadsManagerDelegate {
/// Called when a package is about to be fetched.
func willFetch(package: PackageIdentity, version: Version, fetchDetails: RegistryDownloads.FetchDetails)

/// Called when a package has finished fetching.
func didFetch(package: PackageIdentity, version: Version, result: Result<RegistryDownloads.FetchDetails, Error>, duration: DispatchTimeInterval)

/// Called every time the progress of a repository fetch operation updates.
func fetching(package: PackageIdentity, version: Version, bytesDownloaded: Int64, totalBytesToDownload: Int64?)
}

public protocol RegistryDownloadsManagerInterface {
func lookup(
package: PackageIdentity,
version: Version,
observabilityScope: ObservabilityScope,
delegateQueue: DispatchQueue,
callbackQueue: DispatchQueue,
completion: @escaping (Result<AbsolutePath, Error>) -> Void
)

func purgeCache() throws
func remove(package: PackageIdentity) throws
func reset() throws
}

// MARK: - Registry client

public struct RegistryPackageMetadata {
public let versions: [Version]
public let alternateLocations: [URL]?

public init(versions: [Version], alternateLocations: [URL]?) {
self.versions = versions
self.alternateLocations = alternateLocations
}
}

public protocol RegistryClientInterface {
var configured: Bool { get }

func cancel(deadline: DispatchTime) throws

func downloadSourceArchive(
package: PackageIdentity,
version: Version,
fileSystem: FileSystem,
destinationPath: AbsolutePath,
checksumAlgorithm: HashAlgorithm, // the same algorithm used by `package compute-checksum` tool
progressHandler: ((_ bytesReceived: Int64, _ totalBytes: Int64?) -> Void)?,
timeout: DispatchTimeInterval?,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<Void, Error>) -> Void
)

func getAvailableManifests(
package: PackageIdentity,
version: Version,
timeout: DispatchTimeInterval?,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<[String: (toolsVersion: ToolsVersion, content: String?)], Error>) -> Void
)

func getManifestContent(
package: PackageIdentity,
version: Version,
customToolsVersion: ToolsVersion?,
timeout: DispatchTimeInterval?,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<String, Error>) -> Void
)

func getPackageMetadata(
package: PackageIdentity,
timeout: DispatchTimeInterval?,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<RegistryPackageMetadata, Error>) -> Void
)

func lookupIdentities(
url: URL,
timeout: DispatchTimeInterval?,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<Set<PackageIdentity>, Error>) -> Void
)
}

public extension RegistryClientInterface {
func downloadSourceArchive(
package: PackageIdentity,
version: Version,
fileSystem: FileSystem,
destinationPath: AbsolutePath,
checksumAlgorithm: HashAlgorithm, // the same algorithm used by `package compute-checksum` tool
progressHandler: ((_ bytesReceived: Int64, _ totalBytes: Int64?) -> Void)?,
timeout: DispatchTimeInterval? = .none,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<Void, Error>) -> Void
) {
self.downloadSourceArchive(package: package,
version: version,
fileSystem: fileSystem,
destinationPath: destinationPath,
checksumAlgorithm: checksumAlgorithm,
progressHandler: progressHandler,
timeout: .none,
observabilityScope: observabilityScope,
callbackQueue: callbackQueue,
completion: completion)
}

func getAvailableManifests(
package: PackageIdentity,
version: Version,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<[String: (toolsVersion: ToolsVersion, content: String?)], Error>) -> Void
) {
self.getAvailableManifests(package: package,
version: version,
timeout: .none,
observabilityScope: observabilityScope,
callbackQueue: callbackQueue,
completion: completion)
}

func getManifestContent(
package: PackageIdentity,
version: Version,
customToolsVersion: ToolsVersion?,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<String, Error>) -> Void
) {
self.getManifestContent(package: package,
version: version,
customToolsVersion: customToolsVersion,
timeout: .none,
observabilityScope: observabilityScope,
callbackQueue: callbackQueue,
completion: completion)
}

func getPackageMetadata(
package: PackageIdentity,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<RegistryPackageMetadata, Error>) -> Void
) {
self.getPackageMetadata(
package: package,
timeout: .none,
observabilityScope: observabilityScope,
callbackQueue: callbackQueue,
completion: completion)
}

func lookupIdentities(
url: URL,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<Set<PackageIdentity>, Error>) -> Void
) {
self.lookupIdentities(url: url,
timeout: .none,
observabilityScope: observabilityScope,
callbackQueue: callbackQueue,
completion: completion)
}
}
25 changes: 0 additions & 25 deletions Sources/PackageRegistry/CMakeLists.txt

This file was deleted.

14 changes: 4 additions & 10 deletions Sources/PackageRegistry/RegistryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import Basics
import Dispatch
import Foundation
import PackageFingerprint
import PackageGraph
import PackageLoading
import PackageModel
import TSCBasic

/// Package registry client.
/// API specification: https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md
public final class RegistryClient: Cancellable {
public final class RegistryClient: RegistryClientInterface, Cancellable {
private let apiVersion: APIVersion = .v1

private let configuration: RegistryConfiguration
Expand Down Expand Up @@ -62,7 +63,7 @@ public final class RegistryClient: Cancellable {
timeout: DispatchTimeInterval? = .none,
observabilityScope: ObservabilityScope,
callbackQueue: DispatchQueue,
completion: @escaping (Result<PackageMetadata, Error>) -> Void
completion: @escaping (Result<RegistryPackageMetadata, Error>) -> Void
) {
let completion = self.makeAsync(completion, on: callbackQueue)

Expand Down Expand Up @@ -107,7 +108,7 @@ public final class RegistryClient: Cancellable {

let alternateLocations = try response.headers.parseAlternativeLocationLinks()

return PackageMetadata(
return RegistryPackageMetadata(
versions: versions,
alternateLocations: alternateLocations?.map{ $0.url }
)
Expand Down Expand Up @@ -657,13 +658,6 @@ fileprivate extension RegistryClient {
}
}

extension RegistryClient {
public struct PackageMetadata {
public let versions: [Version]
public let alternateLocations: [URL]?
}
}

fileprivate extension RegistryClient {
struct AlternativeLocationLink {
let url: URL
Expand Down
Loading