Skip to content

Commit 49bbece

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 6a44a3a commit 49bbece

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/go/build/build.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1423,12 +1423,12 @@ func (ctxt *Context) matchFile(dir, name string, allTags map[string]bool, binary
14231423
}
14241424
ext := name[i:]
14251425

1426-
if !ctxt.goodOSArchFile(name, allTags) && !ctxt.UseAllFiles {
1426+
if ext != ".go" && fileListForExt(&dummyPkg, ext) == nil {
1427+
// skip
14271428
return nil, nil
14281429
}
14291430

1430-
if ext != ".go" && fileListForExt(&dummyPkg, ext) == nil {
1431-
// skip
1431+
if !ctxt.goodOSArchFile(name, allTags) && !ctxt.UseAllFiles {
14321432
return nil, nil
14331433
}
14341434

src/go/build/build_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,13 @@ func TestAllTags(t *testing.T) {
790790
t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
791791
}
792792
}
793+
794+
func TestAllTagsNonSourceFile(t *testing.T) {
795+
p, err := Default.ImportDir("testdata/non_source_tags", 0)
796+
if err != nil {
797+
t.Fatal(err)
798+
}
799+
if len(p.AllTags) > 0 {
800+
t.Errorf("AllTags = %v, want empty", p.AllTags)
801+
}
802+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package non_source_tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package non_source_tags

0 commit comments

Comments
 (0)