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