Skip to content

Commit 8e8f285

Browse files
committed
Only resolve dependencies that are visible from the root package
1 parent 2073e2f commit 8e8f285

Some content is hidden

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

42 files changed

+888
-235
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ let package = Package(
236236
dependencies: ["PackageLoading", "SPMTestSupport"]),
237237
.testTarget(
238238
name: "PackageModelTests",
239-
dependencies: ["PackageModel"]),
239+
dependencies: ["PackageModel", "SPMTestSupport"]),
240240
.testTarget(
241241
name: "PackageGraphTests",
242242
dependencies: ["PackageGraph", "SPMTestSupport"]),

Sources/Commands/SwiftPackageTool.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
112112
let builder = PackageBuilder(
113113
manifest: manifest,
114114
path: try getPackageRoot(),
115-
diagnostics: diagnostics,
116-
isRootPackage: true
115+
diagnostics: diagnostics
117116
)
118117
let package = try builder.construct()
119118

@@ -337,8 +336,7 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
337336
let builder = PackageBuilder(
338337
manifest: manifest,
339338
path: try getPackageRoot(),
340-
diagnostics: diagnostics,
341-
isRootPackage: true
339+
diagnostics: diagnostics
342340
)
343341
let package = try builder.construct()
344342
describe(package, in: options.describeMode, on: stdoutStream)
@@ -823,15 +821,14 @@ fileprivate extension SwiftPackageTool {
823821
stream <<< "\n"
824822

825823
for (package, change) in changes {
826-
guard let packageName = package.name else { continue }
827824
let currentVersion = pins.pinsMap[package.identity]?.state.description ?? ""
828825
switch change {
829826
case let .added(requirement):
830-
stream <<< "+ \(packageName) \(requirement.prettyPrinted)"
827+
stream <<< "+ \(package.name) \(requirement.prettyPrinted)"
831828
case let .updated(requirement):
832-
stream <<< "~ \(packageName) \(currentVersion) -> \(packageName) \(requirement.prettyPrinted)"
829+
stream <<< "~ \(package.name) \(currentVersion) -> \(package.name) \(requirement.prettyPrinted)"
833830
case .removed:
834-
stream <<< "- \(packageName) \(currentVersion)"
831+
stream <<< "- \(package.name) \(currentVersion)"
835832
case .unchanged:
836833
continue
837834
}

Sources/PackageGraph/DependencyResolver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,8 @@ public class DependencyResolver {
10091009
let incompatibleConstraints = constraints.filter{ $0.requirement == .unversioned }
10101010
guard incompatibleConstraints.isEmpty else {
10111011
self.error = DependencyResolverError.revisionDependencyContainsLocalPackage(
1012-
dependency: container.identifier.identity,
1013-
localPackage: incompatibleConstraints[0].identifier.identity
1012+
dependency: container.identifier.name,
1013+
localPackage: incompatibleConstraints[0].identifier.name
10141014
)
10151015
return AnySequence([])
10161016
}

Sources/PackageGraph/PackageGraphLoader.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension PackageGraphError: CustomStringConvertible {
3535
public var description: String {
3636
switch self {
3737
case .noModules(let package):
38-
return "package '\(package)' contains no targets"
38+
return "package '\(package)' contains no products"
3939

4040
case .cycleDetected(let cycle):
4141
return "cyclic dependency declaration found: " +
@@ -82,7 +82,7 @@ public struct PackageGraphLoader {
8282
let manifestMapSequence = (root.manifests + externalManifests).map({ (PackageReference.computeIdentity(packageURL: $0.url), $0) })
8383
let manifestMap = Dictionary(uniqueKeysWithValues: manifestMapSequence)
8484
let successors: (Manifest) -> [Manifest] = { manifest in
85-
manifest.dependencies.compactMap({
85+
manifest.allRequiredDependencies.compactMap({
8686
let url = config.mirroredURL(forURL: $0.url)
8787
return manifestMap[PackageReference.computeIdentity(packageURL: url)]
8888
})
@@ -111,8 +111,6 @@ public struct PackageGraphLoader {
111111
// Create the packages.
112112
var manifestToPackage: [Manifest: Package] = [:]
113113
for manifest in allManifests {
114-
let isRootPackage = rootManifestSet.contains(manifest)
115-
116114
// Derive the path to the package.
117115
//
118116
// FIXME: Lift this out of the manifest.
@@ -125,17 +123,16 @@ public struct PackageGraphLoader {
125123
additionalFileRules: additionalFileRules,
126124
fileSystem: fileSystem,
127125
diagnostics: diagnostics,
128-
isRootPackage: isRootPackage,
129126
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
130-
createREPLProduct: isRootPackage ? createREPLProduct : false
127+
createREPLProduct: manifest.packageKind == .root ? createREPLProduct : false
131128
)
132129

133130
diagnostics.wrap(with: PackageLocation.Local(name: manifest.name, packagePath: packagePath), {
134131
let package = try builder.construct()
135132
manifestToPackage[manifest] = package
136133

137134
// Throw if any of the non-root package is empty.
138-
if package.targets.isEmpty && !isRootPackage {
135+
if package.targets.isEmpty && manifest.packageKind != .root {
139136
throw PackageGraphError.noModules(package)
140137
}
141138
})
@@ -231,7 +228,7 @@ private func createResolvedPackages(
231228
let package = packageBuilder.package
232229

233230
// Establish the manifest-declared package dependencies.
234-
packageBuilder.dependencies = package.manifest.dependencies.compactMap({
231+
packageBuilder.dependencies = package.manifest.allRequiredDependencies.compactMap({
235232
let url = config.mirroredURL(forURL: $0.url)
236233
return packageMap[PackageReference.computeIdentity(packageURL: url)]
237234
})

Sources/PackageGraph/PackageGraphRoot.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public struct PackageGraphRoot {
6161
return PackageReference(
6262
identity: PackageReference.computeIdentity(packageURL: effectiveURL),
6363
path: effectiveURL,
64-
isLocal: (requirement == .localPackage)
64+
kind: requirement == .localPackage ? .local : .remote
6565
)
6666
}
6767

@@ -96,7 +96,7 @@ public struct PackageGraphRoot {
9696
public init(input: PackageGraphRootInput, manifests: [Manifest]) {
9797
self.packageRefs = zip(input.packages, manifests).map { (path, manifest) in
9898
let identity = PackageReference.computeIdentity(packageURL: manifest.url)
99-
return PackageReference(identity: identity, path: path.pathString, isLocal: true)
99+
return PackageReference(identity: identity, path: path.pathString, kind: .root)
100100
}
101101
self.manifests = manifests
102102
self.dependencies = input.dependencies

Sources/PackageGraph/PinsStore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ extension PinsStore.Pin: JSONMappable, JSONSerializable, Equatable {
148148
public init(json: JSON) throws {
149149
let name: String? = json.get("package")
150150
let url: String = try json.get("repositoryURL")
151-
let ref = PackageReference(identity: PackageReference.computeIdentity(packageURL: url), path: url)
151+
let identity = PackageReference.computeIdentity(packageURL: url)
152+
let ref = PackageReference(identity: identity, path: url)
152153
self.packageRef = name.flatMap(ref.with(newName:)) ?? ref
153154
self.state = try json.get("state")
154155
}

Sources/PackageGraph/Pubgrub.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,8 @@ public final class PubgrubDependencyResolver {
842842
constraints.append(dependency)
843843
case .unversioned:
844844
throw DependencyResolverError.revisionDependencyContainsLocalPackage(
845-
dependency: package.identity,
846-
localPackage: dependency.identifier.identity
845+
dependency: package.name,
846+
localPackage: dependency.identifier.name
847847
)
848848
}
849849
}
@@ -898,7 +898,7 @@ public final class PubgrubDependencyResolver {
898898
identity: "<synthesized-root>",
899899
path: "<synthesized-root-path>",
900900
name: nil,
901-
isLocal: true
901+
kind: .root
902902
)
903903

904904
self.root = root
@@ -1459,7 +1459,7 @@ private final class DiagnosticReportBuilder {
14591459
}
14601460

14611461
private func description(for term: Term, normalizeRange: Bool = false) -> String {
1462-
let name = term.package.name ?? term.package.lastPathComponent
1462+
let name = term.package.name
14631463

14641464
switch term.requirement {
14651465
case .any: return "every version of \(name)"

Sources/PackageGraph/RawPackageConstraints.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension PackageDependencyDescription {
1818
return PackageReference(
1919
identity: PackageReference.computeIdentity(packageURL: effectiveURL),
2020
path: effectiveURL,
21-
isLocal: (requirement == .localPackage)
21+
kind: requirement == .localPackage ? .local : .remote
2222
)
2323
}
2424
}
@@ -27,7 +27,7 @@ extension Manifest {
2727

2828
/// Constructs constraints of the dependencies in the raw package.
2929
public func dependencyConstraints(config: SwiftPMConfig) -> [RepositoryPackageConstraint] {
30-
return dependencies.map({
30+
return allRequiredDependencies.map({
3131
return RepositoryPackageConstraint(
3232
container: $0.createPackageRef(config: config),
3333
requirement: $0.requirement.toConstraintRequirement())

Sources/PackageGraph/RepositoryPackageContainerProvider.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class RepositoryPackageContainerProvider: PackageContainerProvider {
6262
completion: @escaping (Result<PackageContainer, AnyError>) -> Void
6363
) {
6464
// If the container is local, just create and return a local package container.
65-
if identifier.isLocal {
65+
if identifier.kind != .remote {
6666
callbacksQueue.async {
6767
let container = LocalPackageContainer(identifier,
6868
config: self.config,
@@ -107,7 +107,7 @@ extension PackageReference {
107107
///
108108
/// This should only be accessed when the reference is not local.
109109
public var repository: RepositorySpecifier {
110-
precondition(!isLocal)
110+
precondition(kind == .remote)
111111
return RepositorySpecifier(url: path)
112112
}
113113
}
@@ -210,6 +210,7 @@ public class LocalPackageContainer: BasePackageContainer, CustomStringConvertibl
210210
baseURL: identifier.path,
211211
version: nil,
212212
toolsVersion: toolsVersion,
213+
packageKind: identifier.kind,
213214
fileSystem: fs)
214215
return _manifest!
215216
}
@@ -469,6 +470,7 @@ public class RepositoryPackageContainer: BasePackageContainer, CustomStringConve
469470
baseURL: packageURL,
470471
version: version,
471472
toolsVersion: toolsVersion,
473+
packageKind: identifier.kind,
472474
fileSystem: fs)
473475
}
474476
}

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ public protocol ManifestLoaderProtocol {
6868
/// - path: The root path of the package.
6969
/// - baseURL: The URL the manifest was loaded from.
7070
/// - version: The version the manifest is from, if known.
71-
/// - manifestVersion: The version of manifest to load.
71+
/// - toolsVersion: The version of the tools the manifest supports.
72+
/// - kind: The kind of package the manifest is from.
7273
/// - fileSystem: If given, the file system to load from (otherwise load from the local file system).
74+
/// - diagnostics: The diagnostics engine.
7375
func load(
7476
packagePath path: AbsolutePath,
7577
baseURL: String,
7678
version: Version?,
7779
toolsVersion: ToolsVersion,
80+
packageKind: PackageReference.Kind,
7881
fileSystem: FileSystem?,
7982
diagnostics: DiagnosticsEngine?
8083
) throws -> Manifest
@@ -87,12 +90,16 @@ extension ManifestLoaderProtocol {
8790
/// - path: The root path of the package.
8891
/// - baseURL: The URL the manifest was loaded from.
8992
/// - version: The version the manifest is from, if known.
90-
/// - fileSystem: The file system to load from.
93+
/// - toolsVersion: The version of the tools the manifest supports.
94+
/// - kind: The kind of package the manifest is from.
95+
/// - fileSystem: If given, the file system to load from (otherwise load from the local file system).
96+
/// - diagnostics: The diagnostics engine.
9197
public func load(
9298
package path: AbsolutePath,
9399
baseURL: String,
94100
version: Version? = nil,
95101
toolsVersion: ToolsVersion,
102+
packageKind: PackageReference.Kind,
96103
fileSystem: FileSystem? = nil,
97104
diagnostics: DiagnosticsEngine? = nil
98105
) throws -> Manifest {
@@ -101,6 +108,7 @@ extension ManifestLoaderProtocol {
101108
baseURL: baseURL,
102109
version: version,
103110
toolsVersion: toolsVersion,
111+
packageKind: packageKind,
104112
fileSystem: fileSystem,
105113
diagnostics: diagnostics
106114
)
@@ -166,17 +174,20 @@ public final class ManifestLoader: ManifestLoaderProtocol {
166174
/// - packagePath: The absolute path of the package root.
167175
/// - swiftCompiler: The absolute path of a `swiftc` executable.
168176
/// Its associated resources will be used by the loader.
177+
/// - kind: The kind of package the manifest is from.
169178
public static func loadManifest(
170179
packagePath: AbsolutePath,
171-
swiftCompiler: AbsolutePath
180+
swiftCompiler: AbsolutePath,
181+
packageKind: PackageReference.Kind
172182
) throws -> Manifest {
173183
let resources = try UserManifestResources(swiftCompiler: swiftCompiler)
174184
let loader = ManifestLoader(manifestResources: resources)
175185
let toolsVersion = try ToolsVersionLoader().load(at: packagePath, fileSystem: localFileSystem)
176186
return try loader.load(
177187
package: packagePath,
178188
baseURL: packagePath.pathString,
179-
toolsVersion: toolsVersion
189+
toolsVersion: toolsVersion,
190+
packageKind: packageKind
180191
)
181192
}
182193

@@ -185,6 +196,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
185196
baseURL: String,
186197
version: Version?,
187198
toolsVersion: ToolsVersion,
199+
packageKind: PackageReference.Kind,
188200
fileSystem: FileSystem? = nil,
189201
diagnostics: DiagnosticsEngine? = nil
190202
) throws -> Manifest {
@@ -193,6 +205,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
193205
baseURL: baseURL,
194206
version: version,
195207
toolsVersion: toolsVersion,
208+
packageKind: packageKind,
196209
fileSystem: fileSystem,
197210
diagnostics: diagnostics
198211
)
@@ -204,12 +217,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
204217
/// - path: The path to the manifest file (or a package root).
205218
/// - baseURL: The URL the manifest was loaded from.
206219
/// - version: The version the manifest is from, if known.
220+
/// - kind: The kind of package the manifest is from.
207221
/// - fileSystem: If given, the file system to load from (otherwise load from the local file system).
208222
func loadFile(
209223
path inputPath: AbsolutePath,
210224
baseURL: String,
211225
version: Version?,
212226
toolsVersion: ToolsVersion,
227+
packageKind: PackageReference.Kind,
213228
fileSystem: FileSystem? = nil,
214229
diagnostics: DiagnosticsEngine? = nil
215230
) throws -> Manifest {
@@ -260,6 +275,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
260275
url: baseURL,
261276
version: version,
262277
toolsVersion: toolsVersion,
278+
packageKind: packageKind,
263279
pkgConfig: manifestBuilder.pkgConfig,
264280
providers: manifestBuilder.providers,
265281
cLanguageStandard: manifestBuilder.cLanguageStandard,

0 commit comments

Comments
 (0)