Commit 3d15f768 authored by Zhongpeng Lin's avatar Zhongpeng Lin Committed by Brad Fitzpatrick

go/build: call ctxt.match for checking file name constraints

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a10d3906
......@@ -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
}
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 ctxt.match(l[n-1], allTags) && ctxt.match(l[n-2], allTags)
}
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
}
......
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment