Skip to content

Commit c313dea

Browse files
authored
integrate registry dependencies into dependency resolution (#3873)
motivation: support registries changes: * create RegistryPackageContainer to handle dependencies from registry, integrated with the previously introduces registry client * update workspace to create RegistryPackageContainer when dealing with registry dependencies * update registry client (RegitryManager) to perform download request (buffered) when downloading the package archive * update registry client manifest listing and handling so it supportes multi-manifest setups. simplified the client to return the manifest content instead of attempting to load it which is done in RegistryPackageContainer which has additional context * update registry client to use Codable * add testing infrastructure to MockWorkspace to mock registry dependencies * add basic tests for regsitry scenarios
1 parent 8516cb5 commit c313dea

18 files changed

+1659
-447
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ let package = Package(
381381
"Basics",
382382
"PackageGraph",
383383
"PackageLoading",
384+
"PackageRegistry",
384385
"SourceControl",
385386
.product(name: "TSCTestSupport", package: "swift-tools-support-core"),
386387
"Workspace",

Sources/Basics/HTTPClient.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,11 @@ public struct HTTPClientResponse {
387387

388388
extension HTTPClientResponse {
389389
public static func okay(body: String? = nil) -> HTTPClientResponse {
390-
return HTTPClientResponse(statusCode: 200, body: body?.data(using: .utf8))
390+
return .okay(body: body?.data(using: .utf8))
391+
}
392+
393+
public static func okay(body: Data?) -> HTTPClientResponse {
394+
return HTTPClientResponse(statusCode: 200, body: body)
391395
}
392396

393397
public static func notFound(reason: String? = nil) -> HTTPClientResponse {

Sources/Commands/SwiftPackageRegistryTool.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
8484
var url: String
8585

8686
func run(_ swiftTool: SwiftTool) throws {
87-
guard let url = URL(string: self.url),
88-
url.scheme == "https"
89-
else {
87+
guard let url = URL(string: self.url), url.scheme == "https" else {
9088
throw RegistryConfigurationError.invalidURL(self.url)
9189
}
9290

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ private func createResolvedPackages(
247247
case .remote(let url):
248248
dependencyLocation = url.absoluteString
249249
}
250-
case .registry:
251-
// FIXME
252-
fatalError("registry based dependencies not implemented yet")
250+
case .registry(let settings):
251+
dependencyLocation = settings.identity.description
253252
}
254253

255254
// Otherwise, look it up by its identity.

Sources/PackageLoading/ToolsVersionLoader.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,13 @@ public struct ToolsVersionLoader: ToolsVersionLoaderProtocol {
353353
guard let manifestContentsDecodedWithUTF8 = manifestContents.validDescription else {
354354
throw Error.nonUTF8EncodedManifest(path: file)
355355
}
356-
356+
357+
return try self.load(utf8String: manifestContentsDecodedWithUTF8)
358+
}
359+
360+
public func load(utf8String: String) throws -> ToolsVersion {
357361
/// The manifest represented in its constituent parts.
358-
let manifestComponents = ToolsVersionLoader.split(manifestContentsDecodedWithUTF8)
362+
let manifestComponents = ToolsVersionLoader.split(utf8String)
359363
/// The Swift tools version specification represented in its constituent parts.
360364
let toolsVersionSpecificationComponents = manifestComponents.toolsVersionSpecificationComponents
361365

Sources/PackageModel/PackageIdentity.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ public struct PackageIdentity: CustomStringConvertible {
6565
}
6666

6767
// TODO: formalize package registry identifier
68-
public var scopeAndName: (Scope, Name)? {
68+
public var scopeAndName: (scope: Scope, name: Name)? {
6969
let components = description.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: true)
7070
guard components.count == 2,
7171
let scope = Scope(components.first),
7272
let name = Name(components.last)
73-
else { return nil }
73+
else { return .none }
7474

75-
return (scope, name)
75+
return (scope: scope, name: name)
7676
}
7777
}
7878

Sources/PackageRegistry/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
add_library(PackageRegistry
1010
Registry.swift
1111
RegistryConfiguration.swift
12-
RegistryManager.swift
12+
RegistryClient.swift
1313
SourceArchiver.swift)
1414
target_link_libraries(PackageRegistry PUBLIC
1515
Basics

0 commit comments

Comments
 (0)