1
0
mirror of https://github.com/golang/go synced 2024-09-29 22:24:33 -06:00

cmd/go: avoid infinite loop in go list -json -e on import cycle

Don't chase import cycles forever preparing list JSON.

Fixes #24086.

Change-Id: Ia1139d0c8d813d068c367a8baee59d240a545617
Reviewed-on: https://go-review.googlesource.com/108016
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Russ Cox 2018-04-18 21:26:55 -04:00
parent 25813f9f91
commit f2df0ec7dd
2 changed files with 7 additions and 2 deletions

View File

@ -1373,6 +1373,9 @@ func TestImportCycle(t *testing.T) {
if count > 1 {
t.Fatal("go build mentioned import cycle more than once")
}
// Don't hang forever.
tg.run("list", "-e", "-json", "selfimport")
}
// cmd/go: custom import path checking should not apply to Go packages without import comment.

View File

@ -339,8 +339,10 @@ func (b *Builder) CompileAction(mode, depMode BuildMode, p *load.Package) *Actio
Objdir: b.NewObjdir(),
}
for _, p1 := range p.Internal.Imports {
a.Deps = append(a.Deps, b.CompileAction(depMode, depMode, p1))
if p.Error == nil || !p.Error.IsImportCycle {
for _, p1 := range p.Internal.Imports {
a.Deps = append(a.Deps, b.CompileAction(depMode, depMode, p1))
}
}
if p.Standard {