]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: ignore files by extension before matching on name
authorIan Lance Taylor <iant@golang.org>
Sat, 29 Oct 2022 00:23:58 +0000 (17:23 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 1 Nov 2022 19:48:43 +0000 (19:48 +0000)
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 <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/go/build/build.go
src/go/build/build_test.go
src/go/build/testdata/non_source_tags/non_source_tags.go [new file with mode: 0644]
src/go/build/testdata/non_source_tags/x_arm.go.ignore [new file with mode: 0644]

index 28c74455809573fe03794de8836350249a1f451e..1cb10f50bf9e7379bd5cbbf972964857b14dcc96 100644 (file)
@@ -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
        }
 
index 1b0a371d67be250f511638847b1793abedfc6b08..332237771515411aa6c1c701068d901053a939fe 100644 (file)
@@ -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 (file)
index 0000000..068acc4
--- /dev/null
@@ -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 (file)
index 0000000..068acc4
--- /dev/null
@@ -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