Skip to content

Commit 4edaa39

Browse files
authored
reduce the use of manifest name (#3851)
motivation: manifest name is for display purposes only changes: * rename Manifest::name to Manifest::displayName to more clearly articulate the purpose * remove name attribute from Package and ResolvedPackage to make it harder to use it by mistake * rename PackageRef::name attribute to PackageRef::deprecatedName to discourage the use of it (needed for backwards compatibility) * update other call sites where its possible to use identity of name * adjust tests
1 parent 86bd1fe commit 4edaa39

File tree

50 files changed

+290
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+290
-280
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ public class BuildPlan {
20022002
var arguments = ["-I" + buildPath, "-L" + buildPath]
20032003

20042004
// Link the special REPL product that contains all of the library targets.
2005-
let replProductName = graph.rootPackages[0].manifest.name + Product.replProductSuffix
2005+
let replProductName = graph.rootPackages[0].identity.description + Product.replProductSuffix
20062006
arguments.append("-l" + replProductName)
20072007

20082008
// The graph should have the REPL product.

Sources/Commands/Describe.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import Foundation
1414

1515
/// Represents a package for the sole purpose of generating a description.
1616
struct DescribedPackage: Encodable {
17-
let name: String
17+
let name: String // for backwards compatibility
18+
let manifestDisplayName: String
1819
let path: String
1920
let toolsVersion: String
2021
let dependencies: [DescribedPackageDependency]
@@ -27,7 +28,8 @@ struct DescribedPackage: Encodable {
2728
let swiftLanguagesVersions: [String]?
2829

2930
init(from package: Package) {
30-
self.name = package.manifestName // TODO: rename property to manifestName?
31+
self.manifestDisplayName = package.manifest.displayName
32+
self.name = self.manifestDisplayName // TODO: deprecate, backwards compatibility 11/2021
3133
self.path = package.path.pathString
3234
self.toolsVersion = "\(package.manifest.toolsVersion.major).\(package.manifest.toolsVersion.minor)"
3335
+ (package.manifest.toolsVersion.patch == 0 ? "" : ".\(package.manifest.toolsVersion.patch)")

Sources/Commands/SwiftPackageTool.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ extension SwiftPackageTool {
847847
destination = output
848848
} else {
849849
let graph = try swiftTool.loadPackageGraph()
850-
let packageName = graph.rootPackages[0].manifestName // TODO: use identity instead?
850+
let packageName = graph.rootPackages[0].manifest.displayName // TODO: use identity instead?
851851
destination = packageRoot.appending(component: "\(packageName).zip")
852852
}
853853

@@ -922,10 +922,10 @@ extension SwiftPackageTool {
922922
dstdir = outpath.parentDirectory
923923
case let outpath?:
924924
dstdir = outpath
925-
projectName = graph.rootPackages[0].manifestName // TODO: use identity instead?
925+
projectName = graph.rootPackages[0].manifest.displayName // TODO: use identity instead?
926926
case _:
927927
dstdir = try swiftTool.getPackageRoot()
928-
projectName = graph.rootPackages[0].manifestName // TODO: use identity instead?
928+
projectName = graph.rootPackages[0].manifest.displayName // TODO: use identity instead?
929929
}
930930
let xcodeprojPath = Xcodeproj.buildXcodeprojPath(outputDir: dstdir, projectName: projectName)
931931

@@ -1321,11 +1321,11 @@ fileprivate func logPackageChanges(changes: [(PackageReference, Workspace.Packag
13211321
let currentVersion = pins.pinsMap[package.identity]?.state.description ?? ""
13221322
switch change {
13231323
case let .added(state):
1324-
stream <<< "+ \(package.name) \(state.requirement.prettyPrinted)"
1324+
stream <<< "+ \(package.identity) \(state.requirement.prettyPrinted)"
13251325
case let .updated(state):
1326-
stream <<< "~ \(package.name) \(currentVersion) -> \(package.name) \(state.requirement.prettyPrinted)"
1326+
stream <<< "~ \(package.identity) \(currentVersion) -> \(package.identity) \(state.requirement.prettyPrinted)"
13271327
case .removed:
1328-
stream <<< "- \(package.name) \(currentVersion)"
1328+
stream <<< "- \(package.identity) \(currentVersion)"
13291329
case .unchanged:
13301330
continue
13311331
}

Sources/Commands/SwiftTestTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public struct SwiftTestTool: SwiftCommand {
382382
// Export the codecov data as JSON.
383383
let jsonPath = codeCovAsJSONPath(
384384
buildParameters: buildParameters,
385-
packageName: rootManifest.name)
385+
packageName: rootManifest.displayName)
386386
try exportCodeCovAsJSON(to: jsonPath, testBinary: product.binaryPath, swiftTool: swiftTool)
387387
}
388388
}

Sources/Commands/show-dependencies.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ final class JSONDumper: DependenciesDumper {
114114
func dump(dependenciesOf rootpkg: ResolvedPackage, on stream: OutputByteStream) {
115115
func convert(_ package: ResolvedPackage) -> JSON {
116116
return .orderedDictionary([
117-
"name": .string(package.manifestName), // TODO: remove? add identity?
117+
"identity": .string(package.identity.description),
118+
"name": .string(package.manifest.displayName), // TODO: remove?
118119
"url": .string(package.manifest.packageLocation),
119120
"version": .string(package.manifest.version?.description ?? "unspecified"),
120121
"path": .string(package.path.pathString),

Sources/PackageGraph/DependencyResolutionNode.swift

Lines changed: 5 additions & 5 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-
package: package,
98+
package: self.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-
package: package,
111+
package: self.package,
112112
requirement: .revision(revision),
113113
products: .specific([])
114114
)
@@ -123,13 +123,13 @@ extension DependencyResolutionNode: Equatable {
123123

124124
extension DependencyResolutionNode: Hashable {
125125
public func hash(into hasher: inout Hasher) {
126-
hasher.combine(package)
127-
hasher.combine(specificProduct)
126+
hasher.combine(self.package)
127+
hasher.combine(self.specificProduct)
128128
}
129129
}
130130

131131
extension DependencyResolutionNode: CustomStringConvertible {
132132
public var description: String {
133-
return "\(package.name)\(productFilter)"
133+
return "\(self.package.identity)\(self.productFilter)"
134134
}
135135
}

Sources/PackageGraph/GraphLoadingNode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ extension GraphLoadingNode: CustomStringConvertible {
4444
public var description: String {
4545
switch productFilter {
4646
case .everything:
47-
return self.manifest.name
47+
return self.identity.description
4848
case .specific(let set):
49-
return "\(self.manifest.name)[\(set.sorted().joined(separator: ", "))]"
49+
return "\(self.identity.description)[\(set.sorted().joined(separator: ", "))]"
5050
}
5151
}
5252
}

Sources/PackageGraph/PackageContainer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public protocol PackageContainer {
9090
/// This can be used by the containers to fill in the missing information that is obtained
9191
/// after the container is available. The updated identifier is returned in result of the
9292
/// dependency resolution.
93-
func getUpdatedIdentifier(at boundVersion: BoundVersion) throws -> PackageReference
93+
func loadPackageReference(at boundVersion: BoundVersion) throws -> PackageReference
9494
}
9595

9696
extension PackageContainer {

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private func createResolvedPackages(
279279
// backwards compatibility with older versions of SwiftPM that had too weak of a validation
280280
// we will upgrade this to an error in a few versions to tighten up the validation
281281
if dependency.explicitNameForTargetDependencyResolutionOnly == .none ||
282-
resolvedPackage.package.manifestName == dependency.explicitNameForTargetDependencyResolutionOnly {
282+
resolvedPackage.package.manifest.displayName == dependency.explicitNameForTargetDependencyResolutionOnly {
283283
packageObservabilityScope.emit(warning: error.description + ". this will be escalated to an error in future versions of SwiftPM.")
284284
} else {
285285
return packageObservabilityScope.emit(error)

Sources/PackageGraph/PackageGraph.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ extension PackageGraphError: CustomStringConvertible {
187187

188188
case .cycleDetected(let cycle):
189189
return "cyclic dependency declaration found: " +
190-
(cycle.path + cycle.cycle).map({ $0.name }).joined(separator: " -> ") +
191-
" -> " + cycle.cycle[0].name
190+
(cycle.path + cycle.cycle).map({ $0.displayName }).joined(separator: " -> ") +
191+
" -> " + cycle.cycle[0].displayName
192192

193193
case .productDependencyNotFound(let package, let targetName, let dependencyProductName, let dependencyPackageName, let dependencyProductInDecl):
194194
if dependencyProductInDecl {

Sources/PackageGraph/PinsStore.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fileprivate struct PinsStorage {
129129
let v1 = try decoder.decode(path: self.path, fileSystem: self.fileSystem, as: V1.self)
130130
return try v1.object.pins.map{ try PinsStore.Pin($0, mirrors: mirrors) }.reduce(into: [PackageIdentity: PinsStore.Pin]()) { partial, iterator in
131131
if partial.keys.contains(iterator.packageRef.identity) {
132-
throw StringError("duplicated entry for package \"\(iterator.packageRef.name)\"")
132+
throw StringError("duplicated entry for package \"\(iterator.packageRef.identity)\"")
133133
}
134134
partial[iterator.packageRef.identity] = iterator
135135
}
@@ -234,7 +234,7 @@ fileprivate struct PinsStorage {
234234
throw StringError("invalid package type \(pin.packageRef.kind)")
235235
}
236236

237-
self.package = pin.packageRef.name
237+
self.package = pin.packageRef.deprecatedName
238238
// rdar://52529014, rdar://52529011: pin file should store the original location but remap when loading
239239
self.repositoryURL = mirrors.originalURL(for: location) ?? location
240240
self.state = .init(pin.state)
@@ -328,7 +328,7 @@ extension PinsStore.Pin {
328328
throw StringError("invalid package location \(location)")
329329
}
330330
if let newName = pin.package {
331-
packageRef = packageRef.with(newName: newName)
331+
packageRef = packageRef.withName(newName)
332332
}
333333
self.init(
334334
packageRef: packageRef,

Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,18 @@ public struct PubgrubDependencyResolver {
215215

216216
// TODO: replace with async/await when available
217217
let container = try temp_await { provider.getContainer(for: assignment.term.node.package, completion: $0) }
218-
let identifier = try container.underlying.getUpdatedIdentifier(at: boundVersion)
218+
let updatePackage = try container.underlying.loadPackageReference(at: boundVersion)
219219

220-
if var existing = flattenedAssignments[identifier] {
220+
if var existing = flattenedAssignments[updatePackage] {
221221
assert(existing.binding == boundVersion, "Two products in one package resolved to different versions: \(existing.products)@\(existing.binding) vs \(products)@\(boundVersion)")
222222
existing.products.formUnion(products)
223-
flattenedAssignments[identifier] = existing
223+
flattenedAssignments[updatePackage] = existing
224224
} else {
225-
flattenedAssignments[identifier] = (binding: boundVersion, products: products)
225+
flattenedAssignments[updatePackage] = (binding: boundVersion, products: products)
226226
}
227227
}
228228
var finalAssignments: [DependencyResolver.Binding]
229-
= flattenedAssignments.keys.sorted(by: { $0.name < $1.name }).map { package in
229+
= flattenedAssignments.keys.sorted(by: { $0.deprecatedName < $1.deprecatedName }).map { package in
230230
let details = flattenedAssignments[package]!
231231
return (package: package, binding: details.binding, products: details.products)
232232
}
@@ -235,8 +235,8 @@ public struct PubgrubDependencyResolver {
235235
for (package, override) in state.overriddenPackages {
236236
// TODO: replace with async/await when available
237237
let container = try temp_await { provider.getContainer(for: package, completion: $0) }
238-
let identifier = try container.underlying.getUpdatedIdentifier(at: override.version)
239-
finalAssignments.append((identifier, override.version, override.products))
238+
let updatePackage = try container.underlying.loadPackageReference(at: override.version)
239+
finalAssignments.append((updatePackage, override.version, override.products))
240240
}
241241

242242
self.delegate?.solved(result: finalAssignments)
@@ -376,8 +376,8 @@ public struct PubgrubDependencyResolver {
376376
constraints.append(dependency)
377377
case .unversioned:
378378
throw DependencyResolverError.revisionDependencyContainsLocalPackage(
379-
dependency: package.name,
380-
localPackage: dependency.package.name
379+
dependency: package.identity.description,
380+
localPackage: dependency.package.identity.description
381381
)
382382
}
383383
}
@@ -1329,7 +1329,7 @@ private final class PubGrubPackageContainer {
13291329
let versions: [Version] = try self.underlying.versionsAscending()
13301330

13311331
guard let idx = versions.firstIndex(of: firstVersion) else {
1332-
throw InternalError("from version \(firstVersion) not found in \(node.package.name)")
1332+
throw InternalError("from version \(firstVersion) not found in \(node.package.identity)")
13331333
}
13341334

13351335
let sync = DispatchGroup()
@@ -1347,7 +1347,7 @@ private final class PubGrubPackageContainer {
13471347
// timeout is a function of # of versions since we need to make several git operations per tag/version
13481348
let timeout = DispatchTimeInterval.seconds(60 + versions.count)
13491349
guard case .success = sync.wait(timeout: .now() + timeout) else {
1350-
throw StringError("timeout computing '\(node.package.name)' bounds")
1350+
throw StringError("timeout computing '\(node.package.identity)' bounds")
13511351
}
13521352

13531353
return (lowerBounds, upperBounds)
@@ -1386,7 +1386,7 @@ private final class ContainerProvider {
13861386
/// Get a cached container for the given identifier, asserting / throwing if not found.
13871387
func getCachedContainer(for package: PackageReference) throws -> PubGrubPackageContainer {
13881388
guard let container = self.containersCache[package] else {
1389-
throw InternalError("container for \(package.name) expected to be cached")
1389+
throw InternalError("container for \(package.identity) expected to be cached")
13901390
}
13911391
return container
13921392
}
@@ -1531,6 +1531,6 @@ private extension PackageRequirement {
15311531

15321532
private extension DependencyResolutionNode {
15331533
var nameForDiagnostics: String {
1534-
return "'\(package.name)'"
1534+
return "'\(package.identity)'"
15351535
}
15361536
}

Sources/PackageGraph/ResolvedPackage.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ public final class ResolvedPackage {
2626
return self.underlyingPackage.manifest
2727
}
2828

29-
/// The name of the package.
30-
@available(*, deprecated, message: "use identity (or manifestName, but only if you must) instead")
31-
public var name: String {
32-
return self.underlyingPackage.name
33-
}
34-
35-
/// The name of the package as entered in the manifest.
36-
/// This should rarely be used beyond presentation purposes
37-
//@available(*, deprecated)
38-
public var manifestName: String {
39-
return self.underlyingPackage.manifestName
40-
}
41-
4229
/// The local path of the package.
4330
public var path: AbsolutePath {
4431
return self.underlyingPackage.path

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
274274
}
275275

276276
let manifest = Manifest(
277-
name: parsedManifest.name,
277+
displayName: parsedManifest.name,
278278
path: path,
279279
packageKind: packageKind,
280280
packageLocation: packageLocation,

0 commit comments

Comments
 (0)