@@ -408,6 +408,24 @@ extension Workspace {
408
408
automaticallyAddManagedDependencies: Bool = false ,
409
409
observabilityScope: ObservabilityScope
410
410
) throws -> DependencyManifests {
411
+ let prepopulateManagedDependencies : ( [ PackageReference ] ) throws -> Void = { refs in
412
+ // pre-populate managed dependencies if we are asked to do so (this happens when resolving to a resolved
413
+ // file)
414
+ if automaticallyAddManagedDependencies {
415
+ try refs. forEach { ref in
416
+ // Since we are creating managed dependencies based on the resolved file in this mode, but local
417
+ // packages aren't part of that file, they will be missing from it. So we're eagerly adding them
418
+ // here, but explicitly don't add any that are overridden by a root with the same identity since
419
+ // that would lead to loading the given package twice, once as a root and once as a dependency
420
+ // which violates various assumptions.
421
+ if case . fileSystem = ref. kind, !root. manifests. keys. contains ( ref. identity) {
422
+ try self . state. dependencies. add ( . fileSystem( packageRef: ref) )
423
+ }
424
+ }
425
+ observabilityScope. trap { try self . state. save ( ) }
426
+ }
427
+ }
428
+
411
429
// Utility Just because a raw tuple cannot be hashable.
412
430
struct Key : Hashable {
413
431
let identity : PackageIdentity
@@ -442,6 +460,7 @@ extension Workspace {
442
460
443
461
// Load root dependencies manifests (in parallel)
444
462
let rootDependencies = root. dependencies. map ( \. packageRef)
463
+ try prepopulateManagedDependencies ( rootDependencies)
445
464
let rootDependenciesManifests = try temp_await { self . loadManagedManifests (
446
465
for: rootDependencies,
447
466
observabilityScope: observabilityScope,
@@ -473,21 +492,7 @@ extension Workspace {
473
492
let dependenciesRequired = pair. item. dependenciesRequired ( for: pair. key. productFilter)
474
493
let dependenciesToLoad = dependenciesRequired. map ( \. packageRef)
475
494
. filter { !loadedManifests. keys. contains ( $0. identity) }
476
- // pre-populate managed dependencies if we are asked to do so (this happens when resolving to a resolved
477
- // file)
478
- if automaticallyAddManagedDependencies {
479
- try dependenciesToLoad. forEach { ref in
480
- // Since we are creating managed dependencies based on the resolved file in this mode, but local
481
- // packages aren't part of that file, they will be missing from it. So we're eagerly adding them
482
- // here, but explicitly don't add any that are overridden by a root with the same identity since
483
- // that would lead to loading the given package twice, once as a root and once as a dependency
484
- // which violates various assumptions.
485
- if case . fileSystem = ref. kind, !root. manifests. keys. contains ( ref. identity) {
486
- try self . state. dependencies. add ( . fileSystem( packageRef: ref) )
487
- }
488
- }
489
- observabilityScope. trap { try self . state. save ( ) }
490
- }
495
+ try prepopulateManagedDependencies ( dependenciesToLoad)
491
496
let dependenciesManifests = try temp_await { self . loadManagedManifests (
492
497
for: dependenciesToLoad,
493
498
observabilityScope: observabilityScope,
0 commit comments