Skip to content

Commit 58d25eb

Browse files
committed
Actually skip not needed dependencies during dependency resolution
This is a follow-up to #3162. While that brought back the code for `dependenciesRequired(for:)`, the guard based on `productFilter` actually made it so that it was practically never executed. Instead, the guard should be based on whether the package in question is a root package. Additionally, this made the order of the returned dependencies unstable, due to use of `Set`. Since `dependenciesRequired(for: keepUnused:)` is now only used if `ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION` is set, I removed some dead code from there as well.
1 parent 9305cd7 commit 58d25eb

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Sources/PackageModel/Manifest.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,23 @@ public final class Manifest: ObjectIdentifierProtocol {
165165
return dependencies
166166
}
167167
#else
168-
guard toolsVersion >= .v5_2 && productFilter != .everything else {
168+
guard toolsVersion >= .v5_2 && packageKind != .root else {
169169
return dependencies
170170
}
171-
172-
var requiredDependencies: Set<PackageDependencyDescription> = []
173-
171+
172+
var requiredDependencyURLs: Set<String> = []
173+
174174
for target in targetsRequired(for: products) {
175175
for targetDependency in target.dependencies {
176176
if let dependency = packageDependency(referencedBy: targetDependency) {
177-
requiredDependencies.insert(dependency)
177+
requiredDependencyURLs.insert(dependency.url)
178178
}
179179
}
180180
}
181-
182-
return Array(requiredDependencies)
181+
182+
let dependenciesByURL = Dictionary(dependencies.map({ ($0.url, $0) }), uniquingKeysWith: { $1 })
183+
let requiredDependencies = requiredDependencyURLs.compactMap({ dependenciesByURL[$0] })
184+
return requiredDependencies
183185
#endif
184186
}
185187

@@ -233,7 +235,6 @@ public final class Manifest: ObjectIdentifierProtocol {
233235
}
234236

235237
return dependencies.compactMap { dependency in
236-
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
237238
if let filter = associations[dependency.name] {
238239
return dependency.filtered(by: filter)
239240
} else if keepUnused {
@@ -243,9 +244,6 @@ public final class Manifest: ObjectIdentifierProtocol {
243244
// Dependencies known to not have any relevant products are discarded.
244245
return nil
245246
}
246-
#else
247-
return dependency.filtered(by: .everything)
248-
#endif
249247
}
250248
}
251249

0 commit comments

Comments
 (0)