Commit f2df0ec7 authored by Russ Cox's avatar Russ Cox

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: default avatarBryan C. Mills <bcmills@google.com>
parent 25813f9f
......@@ -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.
......
......@@ -339,9 +339,11 @@ func (b *Builder) CompileAction(mode, depMode BuildMode, p *load.Package) *Actio
Objdir: b.NewObjdir(),
}
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 {
switch p.ImportPath {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment