mirror of
https://github.com/golang/go
synced 2024-11-17 02:34:46 -07:00
cmd/dist: consistently use $GOROOT/bin/go instead of just "go"
Also remove existing special cases that transform "go" into gorootBinGo, because they make debugging and code-reviews more difficult: log messages that don't include the full path can mask bugs like #31567, and the reader of the code has to trace through the various call chains to verify that the correct "go" is being used. Instead, we can make the use of the correct "go" command plainly obvious in the code by using one consistent name for it. (Prior to this CL, we had three different names for it: gorootBinGo, "go", and cmdGo. Now we have only one. Updates #31567. Change-Id: Ia9ff27e5e800c79af5a4e9f2803c9ea5ccafbf35 Reviewed-on: https://go-review.googlesource.com/c/go/+/452678 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
13c70b12d7
commit
a0bebffa33
11
src/cmd/dist/build.go
vendored
11
src/cmd/dist/build.go
vendored
@ -1405,7 +1405,6 @@ func cmdbootstrap() {
|
|||||||
setNoOpt()
|
setNoOpt()
|
||||||
goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
|
goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
|
||||||
goBootstrap := pathf("%s/go_bootstrap", tooldir)
|
goBootstrap := pathf("%s/go_bootstrap", tooldir)
|
||||||
cmdGo := pathf("%s/go", gorootBin)
|
|
||||||
if debug {
|
if debug {
|
||||||
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
|
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
|
||||||
copyfile(pathf("%s/compile1", tooldir), pathf("%s/compile", tooldir), writeExec)
|
copyfile(pathf("%s/compile1", tooldir), pathf("%s/compile", tooldir), writeExec)
|
||||||
@ -1488,8 +1487,8 @@ func cmdbootstrap() {
|
|||||||
goInstall(toolenv, goBootstrap, "cmd")
|
goInstall(toolenv, goBootstrap, "cmd")
|
||||||
checkNotStale(nil, goBootstrap, "std")
|
checkNotStale(nil, goBootstrap, "std")
|
||||||
checkNotStale(toolenv, goBootstrap, "cmd")
|
checkNotStale(toolenv, goBootstrap, "cmd")
|
||||||
checkNotStale(nil, cmdGo, "std")
|
checkNotStale(nil, gorootBinGo, "std")
|
||||||
checkNotStale(toolenv, cmdGo, "cmd")
|
checkNotStale(toolenv, gorootBinGo, "cmd")
|
||||||
|
|
||||||
timelog("build", "target toolchain")
|
timelog("build", "target toolchain")
|
||||||
if vflag > 0 {
|
if vflag > 0 {
|
||||||
@ -1507,8 +1506,8 @@ func cmdbootstrap() {
|
|||||||
checkNotStale(toolenv, goBootstrap, append(toolchain, "runtime/internal/sys")...)
|
checkNotStale(toolenv, goBootstrap, append(toolchain, "runtime/internal/sys")...)
|
||||||
checkNotStale(nil, goBootstrap, "std")
|
checkNotStale(nil, goBootstrap, "std")
|
||||||
checkNotStale(toolenv, goBootstrap, "cmd")
|
checkNotStale(toolenv, goBootstrap, "cmd")
|
||||||
checkNotStale(nil, cmdGo, "std")
|
checkNotStale(nil, gorootBinGo, "std")
|
||||||
checkNotStale(toolenv, cmdGo, "cmd")
|
checkNotStale(toolenv, gorootBinGo, "cmd")
|
||||||
if debug {
|
if debug {
|
||||||
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
|
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
|
||||||
checkNotStale(toolenv, goBootstrap, append(toolchain, "runtime/internal/sys")...)
|
checkNotStale(toolenv, goBootstrap, append(toolchain, "runtime/internal/sys")...)
|
||||||
@ -1542,7 +1541,7 @@ func cmdbootstrap() {
|
|||||||
os.Setenv("GOOS", gohostos)
|
os.Setenv("GOOS", gohostos)
|
||||||
os.Setenv("GOARCH", gohostarch)
|
os.Setenv("GOARCH", gohostarch)
|
||||||
os.Setenv("CC", compilerEnvLookup("CC", defaultcc, gohostos, gohostarch))
|
os.Setenv("CC", compilerEnvLookup("CC", defaultcc, gohostos, gohostarch))
|
||||||
goCmd(nil, cmdGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gorootBin, goos, goarch, exe), wrapperPath)
|
goCmd(nil, gorootBinGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gorootBin, goos, goarch, exe), wrapperPath)
|
||||||
// Restore environment.
|
// Restore environment.
|
||||||
// TODO(elias.naur): support environment variables in goCmd?
|
// TODO(elias.naur): support environment variables in goCmd?
|
||||||
os.Setenv("GOOS", goos)
|
os.Setenv("GOOS", goos)
|
||||||
|
29
src/cmd/dist/test.go
vendored
29
src/cmd/dist/test.go
vendored
@ -149,7 +149,7 @@ func (t *tester) run() {
|
|||||||
if t.rebuild {
|
if t.rebuild {
|
||||||
t.out("Building packages and commands.")
|
t.out("Building packages and commands.")
|
||||||
// Force rebuild the whole toolchain.
|
// Force rebuild the whole toolchain.
|
||||||
goInstall(toolenv, "go", append([]string{"-a"}, toolchain...)...)
|
goInstall(toolenv, gorootBinGo, append([]string{"-a"}, toolchain...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !t.listMode {
|
if !t.listMode {
|
||||||
@ -166,10 +166,10 @@ func (t *tester) run() {
|
|||||||
// to break if we don't automatically refresh things here.
|
// to break if we don't automatically refresh things here.
|
||||||
// Rebuilding is a shortened bootstrap.
|
// Rebuilding is a shortened bootstrap.
|
||||||
// See cmdbootstrap for a description of the overall process.
|
// See cmdbootstrap for a description of the overall process.
|
||||||
goInstall(toolenv, "go", toolchain...)
|
goInstall(toolenv, gorootBinGo, toolchain...)
|
||||||
goInstall(toolenv, "go", toolchain...)
|
goInstall(toolenv, gorootBinGo, toolchain...)
|
||||||
goInstall(toolenv, "go", "cmd")
|
goInstall(toolenv, gorootBinGo, "cmd")
|
||||||
goInstall(nil, "go", "std")
|
goInstall(nil, gorootBinGo, "std")
|
||||||
} else {
|
} else {
|
||||||
// The Go builder infrastructure should always begin running tests from a
|
// The Go builder infrastructure should always begin running tests from a
|
||||||
// clean, non-stale state, so there is no need to rebuild the world.
|
// clean, non-stale state, so there is no need to rebuild the world.
|
||||||
@ -179,15 +179,15 @@ func (t *tester) run() {
|
|||||||
// The cache used by dist when building is different from that used when
|
// The cache used by dist when building is different from that used when
|
||||||
// running dist test, so rebuild (but don't install) std and cmd to make
|
// running dist test, so rebuild (but don't install) std and cmd to make
|
||||||
// sure packages without install targets are cached so they are not stale.
|
// sure packages without install targets are cached so they are not stale.
|
||||||
goCmd(toolenv, "go", "build", "cmd") // make sure dependencies of targets are cached
|
goCmd(toolenv, gorootBinGo, "build", "cmd") // make sure dependencies of targets are cached
|
||||||
goCmd(nil, "go", "build", "std")
|
goCmd(nil, gorootBinGo, "build", "std")
|
||||||
checkNotStale(nil, "go", "std")
|
checkNotStale(nil, gorootBinGo, "std")
|
||||||
if builder != "aix-ppc64" {
|
if builder != "aix-ppc64" {
|
||||||
// The aix-ppc64 builder for some reason does not have deterministic cgo
|
// The aix-ppc64 builder for some reason does not have deterministic cgo
|
||||||
// builds, so "cmd" is stale. Fortunately, most of the tests don't care.
|
// builds, so "cmd" is stale. Fortunately, most of the tests don't care.
|
||||||
// TODO(#56896): remove this special case once the builder supports
|
// TODO(#56896): remove this special case once the builder supports
|
||||||
// determistic cgo builds.
|
// determistic cgo builds.
|
||||||
checkNotStale(toolenv, "go", "cmd")
|
checkNotStale(toolenv, gorootBinGo, "cmd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,7 +300,7 @@ func (t *tester) maybeLogMetadata() error {
|
|||||||
//
|
//
|
||||||
// TODO(prattmic): If we split dist bootstrap and dist test then this
|
// TODO(prattmic): If we split dist bootstrap and dist test then this
|
||||||
// could be simplified to directly use internal/sysinfo here.
|
// could be simplified to directly use internal/sysinfo here.
|
||||||
return t.dirCmd(filepath.Join(goroot, "src/cmd/internal/metadata"), "go", []string{"run", "main.go"}).Run()
|
return t.dirCmd(filepath.Join(goroot, "src/cmd/internal/metadata"), gorootBinGo, []string{"run", "main.go"}).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// goTest represents all options to a "go test" command. The final command will
|
// goTest represents all options to a "go test" command. The final command will
|
||||||
@ -1077,9 +1077,6 @@ func flattenCmdline(cmdline []interface{}) (bin string, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bin = list[0]
|
bin = list[0]
|
||||||
if bin == "go" {
|
|
||||||
bin = gorootBinGo
|
|
||||||
}
|
|
||||||
return bin, list[1:]
|
return bin, list[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1354,7 +1351,7 @@ func (t *tester) registerCgoTests() {
|
|||||||
// running in parallel with earlier tests, or if it has some other reason
|
// running in parallel with earlier tests, or if it has some other reason
|
||||||
// for needing the earlier tests to be done.
|
// for needing the earlier tests to be done.
|
||||||
func (t *tester) runPending(nextTest *distTest) {
|
func (t *tester) runPending(nextTest *distTest) {
|
||||||
checkNotStale(nil, "go", "std")
|
checkNotStale(nil, gorootBinGo, "std")
|
||||||
worklist := t.worklist
|
worklist := t.worklist
|
||||||
t.worklist = nil
|
t.worklist = nil
|
||||||
for _, w := range worklist {
|
for _, w := range worklist {
|
||||||
@ -1412,7 +1409,7 @@ func (t *tester) runPending(nextTest *distTest) {
|
|||||||
log.Printf("Failed: %v", w.err)
|
log.Printf("Failed: %v", w.err)
|
||||||
t.failed = true
|
t.failed = true
|
||||||
}
|
}
|
||||||
checkNotStale(nil, "go", "std")
|
checkNotStale(nil, gorootBinGo, "std")
|
||||||
}
|
}
|
||||||
if t.failed && !t.keepGoing {
|
if t.failed && !t.keepGoing {
|
||||||
fatalf("FAILED")
|
fatalf("FAILED")
|
||||||
@ -1612,7 +1609,7 @@ func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
|
|||||||
os.Remove(runtest.exe)
|
os.Remove(runtest.exe)
|
||||||
})
|
})
|
||||||
|
|
||||||
cmd := t.dirCmd("test", "go", "build", "-o", runtest.exe, "run.go")
|
cmd := t.dirCmd("test", gorootBinGo, "build", "-o", runtest.exe, "run.go")
|
||||||
setEnv(cmd, "GOOS", gohostos)
|
setEnv(cmd, "GOOS", gohostos)
|
||||||
setEnv(cmd, "GOARCH", gohostarch)
|
setEnv(cmd, "GOARCH", gohostarch)
|
||||||
runtest.err = cmd.Run()
|
runtest.err = cmd.Run()
|
||||||
|
6
src/cmd/dist/util.go
vendored
6
src/cmd/dist/util.go
vendored
@ -75,11 +75,7 @@ func runEnv(dir string, mode int, env []string, cmd ...string) string {
|
|||||||
errprintf("run: %s\n", strings.Join(cmd, " "))
|
errprintf("run: %s\n", strings.Join(cmd, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
bin := cmd[0]
|
xcmd := exec.Command(cmd[0], cmd[1:]...)
|
||||||
if bin == "go" {
|
|
||||||
bin = gorootBinGo
|
|
||||||
}
|
|
||||||
xcmd := exec.Command(bin, cmd[1:]...)
|
|
||||||
if env != nil {
|
if env != nil {
|
||||||
xcmd.Env = append(os.Environ(), env...)
|
xcmd.Env = append(os.Environ(), env...)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user