mirror of
https://github.com/golang/go
synced 2024-11-17 04:14:52 -07:00
go/build: set allTags even when short-circuiting x_GOOS_GOARCH.go
Fixes #52053 Change-Id: I0e1f2737f97a4656913b34a731d8de2c77a15b4d Reviewed-on: https://go-review.googlesource.com/c/go/+/396918 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
40504892c1
commit
9743fdd097
@ -1974,6 +1974,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 {
|
||||
// In case we short-circuit on l[n-1].
|
||||
allTags[l[n-2]] = true
|
||||
}
|
||||
return ctxt.matchTag(l[n-1], allTags) && ctxt.matchTag(l[n-2], allTags)
|
||||
}
|
||||
if n >= 1 && (knownOS[l[n-1]] || knownArch[l[n-1]]) {
|
||||
|
@ -731,3 +731,39 @@ func TestCgoImportsIgnored(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #52053. Check that if there is a file x_GOOS_GOARCH.go that both
|
||||
// GOOS and GOARCH show up in the Package.AllTags field. We test both the
|
||||
// case where the file matches and where the file does not match.
|
||||
// The latter case used to fail, incorrectly omitting GOOS.
|
||||
func TestAllTags(t *testing.T) {
|
||||
ctxt := Default
|
||||
ctxt.GOARCH = "arm"
|
||||
ctxt.GOOS = "netbsd"
|
||||
p, err := ctxt.ImportDir("testdata/alltags", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"arm", "netbsd"}
|
||||
if !reflect.DeepEqual(p.AllTags, want) {
|
||||
t.Errorf("AllTags = %v, want %v", p.AllTags, want)
|
||||
}
|
||||
wantFiles := []string{"alltags.go", "x_netbsd_arm.go"}
|
||||
if !reflect.DeepEqual(p.GoFiles, wantFiles) {
|
||||
t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
|
||||
}
|
||||
|
||||
ctxt.GOARCH = "amd64"
|
||||
ctxt.GOOS = "linux"
|
||||
p, err = ctxt.ImportDir("testdata/alltags", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(p.AllTags, want) {
|
||||
t.Errorf("AllTags = %v, want %v", p.AllTags, want)
|
||||
}
|
||||
wantFiles = []string{"alltags.go"}
|
||||
if !reflect.DeepEqual(p.GoFiles, wantFiles) {
|
||||
t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
|
||||
}
|
||||
}
|
||||
|
5
src/go/build/testdata/alltags/alltags.go
vendored
Normal file
5
src/go/build/testdata/alltags/alltags.go
vendored
Normal file
@ -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 alltags
|
5
src/go/build/testdata/alltags/x_netbsd_arm.go
vendored
Normal file
5
src/go/build/testdata/alltags/x_netbsd_arm.go
vendored
Normal file
@ -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 alltags
|
Loading…
Reference in New Issue
Block a user