Skip to content

Commit 28fa1da

Browse files
mengzhuogriesemer
authored andcommitted
cmd/api: explicit tagKey with GOOS and GOARCH
The origin tagKey is just dirname if no tags input which will cause pkgCache missmatch if other imported pkg explicit on GOARCH or GOOS This CL will add GOOS and GOARCH to tagKey Fixes golang#8425 Fixes golang#21181 Change-Id: Ifc189cf6746d753ad7c7e5bb60621297fc0a4e35 Reviewed-on: https://go-review.googlesource.com/c/138315 Reviewed-by: Robert Griesemer <gri@golang.org>
1 parent 415e948 commit 28fa1da

File tree

9 files changed

+65
-4
lines changed

9 files changed

+65
-4
lines changed

api/except.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pkg os, const ModeType = 2399141888
66
pkg os, const ModeType = 2399666176
77
pkg os (linux-arm), const O_SYNC = 4096
88
pkg os (linux-arm-cgo), const O_SYNC = 4096
9+
pkg os (linux-arm), const O_SYNC = 1052672
10+
pkg os (linux-arm-cgo), const O_SYNC = 1052672
911
pkg syscall (darwin-386), const ImplementsGetwd = false
1012
pkg syscall (darwin-386), func Fchflags(string, int) error
1113
pkg syscall (darwin-386-cgo), const ImplementsGetwd = false

src/cmd/api/goapi.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,7 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) {
385385
return f, nil
386386
}
387387

388-
// The package cache doesn't operate correctly in rare (so far artificial)
389-
// circumstances (issue 8425). Disable before debugging non-obvious errors
390-
// from the type-checker.
388+
// Disable before debugging non-obvious errors from the type-checker.
391389
const usePkgCache = true
392390

393391
var (
@@ -398,7 +396,7 @@ var (
398396
// tagKey returns the tag-based key to use in the pkgCache.
399397
// It is a comma-separated string; the first part is dir, the rest tags.
400398
// The satisfied tags are derived from context but only those that
401-
// matter (the ones listed in the tags argument) are used.
399+
// matter (the ones listed in the tags argument plus GOOS and GOARCH) are used.
402400
// The tags list, which came from go/build's Package.AllTags,
403401
// is known to be sorted.
404402
func tagKey(dir string, context *build.Context, tags []string) string {
@@ -414,9 +412,17 @@ func tagKey(dir string, context *build.Context, tags []string) string {
414412
}
415413
// TODO: ReleaseTags (need to load default)
416414
key := dir
415+
416+
// explicit on GOOS and GOARCH as global cache will use "all" cached packages for
417+
// an indirect imported package. See https://github.com/golang/go/issues/21181
418+
// for more detail.
419+
tags = append(tags, context.GOOS, context.GOARCH)
420+
sort.Strings(tags)
421+
417422
for _, tag := range tags {
418423
if ctags[tag] {
419424
key += "," + tag
425+
ctags[tag] = false
420426
}
421427
}
422428
return key

src/cmd/api/goapi_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,18 @@ func BenchmarkAll(b *testing.B) {
188188
}
189189
}
190190
}
191+
192+
func TestIssue21181(t *testing.T) {
193+
for _, c := range contexts {
194+
c.Compiler = build.Default.Compiler
195+
}
196+
for _, context := range contexts {
197+
w := NewWalker(context, "testdata/src/issue21181")
198+
pkg, err := w.Import("p")
199+
if err != nil {
200+
t.Fatalf("%s: (%s-%s) %s %v", err, context.GOOS, context.GOARCH,
201+
pkg.Name(), w.imported)
202+
}
203+
w.export(pkg)
204+
}
205+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dep
2+
3+
type Interface interface {
4+
N([]byte)
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package dep
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package indirect
2+
3+
import "dep"
4+
5+
func F(dep.Interface) {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package p
2+
3+
import (
4+
"dep"
5+
)
6+
7+
type algo struct {
8+
indrt func(dep.Interface)
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package p
2+
3+
import "indirect"
4+
5+
var in = []algo{
6+
{indirect.F},
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +build !amd64
2+
3+
package p
4+
5+
import (
6+
"indirect"
7+
)
8+
9+
var in = []algo{
10+
{indirect.F},
11+
}

0 commit comments

Comments
 (0)