diff options
author | Meng Zhuo <mengzhuo1203@gmail.com> | 2018-10-04 16:46:22 +0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2018-10-05 17:53:43 +0000 |
commit | 28fa1da9db8eedf079f1b83fd39383e17b3d7e68 (patch) | |
tree | 6824c561af5c9587714a99f71d82e7a49681ff37 /src/cmd/api/goapi.go | |
parent | 415e948eaea05930b2a16bab6af9e38b24e8414b (diff) | |
download | go-git-28fa1da9db8eedf079f1b83fd39383e17b3d7e68.tar.gz |
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 #8425
Fixes #21181
Change-Id: Ifc189cf6746d753ad7c7e5bb60621297fc0a4e35
Reviewed-on: https://go-review.googlesource.com/c/138315
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/api/goapi.go')
-rw-r--r-- | src/cmd/api/goapi.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 8cc78c01ed..9698f25b51 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -385,9 +385,7 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) { return f, nil } -// The package cache doesn't operate correctly in rare (so far artificial) -// circumstances (issue 8425). Disable before debugging non-obvious errors -// from the type-checker. +// Disable before debugging non-obvious errors from the type-checker. const usePkgCache = true var ( @@ -398,7 +396,7 @@ var ( // tagKey returns the tag-based key to use in the pkgCache. // It is a comma-separated string; the first part is dir, the rest tags. // The satisfied tags are derived from context but only those that -// matter (the ones listed in the tags argument) are used. +// matter (the ones listed in the tags argument plus GOOS and GOARCH) are used. // The tags list, which came from go/build's Package.AllTags, // is known to be sorted. func tagKey(dir string, context *build.Context, tags []string) string { @@ -414,9 +412,17 @@ func tagKey(dir string, context *build.Context, tags []string) string { } // TODO: ReleaseTags (need to load default) key := dir + + // explicit on GOOS and GOARCH as global cache will use "all" cached packages for + // an indirect imported package. See https://github.com/golang/go/issues/21181 + // for more detail. + tags = append(tags, context.GOOS, context.GOARCH) + sort.Strings(tags) + for _, tag := range tags { if ctags[tag] { key += "," + tag + ctags[tag] = false } } return key |