mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
go/build: avoid duplicates in InvalidGoFiles
For #45827 For #39986 Updates #45999 Change-Id: I0c919b6a2e56e7003b90425487eafe0f0eadc609 Reviewed-on: https://go-review.googlesource.com/c/go/+/317299 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
287025925f
commit
e18a8b4fb2
2 changed files with 37 additions and 17 deletions
|
|
@ -810,6 +810,17 @@ Found:
|
||||||
}
|
}
|
||||||
|
|
||||||
var badGoError error
|
var badGoError error
|
||||||
|
badFiles := make(map[string]bool)
|
||||||
|
badFile := func(name string, err error) {
|
||||||
|
if badGoError == nil {
|
||||||
|
badGoError = err
|
||||||
|
}
|
||||||
|
if !badFiles[name] {
|
||||||
|
p.InvalidGoFiles = append(p.InvalidGoFiles, name)
|
||||||
|
badFiles[name] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var Sfiles []string // files with ".S"(capital S)/.sx(capital s equivalent for case insensitive filesystems)
|
var Sfiles []string // files with ".S"(capital S)/.sx(capital s equivalent for case insensitive filesystems)
|
||||||
var firstFile, firstCommentFile string
|
var firstFile, firstCommentFile string
|
||||||
embedPos := make(map[string][]token.Position)
|
embedPos := make(map[string][]token.Position)
|
||||||
|
|
@ -834,16 +845,9 @@ Found:
|
||||||
name := d.Name()
|
name := d.Name()
|
||||||
ext := nameExt(name)
|
ext := nameExt(name)
|
||||||
|
|
||||||
badFile := func(err error) {
|
|
||||||
if badGoError == nil {
|
|
||||||
badGoError = err
|
|
||||||
}
|
|
||||||
p.InvalidGoFiles = append(p.InvalidGoFiles, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := ctxt.matchFile(p.Dir, name, allTags, &p.BinaryOnly, fset)
|
info, err := ctxt.matchFile(p.Dir, name, allTags, &p.BinaryOnly, fset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badFile(err)
|
badFile(name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if info == nil {
|
if info == nil {
|
||||||
|
|
@ -874,7 +878,7 @@ Found:
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.parseErr != nil {
|
if info.parseErr != nil {
|
||||||
badFile(info.parseErr)
|
badFile(name, info.parseErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pf := info.parsed
|
pf := info.parsed
|
||||||
|
|
@ -896,12 +900,14 @@ Found:
|
||||||
p.Name = pkg
|
p.Name = pkg
|
||||||
firstFile = name
|
firstFile = name
|
||||||
} else if pkg != p.Name {
|
} else if pkg != p.Name {
|
||||||
badFile(&MultiplePackageError{
|
// TODO(#45999): The choice of p.Name is arbitrary based on file iteration
|
||||||
|
// order. Instead of resolving p.Name arbitrarily, we should clear out the
|
||||||
|
// existing name and mark the existing files as also invalid.
|
||||||
|
badFile(name, &MultiplePackageError{
|
||||||
Dir: p.Dir,
|
Dir: p.Dir,
|
||||||
Packages: []string{p.Name, pkg},
|
Packages: []string{p.Name, pkg},
|
||||||
Files: []string{firstFile, name},
|
Files: []string{firstFile, name},
|
||||||
})
|
})
|
||||||
p.InvalidGoFiles = append(p.InvalidGoFiles, name)
|
|
||||||
}
|
}
|
||||||
// Grab the first package comment as docs, provided it is not from a test file.
|
// Grab the first package comment as docs, provided it is not from a test file.
|
||||||
if pf.Doc != nil && p.Doc == "" && !isTest && !isXTest {
|
if pf.Doc != nil && p.Doc == "" && !isTest && !isXTest {
|
||||||
|
|
@ -913,12 +919,12 @@ Found:
|
||||||
if line != 0 {
|
if line != 0 {
|
||||||
com, err := strconv.Unquote(qcom)
|
com, err := strconv.Unquote(qcom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badFile(fmt.Errorf("%s:%d: cannot parse import comment", filename, line))
|
badFile(name, fmt.Errorf("%s:%d: cannot parse import comment", filename, line))
|
||||||
} else if p.ImportComment == "" {
|
} else if p.ImportComment == "" {
|
||||||
p.ImportComment = com
|
p.ImportComment = com
|
||||||
firstCommentFile = name
|
firstCommentFile = name
|
||||||
} else if p.ImportComment != com {
|
} else if p.ImportComment != com {
|
||||||
badFile(fmt.Errorf("found import comments %q (%s) and %q (%s) in %s", p.ImportComment, firstCommentFile, com, name, p.Dir))
|
badFile(name, fmt.Errorf("found import comments %q (%s) and %q (%s) in %s", p.ImportComment, firstCommentFile, com, name, p.Dir))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -928,13 +934,13 @@ Found:
|
||||||
for _, imp := range info.imports {
|
for _, imp := range info.imports {
|
||||||
if imp.path == "C" {
|
if imp.path == "C" {
|
||||||
if isTest {
|
if isTest {
|
||||||
badFile(fmt.Errorf("use of cgo in test %s not supported", filename))
|
badFile(name, fmt.Errorf("use of cgo in test %s not supported", filename))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
isCgo = true
|
isCgo = true
|
||||||
if imp.doc != nil {
|
if imp.doc != nil {
|
||||||
if err := ctxt.saveCgo(filename, p, imp.doc); err != nil {
|
if err := ctxt.saveCgo(filename, p, imp.doc); err != nil {
|
||||||
badFile(err)
|
badFile(name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,8 @@ func TestEmptyFolderImport(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiplePackageImport(t *testing.T) {
|
func TestMultiplePackageImport(t *testing.T) {
|
||||||
_, err := Import(".", "testdata/multi", 0)
|
pkg, err := Import(".", "testdata/multi", 0)
|
||||||
|
|
||||||
mpe, ok := err.(*MultiplePackageError)
|
mpe, ok := err.(*MultiplePackageError)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal(`Import("testdata/multi") did not return MultiplePackageError.`)
|
t.Fatal(`Import("testdata/multi") did not return MultiplePackageError.`)
|
||||||
|
|
@ -115,7 +116,20 @@ func TestMultiplePackageImport(t *testing.T) {
|
||||||
Files: []string{"file.go", "file_appengine.go"},
|
Files: []string{"file.go", "file_appengine.go"},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(mpe, want) {
|
if !reflect.DeepEqual(mpe, want) {
|
||||||
t.Errorf("got %#v; want %#v", mpe, want)
|
t.Errorf("err = %#v; want %#v", mpe, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#45999): Since the name is ambiguous, pkg.Name should be left empty.
|
||||||
|
if wantName := "main"; pkg.Name != wantName {
|
||||||
|
t.Errorf("pkg.Name = %q; want %q", pkg.Name, wantName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if wantGoFiles := []string{"file.go", "file_appengine.go"}; !reflect.DeepEqual(pkg.GoFiles, wantGoFiles) {
|
||||||
|
t.Errorf("pkg.GoFiles = %q; want %q", pkg.GoFiles, wantGoFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
if wantInvalidFiles := []string{"file_appengine.go"}; !reflect.DeepEqual(pkg.InvalidGoFiles, wantInvalidFiles) {
|
||||||
|
t.Errorf("pkg.InvalidGoFiles = %q; want %q", pkg.InvalidGoFiles, wantInvalidFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue