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

Commit

Permalink
dep: Emit ptree from GetDirectDependencyNames()
Browse files Browse the repository at this point in the history
A convenience, as callers often need both the RootPackageTree and the
direct dependencies map. Though this does further suggest that we ought
to be able to stitch this up neatly in gps, at some point.

Also, handle an error that was previously dropped.
  • Loading branch information
sdboyer committed Jan 16, 2018
1 parent 689880a commit 2eeefbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}

p, err := cmd.establishProjectAt(root, ctx)
if err != nil {
return err
}

sm, err := ctx.SourceManager()
if err != nil {
Expand All @@ -100,9 +103,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
ctx.Out.Println("Getting direct dependencies...")
}

// If this errors, the next call will too; don't bother handling it twice.
ptree, _ := p.ParseRootPackageTree()
directDeps, err := p.GetDirectDependencyNames(sm)
ptree, directDeps, err := p.GetDirectDependencyNames(sm)
if err != nil {
return errors.Wrap(err, "init failed: unable to determine direct dependencies")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con

// Collect the complete set of direct project dependencies, incorporating
// requireds and ignores appropriately.
directDeps, err := p.GetDirectDependencyNames(sm)
_, directDeps, err := p.GetDirectDependencyNames(sm)
if err != nil {
// Return empty collection, not nil, if we fail here.
return constraintCollection, []error{errors.Wrap(err, "failed to get direct dependencies")}
Expand Down
16 changes: 8 additions & 8 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (p *Project) MakeParams() gps.SolveParameters {
//
// The resulting tree is cached internally at p.RootPackageTree.
func (p *Project) ParseRootPackageTree() (pkgtree.PackageTree, error) {
if len(p.RootPackageTree.Packages) == 0 {
if p.RootPackageTree.Packages == nil {
ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
if err != nil {
return pkgtree.PackageTree{}, errors.Wrap(err, "analysis of current project's packages failed")
Expand Down Expand Up @@ -174,10 +174,10 @@ func (p *Project) ParseRootPackageTree() (pkgtree.PackageTree, error) {
// This function will correctly utilize ignores and requireds from an existing
// manifest, if one is present, but will also do the right thing without a
// manifest.
func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (map[gps.ProjectRoot]bool, error) {
func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (pkgtree.PackageTree, map[gps.ProjectRoot]bool, error) {
ptree, err := p.ParseRootPackageTree()
if err != nil {
return nil, err
return pkgtree.PackageTree{}, nil, err
}

var ig *pkgtree.IgnoredRuleset
Expand Down Expand Up @@ -211,26 +211,26 @@ func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (map[gps.Projec
for _, ip := range reach {
pr, err := sm.DeduceProjectRoot(ip)
if err != nil {
return nil, err
return pkgtree.PackageTree{}, nil, err
}
directDeps[pr] = true
}

return directDeps, nil
return ptree, directDeps, nil
}

// FindIneffectualConstraints looks for constraint rules expressed in the
// manifest that will have no effect during solving, as they are specified for
// projects that are not direct dependencies of the Project.
//
// "Direct dependency" here is as implemented by GetDirectDependencyNames() -
// after all "ignored" and "required" rules have been considered.
// "Direct dependency" here is as implemented by GetDirectDependencyNames();
// it correctly incorporates all "ignored" and "required" rules.
func (p *Project) FindIneffectualConstraints(sm gps.SourceManager) []gps.ProjectRoot {
if p.Manifest == nil {
return nil
}

dd, err := p.GetDirectDependencyNames(sm)
_, dd, err := p.GetDirectDependencyNames(sm)
if err != nil {
return nil
}
Expand Down

0 comments on commit 2eeefbd

Please sign in to comment.