Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit ea8b946

Browse files
committed
fix(status): implement collectConstraints()
1 parent ab09aa5 commit ea8b946

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

cmd/dep/status.go

+38-4
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
289289
return digestMismatch, hasMissingPkgs, errors.Errorf("could not set up solver for input hashing: %s", err)
290290
}
291291

292-
cm := collectConstraints(ptree, p, sm)
292+
cm := collectConstraints(ctx, ptree, p, sm)
293293

294294
// Get the project list and sort it so that the printed output users see is
295295
// deterministically ordered. (This may be superfluous if the lock is always
@@ -463,7 +463,41 @@ func formatVersion(v gps.Version) string {
463463
return v.String()
464464
}
465465

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
469503
}

0 commit comments

Comments
 (0)