mirror of
https://github.com/golang/go.git
synced 2026-01-31 08:02:06 +03:00
go/build: include files with parse errors in GoFiles and other lists
go/build.ImportDir returns a *build.Package with various lists of files. If a file is invalid for some reason, for example, because it has a different package name than other files, it's added to InvalidGoFiles in addition to GoFiles, TestGoFiles, or other lists. Previously, files with parse errors or build constraint errors were not included in these lists, which causes problems for tools that use 'go list' since InvalidGoFiles is not printed. With this change, files with any kind of error are added to one of the GoFiles lists. Fixes #39986 Change-Id: Iee007b5092293eb4420c8a39ce731805fe32135f Reviewed-on: https://go-review.googlesource.com/c/go/+/241577 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
26
src/cmd/go/testdata/script/list_load_err.txt
vendored
26
src/cmd/go/testdata/script/list_load_err.txt
vendored
@@ -2,26 +2,42 @@
|
||||
# other files in the same package cause go/build.Import to return an error.
|
||||
# Verfifies golang.org/issue/38568
|
||||
|
||||
|
||||
go list -e -deps ./scan
|
||||
stdout m/want
|
||||
|
||||
|
||||
go list -e -deps ./multi
|
||||
stdout m/want
|
||||
|
||||
|
||||
go list -e -deps ./constraint
|
||||
stdout m/want
|
||||
|
||||
|
||||
[cgo] go list -e -test -deps ./cgotest
|
||||
[cgo] stdout m/want
|
||||
|
||||
|
||||
[cgo] go list -e -deps ./cgoflag
|
||||
[cgo] stdout m/want
|
||||
|
||||
|
||||
# go list -e should include files with errors in GoFiles, TestGoFiles, and
|
||||
# other lists, assuming they match constraints.
|
||||
# Verifies golang.org/issue/39986
|
||||
go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./scan
|
||||
stdout '^good.go,scan.go,$'
|
||||
|
||||
go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./multi
|
||||
stdout '^a.go,b.go,$'
|
||||
|
||||
go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./constraint
|
||||
stdout '^good.go,$'
|
||||
go list -e -f '{{range .IgnoredGoFiles}}{{.}},{{end}}' ./constraint
|
||||
stdout '^constraint.go,$'
|
||||
|
||||
[cgo] go list -e -f '{{range .XTestGoFiles}}{{.}},{{end}}' ./cgotest
|
||||
[cgo] stdout '^cgo_test.go,$'
|
||||
|
||||
[cgo] go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./cgoflag
|
||||
[cgo] stdout '^cgoflag.go,$'
|
||||
|
||||
-- go.mod --
|
||||
module m
|
||||
|
||||
|
||||
@@ -879,14 +879,17 @@ Found:
|
||||
|
||||
if info.parseErr != nil {
|
||||
badFile(name, info.parseErr)
|
||||
continue
|
||||
// Fall through: we might still have a partial AST in info.parsed,
|
||||
// and we want to list files with parse errors anyway.
|
||||
}
|
||||
pf := info.parsed
|
||||
|
||||
pkg := pf.Name.Name
|
||||
if pkg == "documentation" {
|
||||
p.IgnoredGoFiles = append(p.IgnoredGoFiles, name)
|
||||
continue
|
||||
var pkg string
|
||||
if info.parsed != nil {
|
||||
pkg = info.parsed.Name.Name
|
||||
if pkg == "documentation" {
|
||||
p.IgnoredGoFiles = append(p.IgnoredGoFiles, name)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
isTest := strings.HasSuffix(name, "_test.go")
|
||||
@@ -910,8 +913,8 @@ Found:
|
||||
})
|
||||
}
|
||||
// Grab the first package comment as docs, provided it is not from a test file.
|
||||
if pf.Doc != nil && p.Doc == "" && !isTest && !isXTest {
|
||||
p.Doc = doc.Synopsis(pf.Doc.Text())
|
||||
if info.parsed != nil && info.parsed.Doc != nil && p.Doc == "" && !isTest && !isXTest {
|
||||
p.Doc = doc.Synopsis(info.parsed.Doc.Text())
|
||||
}
|
||||
|
||||
if mode&ImportComment != 0 {
|
||||
|
||||
Reference in New Issue
Block a user