Skip to content

Commit b2f40e2

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 b2f40e2

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

Sources/PackageModel/Manifest.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,21 @@ 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+
return dependencies.filter { requiredDependencyURLs.contains($0.url) }
183183
#endif
184184
}
185185

@@ -233,7 +233,6 @@ public final class Manifest: ObjectIdentifierProtocol {
233233
}
234234

235235
return dependencies.compactMap { dependency in
236-
#if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION
237236
if let filter = associations[dependency.name] {
238237
return dependency.filtered(by: filter)
239238
} else if keepUnused {
@@ -243,9 +242,6 @@ public final class Manifest: ObjectIdentifierProtocol {
243242
// Dependencies known to not have any relevant products are discarded.
244243
return nil
245244
}
246-
#else
247-
return dependency.filtered(by: .everything)
248-
#endif
249245
}
250246
}
251247

0 commit comments

Comments
 (0)