]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: call ctxt.match for checking file name constraints
authorZhongpeng Lin <zplin@uber.com>
Mon, 21 May 2018 19:04:00 +0000 (19:04 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 22 May 2018 18:47:03 +0000 (18:47 +0000)
This makes the checking of build tags in file names consistent to that of the build tags in `// +build` line.

Fixed #25461

Change-Id: Iba14d1050f8aba44e7539ab3b8711af1980ccfe4
GitHub-Last-Rev: 11b14e239dd85e11e669919aab45494aee7c59a3
GitHub-Pull-Request: golang/go#25480
Reviewed-on: https://go-review.googlesource.com/113818
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/go/build/build.go
src/go/build/build_test.go

index 38380d323d244b24b630e0ca6ca2da40db4c93a1..b19df28a6357cd171587cbba8fd8cc2500264e29 100644 (file)
@@ -1565,32 +1565,10 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
        }
        n := len(l)
        if n >= 2 && knownOS[l[n-2]] && knownArch[l[n-1]] {
-               if allTags != nil {
-                       allTags[l[n-2]] = true
-                       allTags[l[n-1]] = true
-               }
-               if l[n-1] != ctxt.GOARCH {
-                       return false
-               }
-               if ctxt.GOOS == "android" && l[n-2] == "linux" {
-                       return true
-               }
-               return l[n-2] == ctxt.GOOS
+               return ctxt.match(l[n-1], allTags) && ctxt.match(l[n-2], allTags)
        }
-       if n >= 1 && knownOS[l[n-1]] {
-               if allTags != nil {
-                       allTags[l[n-1]] = true
-               }
-               if ctxt.GOOS == "android" && l[n-1] == "linux" {
-                       return true
-               }
-               return l[n-1] == ctxt.GOOS
-       }
-       if n >= 1 && knownArch[l[n-1]] {
-               if allTags != nil {
-                       allTags[l[n-1]] = true
-               }
-               return l[n-1] == ctxt.GOARCH
+       if n >= 1 && (knownOS[l[n-1]] || knownArch[l[n-1]]) {
+               return ctxt.match(l[n-1], allTags)
        }
        return true
 }
index cb2ae3c77597c422c4895158388a53599e5d44d3..3d4c92dcecf896c4fc717506e4700293801b79cd 100644 (file)
@@ -176,6 +176,18 @@ func TestShouldBuild(t *testing.T) {
        }
 }
 
+func TestGoodOSArchFile(t *testing.T) {
+       ctx := &Context{BuildTags: []string{"linux"}, GOOS:"darwin"}
+       m := map[string]bool{}
+       want := map[string]bool{"linux": true}
+       if !ctx.goodOSArchFile("hello_linux.go", m) {
+               t.Errorf("goodOSArchFile(hello_linux.go) = false, want true")
+       }
+       if !reflect.DeepEqual(m, want) {
+               t.Errorf("goodOSArchFile(hello_linux.go) tags = %v, want %v", m, want)
+       }
+}
+
 type readNopCloser struct {
        io.Reader
 }