Skip to content

Commit d291a81

Browse files
committed
adjust to registry client changes
1 parent 7564567 commit d291a81

File tree

3 files changed

+290
-190
lines changed

3 files changed

+290
-190
lines changed

Sources/PackageRegistry/RegistryManager.swift

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public final class RegistryManager {
5858
}
5959

6060
public func fetchVersions(
61-
of package: PackageIdentity,
62-
timeout: DispatchTimeInterval? = nil,
63-
callbackQueue: DispatchQueue = .sharedConcurrent,
61+
package: PackageIdentity,
62+
timeout: DispatchTimeInterval? = .none,
6463
observabilityScope: ObservabilityScope,
64+
callbackQueue: DispatchQueue,
6565
completion: @escaping (Result<[Version], Error>) -> Void
6666
) {
6767
let completion = self.makeAsync(completion, on: callbackQueue)
@@ -112,14 +112,13 @@ public final class RegistryManager {
112112
}
113113

114114
public func fetchManifest(
115-
for version: Version,
116-
of package: PackageIdentity,
117-
using manifestLoader: ManifestLoaderProtocol,
118-
toolsVersion: ToolsVersion = .currentToolsVersion,
119-
swiftLanguageVersion: SwiftLanguageVersion? = nil,
120-
timeout: DispatchTimeInterval? = nil,
121-
callbackQueue: DispatchQueue = .sharedConcurrent,
115+
package: PackageIdentity,
116+
version: Version,
117+
manifestLoader: ManifestLoaderProtocol,
118+
toolsVersion: ToolsVersion?,
119+
timeout: DispatchTimeInterval? = .none,
122120
observabilityScope: ObservabilityScope,
121+
callbackQueue: DispatchQueue,
123122
completion: @escaping (Result<Manifest, Error>) -> Void
124123
) {
125124
let completion = self.makeAsync(completion, on: callbackQueue)
@@ -135,9 +134,9 @@ public final class RegistryManager {
135134
var components = URLComponents(url: registry.url, resolvingAgainstBaseURL: true)
136135
components?.appendPathComponents("\(scope)", "\(name)", "\(version)", "Package.swift")
137136

138-
if let swiftLanguageVersion = swiftLanguageVersion {
137+
if let toolsVersion = toolsVersion {
139138
components?.queryItems = [
140-
URLQueryItem(name: "swift-version", value: swiftLanguageVersion.rawValue),
139+
URLQueryItem(name: "swift-version", value: toolsVersion.description),
141140
]
142141
}
143142

@@ -169,8 +168,8 @@ public final class RegistryManager {
169168
let fileSystem = InMemoryFileSystem()
170169

171170
let filename: String
172-
if let swiftLanguageVersion = swiftLanguageVersion {
173-
filename = Manifest.basename + "@swift-\(swiftLanguageVersion).swift"
171+
if let toolsVersion = toolsVersion {
172+
filename = Manifest.basename + "@swift-\(toolsVersion).swift"
174173
} else {
175174
filename = Manifest.basename + ".swift"
176175
}
@@ -185,7 +184,7 @@ public final class RegistryManager {
185184
packageLocation: package.description, // FIXME: was originally PackageReference.locationString
186185
version: version,
187186
revision: nil,
188-
toolsVersion: .currentToolsVersion,
187+
toolsVersion: toolsVersion ?? .currentToolsVersion,
189188
identityResolver: self.identityResolver,
190189
fileSystem: fileSystem,
191190
observabilityScope: observabilityScope,
@@ -202,11 +201,11 @@ public final class RegistryManager {
202201
}
203202

204203
public func fetchSourceArchiveChecksum(
205-
for version: Version,
206-
of package: PackageIdentity,
207-
timeout: DispatchTimeInterval? = nil,
208-
callbackQueue: DispatchQueue = .sharedConcurrent,
204+
package: PackageIdentity,
205+
version: Version,
206+
timeout: DispatchTimeInterval? = .none,
209207
observabilityScope: ObservabilityScope,
208+
callbackQueue: DispatchQueue,
210209
completion: @escaping (Result<String, Error>) -> Void
211210
) {
212211
let completion = self.makeAsync(completion, on: callbackQueue)
@@ -262,15 +261,15 @@ public final class RegistryManager {
262261
}
263262

264263
public func downloadSourceArchive(
265-
for version: Version,
266-
of package: PackageIdentity,
267-
into fileSystem: FileSystem,
268-
at destinationPath: AbsolutePath,
269-
expectedChecksum: String? = nil, // previously recorded checksum, if any
264+
package: PackageIdentity,
265+
version: Version,
266+
fileSystem: FileSystem,
267+
destinationPath: AbsolutePath,
268+
expectedChecksum: String?, // previously recorded checksum, if any
270269
checksumAlgorithm: HashAlgorithm, // the same algorithm used by `package compute-checksum` tool
271-
timeout: DispatchTimeInterval? = nil,
272-
callbackQueue: DispatchQueue = .sharedConcurrent,
270+
timeout: DispatchTimeInterval? = .none,
273271
observabilityScope: ObservabilityScope,
272+
callbackQueue: DispatchQueue,
274273
completion: @escaping (Result<Void, Error>) -> Void
275274
) {
276275
let completion = self.makeAsync(completion, on: callbackQueue)
@@ -288,7 +287,13 @@ public final class RegistryManager {
288287
if let expectedChecksum = expectedChecksum {
289288
return body(.success(expectedChecksum))
290289
}
291-
self.fetchSourceArchiveChecksum(for: version, of: package, callbackQueue: callbackQueue, observabilityScope: observabilityScope, completion: body)
290+
self.fetchSourceArchiveChecksum(
291+
package: package,
292+
version: version,
293+
observabilityScope: observabilityScope,
294+
callbackQueue: callbackQueue,
295+
completion: body
296+
)
292297
}
293298

294299
var components = URLComponents(url: registry.url, resolvingAgainstBaseURL: true)
@@ -358,10 +363,10 @@ public final class RegistryManager {
358363
}
359364

360365
public func lookupIdentities(
361-
for url: Foundation.URL,
362-
timeout: DispatchTimeInterval? = nil,
363-
callbackQueue: DispatchQueue = .sharedConcurrent,
366+
url: Foundation.URL,
367+
timeout: DispatchTimeInterval? = .none,
364368
observabilityScope: ObservabilityScope,
369+
callbackQueue: DispatchQueue,
365370
completion: @escaping (Result<Set<PackageIdentity>, Error>) -> Void
366371
) {
367372
let completion = self.makeAsync(completion, on: callbackQueue)

Sources/Workspace/Workspace.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,21 +3342,26 @@ extension Workspace {
33423342
}
33433343

33443344
let downloadPath = self.location.registryDownloadDirectory.appending(components: package.identity.description, version.description)
3345-
if !self.fileSystem.exists(downloadPath) {
3346-
_ = try temp_await {
3347-
registryManager.downloadSourceArchive(
3348-
for: version,
3349-
of: package,
3350-
into: self.fileSystem,
3351-
at: downloadPath,
3352-
observabilityScope: observabilityScope,
3353-
on: .sharedConcurrent,
3354-
completion: $0
3355-
)
3356-
}
3357-
// TODO: make download read-only?
3345+
if self.fileSystem.exists(downloadPath) {
3346+
return downloadPath
33583347
}
33593348

3349+
try temp_await {
3350+
registryManager.downloadSourceArchive(
3351+
package: package.identity,
3352+
version: version,
3353+
fileSystem: self.fileSystem,
3354+
destinationPath: downloadPath,
3355+
expectedChecksum: nil, // we dont know at this point
3356+
checksumAlgorithm: self.checksumAlgorithm,
3357+
observabilityScope: observabilityScope,
3358+
callbackQueue: .sharedConcurrent,
3359+
completion: $0
3360+
)
3361+
}
3362+
3363+
// TODO: make download read-only?
3364+
33603365
self.state.dependencies.add(
33613366
try .registry(
33623367
packageRef: package,

0 commit comments

Comments
 (0)