Skip to content

Commit 3f753dc

Browse files
committed
WIP: Make PackageRegistry module optional
1 parent ce09926 commit 3f753dc

17 files changed

+278
-103
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ let package = Package(
196196
dependencies: [
197197
"Basics",
198198
"PackageFingerprint",
199+
"PackageGraph",
199200
"PackageLoading",
200201
"PackageModel"
201-
],
202-
exclude: ["CMakeLists.txt"]
202+
]
203203
),
204204

205205
.target(
@@ -247,7 +247,6 @@ let package = Package(
247247
"Basics",
248248
"PackageLoading",
249249
"PackageModel",
250-
"PackageRegistry",
251250
"SourceControl"
252251
],
253252
exclude: ["CMakeLists.txt", "README.md"]
@@ -333,6 +332,7 @@ let package = Package(
333332
"Basics",
334333
"PackageFingerprint",
335334
"PackageGraph",
335+
"PackageRegistry",
336336
"PackageModel",
337337
"SourceControl",
338338
"SPMBuildCore",

Sources/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ add_subdirectory(PackageGraph)
2323
add_subdirectory(PackageLoading)
2424
add_subdirectory(PackageModel)
2525
add_subdirectory(PackagePlugin)
26-
add_subdirectory(PackageRegistry)
2726
add_subdirectory(SPMBuildCore)
2827
add_subdirectory(SPMLLBuild)
2928
add_subdirectory(SourceControl)

Sources/PackageGraph/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ add_library(PackageGraph
2626
Pubgrub/PartialSolution.swift
2727
Pubgrub/PubgrubDependencyResolver.swift
2828
Pubgrub/Term.swift
29+
Registry/ClientInterface.swift
30+
Registry/Registry.swift
31+
Registry/RegistryConfiguration.swift
2932
ResolvedPackage.swift
3033
ResolvedProduct.swift
3134
ResolvedTarget.swift
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Basics
14+
import Dispatch
15+
import Foundation
16+
import PackageModel
17+
18+
import struct TSCBasic.AbsolutePath
19+
import protocol TSCBasic.FileSystem
20+
import protocol TSCBasic.HashAlgorithm
21+
22+
// MARK: - Registry downloads manager
23+
24+
public struct RegistryDownloads {
25+
/// Additional information about a fetch
26+
public struct FetchDetails: Equatable {
27+
/// Indicates if the repository was fetched from the cache or from the remote.
28+
public let fromCache: Bool
29+
/// Indicates wether the wether the repository was already present in the cache and updated or if a clean fetch was performed.
30+
public let updatedCache: Bool
31+
32+
public init(fromCache: Bool, updatedCache: Bool) {
33+
self.fromCache = fromCache
34+
self.updatedCache = updatedCache
35+
}
36+
}
37+
}
38+
39+
/// Delegate to notify clients about actions being performed by RegistryManager.
40+
public protocol RegistryDownloadsManagerDelegate {
41+
/// Called when a package is about to be fetched.
42+
func willFetch(package: PackageIdentity, version: Version, fetchDetails: RegistryDownloads.FetchDetails)
43+
44+
/// Called when a package has finished fetching.
45+
func didFetch(package: PackageIdentity, version: Version, result: Result<RegistryDownloads.FetchDetails, Error>, duration: DispatchTimeInterval)
46+
47+
/// Called every time the progress of a repository fetch operation updates.
48+
func fetching(package: PackageIdentity, version: Version, bytesDownloaded: Int64, totalBytesToDownload: Int64?)
49+
}
50+
51+
public protocol RegistryDownloadsManagerInterface {
52+
func lookup(
53+
package: PackageIdentity,
54+
version: Version,
55+
observabilityScope: ObservabilityScope,
56+
delegateQueue: DispatchQueue,
57+
callbackQueue: DispatchQueue,
58+
completion: @escaping (Result<AbsolutePath, Error>) -> Void
59+
)
60+
61+
func purgeCache() throws
62+
func remove(package: PackageIdentity) throws
63+
func reset() throws
64+
}
65+
66+
// MARK: - Registry client
67+
68+
public struct RegistryPackageMetadata {
69+
public let versions: [Version]
70+
public let alternateLocations: [URL]?
71+
72+
public init(versions: [Version], alternateLocations: [URL]?) {
73+
self.versions = versions
74+
self.alternateLocations = alternateLocations
75+
}
76+
}
77+
78+
public protocol RegistryClientInterface {
79+
var configured: Bool { get }
80+
81+
func cancel(deadline: DispatchTime) throws
82+
83+
func downloadSourceArchive(
84+
package: PackageIdentity,
85+
version: Version,
86+
fileSystem: FileSystem,
87+
destinationPath: AbsolutePath,
88+
checksumAlgorithm: HashAlgorithm, // the same algorithm used by `package compute-checksum` tool
89+
progressHandler: ((_ bytesReceived: Int64, _ totalBytes: Int64?) -> Void)?,
90+
timeout: DispatchTimeInterval?,
91+
observabilityScope: ObservabilityScope,
92+
callbackQueue: DispatchQueue,
93+
completion: @escaping (Result<Void, Error>) -> Void
94+
)
95+
96+
func getAvailableManifests(
97+
package: PackageIdentity,
98+
version: Version,
99+
timeout: DispatchTimeInterval?,
100+
observabilityScope: ObservabilityScope,
101+
callbackQueue: DispatchQueue,
102+
completion: @escaping (Result<[String: (toolsVersion: ToolsVersion, content: String?)], Error>) -> Void
103+
)
104+
105+
func getManifestContent(
106+
package: PackageIdentity,
107+
version: Version,
108+
customToolsVersion: ToolsVersion?,
109+
timeout: DispatchTimeInterval?,
110+
observabilityScope: ObservabilityScope,
111+
callbackQueue: DispatchQueue,
112+
completion: @escaping (Result<String, Error>) -> Void
113+
)
114+
115+
func getPackageMetadata(
116+
package: PackageIdentity,
117+
timeout: DispatchTimeInterval?,
118+
observabilityScope: ObservabilityScope,
119+
callbackQueue: DispatchQueue,
120+
completion: @escaping (Result<RegistryPackageMetadata, Error>) -> Void
121+
)
122+
123+
func lookupIdentities(
124+
url: URL,
125+
timeout: DispatchTimeInterval?,
126+
observabilityScope: ObservabilityScope,
127+
callbackQueue: DispatchQueue,
128+
completion: @escaping (Result<Set<PackageIdentity>, Error>) -> Void
129+
)
130+
}
131+
132+
public extension RegistryClientInterface {
133+
func downloadSourceArchive(
134+
package: PackageIdentity,
135+
version: Version,
136+
fileSystem: FileSystem,
137+
destinationPath: AbsolutePath,
138+
checksumAlgorithm: HashAlgorithm, // the same algorithm used by `package compute-checksum` tool
139+
progressHandler: ((_ bytesReceived: Int64, _ totalBytes: Int64?) -> Void)?,
140+
timeout: DispatchTimeInterval? = .none,
141+
observabilityScope: ObservabilityScope,
142+
callbackQueue: DispatchQueue,
143+
completion: @escaping (Result<Void, Error>) -> Void
144+
) {
145+
self.downloadSourceArchive(package: package,
146+
version: version,
147+
fileSystem: fileSystem,
148+
destinationPath: destinationPath,
149+
checksumAlgorithm: checksumAlgorithm,
150+
progressHandler: progressHandler,
151+
timeout: .none,
152+
observabilityScope: observabilityScope,
153+
callbackQueue: callbackQueue,
154+
completion: completion)
155+
}
156+
157+
func getAvailableManifests(
158+
package: PackageIdentity,
159+
version: Version,
160+
observabilityScope: ObservabilityScope,
161+
callbackQueue: DispatchQueue,
162+
completion: @escaping (Result<[String: (toolsVersion: ToolsVersion, content: String?)], Error>) -> Void
163+
) {
164+
self.getAvailableManifests(package: package,
165+
version: version,
166+
timeout: .none,
167+
observabilityScope: observabilityScope,
168+
callbackQueue: callbackQueue,
169+
completion: completion)
170+
}
171+
172+
func getManifestContent(
173+
package: PackageIdentity,
174+
version: Version,
175+
customToolsVersion: ToolsVersion?,
176+
observabilityScope: ObservabilityScope,
177+
callbackQueue: DispatchQueue,
178+
completion: @escaping (Result<String, Error>) -> Void
179+
) {
180+
self.getManifestContent(package: package,
181+
version: version,
182+
customToolsVersion: customToolsVersion,
183+
timeout: .none,
184+
observabilityScope: observabilityScope,
185+
callbackQueue: callbackQueue,
186+
completion: completion)
187+
}
188+
189+
func getPackageMetadata(
190+
package: PackageIdentity,
191+
observabilityScope: ObservabilityScope,
192+
callbackQueue: DispatchQueue,
193+
completion: @escaping (Result<RegistryPackageMetadata, Error>) -> Void
194+
) {
195+
self.getPackageMetadata(
196+
package: package,
197+
timeout: .none,
198+
observabilityScope: observabilityScope,
199+
callbackQueue: callbackQueue,
200+
completion: completion)
201+
}
202+
203+
func lookupIdentities(
204+
url: URL,
205+
observabilityScope: ObservabilityScope,
206+
callbackQueue: DispatchQueue,
207+
completion: @escaping (Result<Set<PackageIdentity>, Error>) -> Void
208+
) {
209+
self.lookupIdentities(url: url,
210+
timeout: .none,
211+
observabilityScope: observabilityScope,
212+
callbackQueue: callbackQueue,
213+
completion: completion)
214+
}
215+
}

Sources/PackageRegistry/CMakeLists.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

Sources/PackageRegistry/RegistryClient.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import Basics
1414
import Dispatch
1515
import Foundation
1616
import PackageFingerprint
17+
import PackageGraph
1718
import PackageLoading
1819
import PackageModel
1920
import TSCBasic
2021

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

2627
private let configuration: RegistryConfiguration
@@ -62,7 +63,7 @@ public final class RegistryClient: Cancellable {
6263
timeout: DispatchTimeInterval? = .none,
6364
observabilityScope: ObservabilityScope,
6465
callbackQueue: DispatchQueue,
65-
completion: @escaping (Result<PackageMetadata, Error>) -> Void
66+
completion: @escaping (Result<RegistryPackageMetadata, Error>) -> Void
6667
) {
6768
let completion = self.makeAsync(completion, on: callbackQueue)
6869

@@ -107,7 +108,7 @@ public final class RegistryClient: Cancellable {
107108

108109
let alternateLocations = try response.headers.parseAlternativeLocationLinks()
109110

110-
return PackageMetadata(
111+
return RegistryPackageMetadata(
111112
versions: versions,
112113
alternateLocations: alternateLocations?.map{ $0.url }
113114
)
@@ -657,13 +658,6 @@ fileprivate extension RegistryClient {
657658
}
658659
}
659660

660-
extension RegistryClient {
661-
public struct PackageMetadata {
662-
public let versions: [Version]
663-
public let alternateLocations: [URL]?
664-
}
665-
}
666-
667661
fileprivate extension RegistryClient {
668662
struct AlternativeLocationLink {
669663
let url: URL

0 commit comments

Comments
 (0)