From: Ian Lance Taylor Date: Sat, 29 Oct 2022 00:23:58 +0000 (-0700) Subject: go/build: ignore files by extension before matching on name X-Git-Tag: go1.20rc1~472 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=49bbece44c93b4de62ff360268c420e45f27ad63;p=gostls13.git go/build: ignore files by extension before matching on name Otherwise given a file like defs_nacl_amd64p32.go.~1~ we will add "nacl" and "amd64p32" to AllTags. This was causing the cmd/go/internal/modindex tests to fail on my system, since I had an old editor backup file lying around. Change-Id: Ib1c5d835e4871addae6dc78cee07c9839bb880e2 Reviewed-on: https://go-review.googlesource.com/c/go/+/446395 Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- diff --git a/src/go/build/build.go b/src/go/build/build.go index 28c7445580..1cb10f50bf 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -1423,12 +1423,12 @@ func (ctxt *Context) matchFile(dir, name string, allTags map[string]bool, binary } ext := name[i:] - if !ctxt.goodOSArchFile(name, allTags) && !ctxt.UseAllFiles { + if ext != ".go" && fileListForExt(&dummyPkg, ext) == nil { + // skip return nil, nil } - if ext != ".go" && fileListForExt(&dummyPkg, ext) == nil { - // skip + if !ctxt.goodOSArchFile(name, allTags) && !ctxt.UseAllFiles { return nil, nil } diff --git a/src/go/build/build_test.go b/src/go/build/build_test.go index 1b0a371d67..3322377715 100644 --- a/src/go/build/build_test.go +++ b/src/go/build/build_test.go @@ -790,3 +790,13 @@ func TestAllTags(t *testing.T) { t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles) } } + +func TestAllTagsNonSourceFile(t *testing.T) { + p, err := Default.ImportDir("testdata/non_source_tags", 0) + if err != nil { + t.Fatal(err) + } + if len(p.AllTags) > 0 { + t.Errorf("AllTags = %v, want empty", p.AllTags) + } +} diff --git a/src/go/build/testdata/non_source_tags/non_source_tags.go b/src/go/build/testdata/non_source_tags/non_source_tags.go new file mode 100644 index 0000000000..068acc42f1 --- /dev/null +++ b/src/go/build/testdata/non_source_tags/non_source_tags.go @@ -0,0 +1,5 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package non_source_tags diff --git a/src/go/build/testdata/non_source_tags/x_arm.go.ignore b/src/go/build/testdata/non_source_tags/x_arm.go.ignore new file mode 100644 index 0000000000..068acc42f1 --- /dev/null +++ b/src/go/build/testdata/non_source_tags/x_arm.go.ignore @@ -0,0 +1,5 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package non_source_tags