@@ -289,7 +289,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
289
289
return digestMismatch , hasMissingPkgs , errors .Errorf ("could not set up solver for input hashing: %s" , err )
290
290
}
291
291
292
- cm := collectConstraints (ptree , p , sm )
292
+ cm := collectConstraints (ctx , ptree , p , sm )
293
293
294
294
// Get the project list and sort it so that the printed output users see is
295
295
// deterministically ordered. (This may be superfluous if the lock is always
@@ -463,7 +463,41 @@ func formatVersion(v gps.Version) string {
463
463
return v .String ()
464
464
}
465
465
466
- func collectConstraints (ptree pkgtree.PackageTree , p * dep.Project , sm gps.SourceManager ) map [string ][]gps.Constraint {
467
- // TODO
468
- return map [string ][]gps.Constraint {}
466
+ // collectConstraints collects constraints declared by all the dependencies.
467
+ func collectConstraints (ctx * dep.Ctx , ptree pkgtree.PackageTree , p * dep.Project , sm gps.SourceManager ) map [string ][]gps.Constraint {
468
+ constraintCollection := make (map [string ][]gps.Constraint )
469
+
470
+ // Get direct deps of the root project
471
+ _ , directDeps , err := getDirectDependencies (sm , p )
472
+ if err != nil {
473
+ ctx .Err .Println ("Error getting direct deps:" , err )
474
+ }
475
+ // Create a root analyzer
476
+ rootAnalyzer := newRootAnalyzer (false , ctx , directDeps , sm )
477
+
478
+ // Iterate through the locked projects and collect constrains of all the projects
479
+ for _ , proj := range p .Lock .Projects () {
480
+ manifest , _ , err := sm .GetManifestAndLock (proj .Ident (), proj .Version (), rootAnalyzer )
481
+ if err != nil {
482
+ ctx .Err .Println ("Error getting manifest and lock:" , err )
483
+ }
484
+
485
+ // Get project constraints
486
+ pc := manifest .DependencyConstraints ()
487
+
488
+ // Iterate through the project constraints to get individual dependency
489
+ // project and constraint values.
490
+ for pr , pp := range pc {
491
+ // Check if a collection exists for a project root and append to
492
+ // existing one or create a new constraint collection.
493
+ if cc , exists := constraintCollection [string (pr )]; exists {
494
+ cc = append (cc , pp .Constraint )
495
+ constraintCollection [string (pr )] = cc
496
+ } else {
497
+ constraintCollection [string (pr )] = []gps.Constraint {pp .Constraint }
498
+ }
499
+ }
500
+ }
501
+
502
+ return constraintCollection
469
503
}
0 commit comments