Skip to content

Commit ca6fab3

Browse files
committed
api cleanup in preperation for identity improvments
motivation: infrastructure towards improve correctness by using identity more broadly throughout the code changes: * rename PackageReference::path to PackageReference::location * make PackageReference kinf explicitly set by the callsite with no default * rename PackageContainerConstraint::identifier to PackageContainerConstraint::package * rename PackageContainer::identifier to PackageContainer::package * adjust tests
1 parent e153053 commit ca6fab3

28 files changed

+310
-321
lines changed

Sources/Commands/SwiftPackageCollectionsTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
221221

222222
mutating func run() throws {
223223
let identity = PackageIdentity(url: packageUrl)
224-
let reference = PackageReference(identity: identity, path: packageUrl)
224+
let reference = PackageReference.remote(identity: identity, location: packageUrl)
225225

226226
do { // assume URL is for a package
227227
let result = try with { collections in

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private class ToolWorkspaceDelegate: WorkspaceDelegate {
138138
case .forced:
139139
self.stdoutStream <<< "it was forced"
140140
case .newPackages(let packages):
141-
let dependencies = packages.lazy.map({ "'\($0.path)'" }).joined(separator: ", ")
141+
let dependencies = packages.lazy.map({ "'\($0.location)'" }).joined(separator: ", ")
142142
self.stdoutStream <<< "the following dependencies were added: \(dependencies)"
143143
case .packageRequirementChange(let package, let state, let requirement):
144144
self.stdoutStream <<< "dependency '\(package.name)' was "

Sources/PackageCollections/Providers/GitHubPackageMetadataProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider {
3838
guard reference.kind == .remote else {
3939
return callback(.failure(Errors.invalidReferenceType(reference)))
4040
}
41-
guard let baseURL = self.apiURL(reference.path) else {
42-
return callback(.failure(Errors.invalidGitURL(reference.path)))
41+
guard let baseURL = self.apiURL(reference.location) else {
42+
return callback(.failure(Errors.invalidGitURL(reference.location)))
4343
}
4444

4545
let metadataURL = baseURL

Sources/PackageCollections/Utility.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ extension PackageReference {
5454
init(repository: RepositorySpecifier, kind: PackageReference.Kind = .remote) {
5555
self.init(
5656
identity: PackageIdentity(url: repository.url),
57-
path: repository.url,
58-
kind: kind
57+
kind: kind,
58+
location: repository.url
5959
)
6060
}
6161
}

Sources/PackageGraph/DependencyResolutionNode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public enum DependencyResolutionNode {
9595
// Don’t create a version lock for anything but a product.
9696
guard specificProduct != nil else { return nil }
9797
return PackageContainerConstraint(
98-
container: package,
98+
package: package,
9999
versionRequirement: .exact(version),
100100
products: .specific([])
101101
)
@@ -108,7 +108,7 @@ public enum DependencyResolutionNode {
108108
// Don’t create a revision lock for anything but a product.
109109
guard specificProduct != nil else { return nil }
110110
return PackageContainerConstraint(
111-
container: package,
111+
package: package,
112112
requirement: .revision(revision),
113113
products: .specific([])
114114
)

Sources/PackageGraph/LocalPackageContainer.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ import TSCUtility
2424
/// should be used as-is. Infact, they might not even have a git repository.
2525
/// Examples: Root packages, local dependencies, edited packages.
2626
public final class LocalPackageContainer: PackageContainer {
27-
public let identifier: PackageReference
27+
public let package: PackageReference
2828
private let mirrors: DependencyMirrors
2929
private let manifestLoader: ManifestLoaderProtocol
3030
private let toolsVersionLoader: ToolsVersionLoaderProtocol
3131
private let currentToolsVersion: ToolsVersion
3232

3333
/// The file system that shoud be used to load this package.
34-
private let fs: FileSystem
34+
private let fileSystem: FileSystem
3535

3636
/// cached version of the manifest
3737
private let manifest = ThreadSafeBox<Manifest>()
3838

3939
private func loadManifest() throws -> Manifest {
4040
try manifest.memoize() {
4141
// Load the tools version.
42-
let toolsVersion = try toolsVersionLoader.load(at: AbsolutePath(identifier.path), fileSystem: fs)
42+
let toolsVersion = try toolsVersionLoader.load(at: AbsolutePath(package.location), fileSystem: fileSystem)
4343

4444
// Validate the tools version.
45-
try toolsVersion.validateToolsVersion(self.currentToolsVersion, packagePath: identifier.path)
45+
try toolsVersion.validateToolsVersion(self.currentToolsVersion, packagePath: package.location)
4646

4747
// Load the manifest.
4848
// FIXME: this should not block
4949
return try temp_await {
50-
manifestLoader.load(package: AbsolutePath(identifier.path),
51-
baseURL: identifier.path,
50+
manifestLoader.load(package: AbsolutePath(package.location),
51+
baseURL: package.location,
5252
version: nil,
5353
toolsVersion: toolsVersion,
54-
packageKind: identifier.kind,
55-
fileSystem: fs,
54+
packageKind: package.kind,
55+
fileSystem: fileSystem,
5656
on: .global(),
5757
completion: $0)
5858
}
@@ -66,24 +66,24 @@ public final class LocalPackageContainer: PackageContainer {
6666
public func getUpdatedIdentifier(at boundVersion: BoundVersion) throws -> PackageReference {
6767
assert(boundVersion == .unversioned, "Unexpected bound version \(boundVersion)")
6868
let manifest = try loadManifest()
69-
return identifier.with(newName: manifest.name)
69+
return package.with(newName: manifest.name)
7070
}
7171

7272
public init(
73-
_ identifier: PackageReference,
73+
package: PackageReference,
7474
mirrors: DependencyMirrors,
7575
manifestLoader: ManifestLoaderProtocol,
7676
toolsVersionLoader: ToolsVersionLoaderProtocol,
7777
currentToolsVersion: ToolsVersion,
78-
fs: FileSystem = localFileSystem
78+
fileSystem: FileSystem = localFileSystem
7979
) {
80-
assert(URL.scheme(identifier.path) == nil, "unexpected scheme \(URL.scheme(identifier.path)!) in \(identifier.path)")
81-
self.identifier = identifier
80+
assert(URL.scheme(package.location) == nil, "unexpected scheme \(URL.scheme(package.location)!) in \(package.location)")
81+
self.package = package
8282
self.mirrors = mirrors
8383
self.manifestLoader = manifestLoader
8484
self.toolsVersionLoader = toolsVersionLoader
8585
self.currentToolsVersion = currentToolsVersion
86-
self.fs = fs
86+
self.fileSystem = fileSystem
8787
}
8888

8989
public func isToolsVersionCompatible(at version: Version) -> Bool {
@@ -113,6 +113,6 @@ public final class LocalPackageContainer: PackageContainer {
113113

114114
extension LocalPackageContainer: CustomStringConvertible {
115115
public var description: String {
116-
return "LocalPackageContainer(\(identifier.path))"
116+
return "LocalPackageContainer(\(package.location))"
117117
}
118118
}

Sources/PackageGraph/PackageContainer.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import struct TSCUtility.Version
3636
public protocol PackageContainer {
3737

3838
/// The identifier for the package.
39-
var identifier: PackageReference { get }
39+
var package: PackageReference { get }
4040

4141
/// Returns true if the tools version is compatible at the given version.
4242
func isToolsVersionCompatible(at version: Version) -> Bool
@@ -116,7 +116,7 @@ extension PackageContainer {
116116
public struct PackageContainerConstraint: Equatable, Hashable {
117117

118118
/// The identifier for the container the constraint is on.
119-
public let identifier: PackageReference
119+
public let package: PackageReference
120120

121121
/// The constraint requirement.
122122
public let requirement: PackageRequirement
@@ -126,22 +126,22 @@ public struct PackageContainerConstraint: Equatable, Hashable {
126126

127127
/// Create a constraint requiring the given `container` satisfying the
128128
/// `requirement`.
129-
public init(container identifier: PackageReference, requirement: PackageRequirement, products: ProductFilter) {
130-
self.identifier = identifier
129+
public init(package: PackageReference, requirement: PackageRequirement, products: ProductFilter) {
130+
self.package = package
131131
self.requirement = requirement
132132
self.products = products
133133
}
134134

135135
/// Create a constraint requiring the given `container` satisfying the
136136
/// `versionRequirement`.
137-
public init(container identifier: PackageReference, versionRequirement: VersionSetSpecifier, products: ProductFilter) {
138-
self.init(container: identifier, requirement: .versionSet(versionRequirement), products: products)
137+
public init(package: PackageReference, versionRequirement: VersionSetSpecifier, products: ProductFilter) {
138+
self.init(package: package, requirement: .versionSet(versionRequirement), products: products)
139139
}
140140
}
141141

142142
extension PackageContainerConstraint: CustomStringConvertible {
143143
public var description: String {
144-
return "Constraint(\(identifier), \(requirement), \(products)"
144+
return "Constraint(\(self.package), \(requirement), \(products)"
145145
}
146146
}
147147

@@ -151,7 +151,7 @@ extension PackageContainerConstraint: CustomStringConvertible {
151151
public protocol PackageContainerProvider {
152152
/// Get the container for a particular identifier asynchronously.
153153
func getContainer(
154-
for identifier: PackageReference,
154+
for package: PackageReference,
155155
skipUpdate: Bool,
156156
on queue: DispatchQueue,
157157
completion: @escaping (Result<PackageContainer, Swift.Error>) -> Void

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private func createResolvedPackages(
201201
guard let package = manifestToPackage[node.manifest] else {
202202
return nil
203203
}
204-
let isAllowedToVendUnsafeProducts = unsafeAllowedPackages.contains{ $0.path == package.manifest.url }
204+
let isAllowedToVendUnsafeProducts = unsafeAllowedPackages.contains{ $0.location == package.manifest.url }
205205
return ResolvedPackageBuilder(
206206
package,
207207
productFilter: node.productFilter,

Sources/PackageGraph/PackageGraphRoot.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public struct PackageGraphRoot {
4949
public init(input: PackageGraphRootInput, manifests: [Manifest], explicitProduct: String? = nil) {
5050
self.packageRefs = zip(input.packages, manifests).map { (path, manifest) in
5151
let identity = PackageIdentity(url: manifest.url)
52-
return PackageReference(identity: identity, path: path.pathString, kind: .root)
52+
return .root(identity: identity, path: path)
5353
}
5454
self.manifests = manifests
5555

@@ -73,11 +73,11 @@ public struct PackageGraphRoot {
7373
/// Returns the constraints imposed by root manifests + dependencies.
7474
public func constraints(mirrors: DependencyMirrors) -> [PackageContainerConstraint] {
7575
let constraints = packageRefs.map({
76-
PackageContainerConstraint(container: $0, requirement: .unversioned, products: .everything)
76+
PackageContainerConstraint(package: $0, requirement: .unversioned, products: .everything)
7777
})
7878
return constraints + dependencies.map({
7979
PackageContainerConstraint(
80-
container: $0.createPackageRef(mirrors: mirrors),
80+
package: $0.createPackageRef(mirrors: mirrors),
8181
requirement: $0.requirement.toConstraintRequirement(),
8282
products: $0.productFilter
8383
)

Sources/PackageGraph/PackageModel+Extensions.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ extension PackageDependencyDescription {
2727

2828
return PackageReference(
2929
identity: identity,
30-
path: effectiveURL,
31-
kind: requirement == .localPackage ? .local : .remote
30+
kind: requirement == .localPackage ? .local : .remote,
31+
location: effectiveURL
3232
)
3333
}
3434
}
@@ -38,7 +38,7 @@ extension Manifest {
3838
public func dependencyConstraints(productFilter: ProductFilter, mirrors: DependencyMirrors) -> [PackageContainerConstraint] {
3939
return dependenciesRequired(for: productFilter).map({
4040
return PackageContainerConstraint(
41-
container: $0.createPackageRef(mirrors: mirrors),
41+
package: $0.createPackageRef(mirrors: mirrors),
4242
requirement: $0.requirement.toConstraintRequirement(),
4343
products: $0.productFilter)
4444
})
@@ -49,17 +49,17 @@ extension PackageContainerConstraint {
4949
internal func nodes() -> [DependencyResolutionNode] {
5050
switch products {
5151
case .everything:
52-
return [.root(package: identifier)]
52+
return [.root(package: self.package)]
5353
case .specific:
5454
switch products {
5555
case .everything:
5656
assertionFailure("Attempted to enumerate a root package’s product filter; root packages have no filter.")
5757
return []
5858
case .specific(let set):
5959
if set.isEmpty { // Pointing at the package without a particular product.
60-
return [.empty(package: identifier)]
60+
return [.empty(package: self.package)]
6161
} else {
62-
return set.sorted().map { .product($0, package: identifier) }
62+
return set.sorted().map { .product($0, package: self.package) }
6363
}
6464
}
6565
}
@@ -72,6 +72,6 @@ extension PackageReference {
7272
/// This should only be accessed when the reference is not local.
7373
public var repository: RepositorySpecifier {
7474
precondition(kind == .remote)
75-
return RepositorySpecifier(url: path)
75+
return RepositorySpecifier(url: self.location)
7676
}
7777
}

Sources/PackageGraph/PinsStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension PinsStore.Pin: JSONMappable, JSONSerializable {
136136
let name: String? = json.get("package")
137137
let url: String = try json.get("repositoryURL")
138138
let identity = PackageIdentity(url: url)
139-
let ref = PackageReference(identity: identity, path: url)
139+
let ref = PackageReference.remote(identity: identity, location: url)
140140
self.packageRef = name.flatMap(ref.with(newName:)) ?? ref
141141
self.state = try json.get("state")
142142
}
@@ -145,7 +145,7 @@ extension PinsStore.Pin: JSONMappable, JSONSerializable {
145145
public func toJSON() -> JSON {
146146
return .init([
147147
"package": packageRef.name.toJSON(),
148-
"repositoryURL": packageRef.path,
148+
"repositoryURL": packageRef.location,
149149
"state": state
150150
])
151151
}

0 commit comments

Comments
 (0)