Commit 1b53f15e authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

cmd/go: include GOARM and GO386 in computed build ID

Now:
$ GOARCH=arm GOARM=5 go install -x cmd/go
... followed by:
$ GOARCH=arm GOARM= go install -x cmd/go

... actually does work. Previously the second "go install" would reuse
the cached binaries from the GOARM=5 command and not rebuild.
(Or vice versa from GOARM= to GOARM=5)

And do the same for GO386.

Fixes #9737

Change-Id: I9630aab34d06465d5033e6743dfe6592c8247aa0
Reviewed-on: https://go-review.googlesource.com/43855
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 8a2553e3
This diff is collapsed.
......@@ -4138,3 +4138,42 @@ func TestGoTestRaceCoverModeFailures(t *testing.T) {
tg.grepStderr(`-covermode must be "atomic", not "set", when -race is enabled`, "-race -covermode=set was allowed")
tg.grepBothNot("PASS", "something passed")
}
// Issue 9737: verify that GOARM and GO386 affect the computed build ID.
func TestBuildIDContainsArchModeEnv(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}
var tg *testgoData
testWith := func(before, after func()) func(*testing.T) {
return func(t *testing.T) {
tg = testgo(t)
defer tg.cleanup()
tg.tempFile("src/mycmd/x.go", `package main
func main() {}`)
tg.setenv("GOPATH", tg.path("."))
tg.cd(tg.path("src/mycmd"))
tg.setenv("GOOS", "linux")
before()
tg.run("install", "mycmd")
after()
tg.wantStale("mycmd", "build ID mismatch", "should be stale after environment variable change")
}
}
t.Run("386", testWith(func() {
tg.setenv("GOARCH", "386")
tg.setenv("GO386", "387")
}, func() {
tg.setenv("GO386", "")
}))
t.Run("arm", testWith(func() {
tg.setenv("GOARCH", "arm")
tg.setenv("GOARM", "5")
}, func() {
tg.setenv("GOARM", "7")
}))
}
......@@ -7,10 +7,13 @@
package cfg
import (
"fmt"
"go/build"
"os"
"path/filepath"
"runtime"
"cmd/internal/objabi"
)
// These are general "build flags" used by build and other commands.
......@@ -69,6 +72,10 @@ var (
GOROOTbin = filepath.Join(GOROOT, "bin")
GOROOTpkg = filepath.Join(GOROOT, "pkg")
GOROOTsrc = filepath.Join(GOROOT, "src")
// Used in envcmd.MkEnv and build ID computations.
GOARM = fmt.Sprint(objabi.GOARM)
GO386 = objabi.GO386
)
func findGOROOT() string {
......
......@@ -68,9 +68,9 @@ func MkEnv() []cfg.EnvVar {
switch cfg.Goarch {
case "arm":
env = append(env, cfg.EnvVar{Name: "GOARM", Value: os.Getenv("GOARM")})
env = append(env, cfg.EnvVar{Name: "GOARM", Value: cfg.GOARM})
case "386":
env = append(env, cfg.EnvVar{Name: "GO386", Value: os.Getenv("GO386")})
env = append(env, cfg.EnvVar{Name: "GO386", Value: cfg.GO386})
}
cmd := b.GccCmd(".")
......
......@@ -1651,6 +1651,14 @@ func computeBuildID(p *Package) {
base.Fatalf("go: %s", err)
}
fmt.Fprintf(h, "zversion %q\n", string(data))
// Add environment variables that affect code generation.
switch cfg.BuildContext.GOARCH {
case "arm":
fmt.Fprintf(h, "GOARM=%s\n", cfg.GOARM)
case "386":
fmt.Fprintf(h, "GO386=%s\n", cfg.GO386)
}
}
// Include the build IDs of any dependencies in the hash.
......
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