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

Commit

Permalink
fix(status): implement collectConstraints()
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Aug 8, 2017
1 parent ab09aa5 commit ea8b946
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
return digestMismatch, hasMissingPkgs, errors.Errorf("could not set up solver for input hashing: %s", err)
}

cm := collectConstraints(ptree, p, sm)
cm := collectConstraints(ctx, ptree, p, sm)

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

func collectConstraints(ptree pkgtree.PackageTree, p *dep.Project, sm gps.SourceManager) map[string][]gps.Constraint {
// TODO
return map[string][]gps.Constraint{}
// collectConstraints collects constraints declared by all the dependencies.
func collectConstraints(ctx *dep.Ctx, ptree pkgtree.PackageTree, p *dep.Project, sm gps.SourceManager) map[string][]gps.Constraint {
constraintCollection := make(map[string][]gps.Constraint)

// Get direct deps of the root project
_, directDeps, err := getDirectDependencies(sm, p)
if err != nil {
ctx.Err.Println("Error getting direct deps:", err)
}
// Create a root analyzer
rootAnalyzer := newRootAnalyzer(false, ctx, directDeps, sm)

// Iterate through the locked projects and collect constrains of all the projects
for _, proj := range p.Lock.Projects() {
manifest, _, err := sm.GetManifestAndLock(proj.Ident(), proj.Version(), rootAnalyzer)
if err != nil {
ctx.Err.Println("Error getting manifest and lock:", err)
}

// Get project constraints
pc := manifest.DependencyConstraints()

// Iterate through the project constraints to get individual dependency
// project and constraint values.
for pr, pp := range pc {
// Check if a collection exists for a project root and append to
// existing one or create a new constraint collection.
if cc, exists := constraintCollection[string(pr)]; exists {
cc = append(cc, pp.Constraint)
constraintCollection[string(pr)] = cc
} else {
constraintCollection[string(pr)] = []gps.Constraint{pp.Constraint}
}
}
}

return constraintCollection
}

0 comments on commit ea8b946

Please sign in to comment.