1
0
mirror of https://github.com/golang/go synced 2024-11-23 21:00:06 -07:00

cmd/go: test and fix missing deep dependencies in list Deps output

Fixes #21522.

Change-Id: Ifec1681b265576c47a4d736f6f124cc25485c593
Reviewed-on: https://go-review.googlesource.com/57011
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Russ Cox 2017-08-18 11:44:21 -04:00
parent e2cdec77c6
commit 6f0b1aa0e2
3 changed files with 40 additions and 15 deletions

View File

@ -53,7 +53,13 @@ func TestDeps(t *testing.T) {
// Very simple minded diff.
t.Log("-current +generated")
clines := strings.Split(string(current), "\n")
for i, line := range clines {
clines[i] = strings.Join(strings.Fields(line), " ")
}
ulines := strings.Split(string(updated), "\n")
for i, line := range ulines {
ulines[i] = strings.Join(strings.Fields(line), " ")
}
for len(clines) > 0 {
cl := clines[0]
switch {

View File

@ -1703,6 +1703,20 @@ func TestGoListDedupsPackages(t *testing.T) {
}
}
func TestGoListDeps(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempDir("src/p1/p2/p3/p4")
tg.setenv("GOPATH", tg.path("."))
tg.tempFile("src/p1/p.go", "package p1\nimport _ \"p1/p2\"\n")
tg.tempFile("src/p1/p2/p.go", "package p2\nimport _ \"p1/p2/p3\"\n")
tg.tempFile("src/p1/p2/p3/p.go", "package p3\nimport _ \"p1/p2/p3/p4\"\n")
tg.tempFile("src/p1/p2/p3/p4/p.go", "package p4\n")
tg.run("list", "-f", "{{.Deps}}", "p1")
tg.grepStdout("p1/p2/p3/p4", "Deps(p1) does not mention p4")
}
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.
func TestUnsuccessfulGoInstallShouldMentionMissingPackage(t *testing.T) {
tg := testgo(t)

View File

@ -1050,17 +1050,6 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) *Package
// Build list of imported packages and full dependency list.
imports := make([]*Package, 0, len(p.Imports))
deps := make(map[string]*Package)
save := func(path string, p1 *Package) {
// The same import path could produce an error or not,
// depending on what tries to import it.
// Prefer to record entries with errors, so we can report them.
p0 := deps[path]
if p0 == nil || p1.Error != nil && (p0.Error == nil || len(p0.Error.ImportStack) > len(p1.Error.ImportStack)) {
deps[path] = p1
}
}
for i, path := range importPaths {
if path == "C" {
continue
@ -1083,17 +1072,33 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) *Package
p.Imports[i] = path
}
save(path, p1)
imports = append(imports, p1)
for _, dep := range p1.Internal.Imports {
save(dep.ImportPath, dep)
}
if p1.Incomplete {
p.Incomplete = true
}
}
p.Internal.Imports = imports
deps := make(map[string]*Package)
var q []*Package
q = append(q, imports...)
for i := 0; i < len(q); i++ {
p1 := q[i]
path := p1.ImportPath
// The same import path could produce an error or not,
// depending on what tries to import it.
// Prefer to record entries with errors, so we can report them.
p0 := deps[path]
if p0 == nil || p1.Error != nil && (p0.Error == nil || len(p0.Error.ImportStack) > len(p1.Error.ImportStack)) {
deps[path] = p1
for _, p2 := range p1.Internal.Imports {
if deps[p2.ImportPath] != p2 {
q = append(q, p2)
}
}
}
}
p.Deps = make([]string, 0, len(deps))
for dep := range deps {
p.Deps = append(p.Deps, dep)