cmd/go: fix experiment isolation in cache key

In general we don't assume that the go command knows the
specific version of the compiler being used, including which
experiments the compiler was built with. Let the compiler tell us,
instead of importing cmd/internal/objabi from cmd/go.

Replacement for CL 128735.

Change-Id: Iaa07f46e19764d0fb14a1c89979bea7bb7139b9c
Reviewed-on: https://go-review.googlesource.com/c/149338
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Russ Cox 2018-11-13 10:09:22 -05:00
parent f53a986856
commit 94f7795d05
2 changed files with 11 additions and 8 deletions

View file

@ -18,7 +18,6 @@ import (
"cmd/go/internal/load"
"cmd/go/internal/str"
"cmd/internal/buildid"
"cmd/internal/objabi"
)
// Build IDs
@ -208,11 +207,6 @@ func (b *Builder) toolID(name string) string {
id = f[2]
}
// For the compiler, add any experiments.
if name == "compile" {
id += " " + objabi.Expstring()
}
b.id.Lock()
b.toolIDCache[name] = id
b.id.Unlock()

View file

@ -100,9 +100,18 @@ func (versionFlag) Set(s string) error {
// for releases, but during development we include the full
// build ID of the binary, so that if the compiler is changed and
// rebuilt, we notice and rebuild all packages.
if s == "full" && strings.HasPrefix(Version, "devel") {
p += " buildID=" + buildID
if s == "full" {
// If there's an active experiment, include that,
// to distinguish go1.10.2 with an experiment
// from go1.10.2 without an experiment.
if x := Expstring(); x != "" {
p += " " + x
}
if strings.HasPrefix(Version, "devel") {
p += " buildID=" + buildID
}
}
fmt.Printf("%s version %s%s%s\n", name, Version, sep, p)
os.Exit(0)
return nil