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

Commit ffe2945

Browse files
committed
dep: Emit ptree from GetDirectDependencyNames()
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.
1 parent 689880a commit ffe2945

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

cmd/dep/init.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
100100
ctx.Out.Println("Getting direct dependencies...")
101101
}
102102

103-
// If this errors, the next call will too; don't bother handling it twice.
104-
ptree, _ := p.ParseRootPackageTree()
105-
directDeps, err := p.GetDirectDependencyNames(sm)
103+
ptree, directDeps, err := p.GetDirectDependencyNames(sm)
106104
if err != nil {
107105
return errors.Wrap(err, "init failed: unable to determine direct dependencies")
108106
}

cmd/dep/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con
766766

767767
// Collect the complete set of direct project dependencies, incorporating
768768
// requireds and ignores appropriately.
769-
directDeps, err := p.GetDirectDependencyNames(sm)
769+
_, directDeps, err := p.GetDirectDependencyNames(sm)
770770
if err != nil {
771771
// Return empty collection, not nil, if we fail here.
772772
return constraintCollection, []error{errors.Wrap(err, "failed to get direct dependencies")}

project.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (p *Project) MakeParams() gps.SolveParameters {
143143
//
144144
// The resulting tree is cached internally at p.RootPackageTree.
145145
func (p *Project) ParseRootPackageTree() (pkgtree.PackageTree, error) {
146-
if len(p.RootPackageTree.Packages) == 0 {
146+
if p.RootPackageTree.Packages == nil {
147147
ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
148148
if err != nil {
149149
return pkgtree.PackageTree{}, errors.Wrap(err, "analysis of current project's packages failed")
@@ -174,10 +174,10 @@ func (p *Project) ParseRootPackageTree() (pkgtree.PackageTree, error) {
174174
// This function will correctly utilize ignores and requireds from an existing
175175
// manifest, if one is present, but will also do the right thing without a
176176
// manifest.
177-
func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (map[gps.ProjectRoot]bool, error) {
177+
func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (pkgtree.PackageTree, map[gps.ProjectRoot]bool, error) {
178178
ptree, err := p.ParseRootPackageTree()
179179
if err != nil {
180-
return nil, err
180+
return pkgtree.PackageTree{}, nil, err
181181
}
182182

183183
var ig *pkgtree.IgnoredRuleset
@@ -211,26 +211,26 @@ func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (map[gps.Projec
211211
for _, ip := range reach {
212212
pr, err := sm.DeduceProjectRoot(ip)
213213
if err != nil {
214-
return nil, err
214+
return pkgtree.PackageTree{}, nil, err
215215
}
216216
directDeps[pr] = true
217217
}
218218

219-
return directDeps, nil
219+
return ptree, directDeps, nil
220220
}
221221

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

233-
dd, err := p.GetDirectDependencyNames(sm)
233+
_, dd, err := p.GetDirectDependencyNames(sm)
234234
if err != nil {
235235
return nil
236236
}

0 commit comments

Comments
 (0)