internal/build: add GoTool and document why it uses GOROOT
This commit is contained in:
parent
46cf0a616b
commit
f59a49d591
|
@ -250,10 +250,7 @@ func goTool(subcmd string, args ...string) *exec.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
func goToolArch(arch string, subcmd string, args ...string) *exec.Cmd {
|
func goToolArch(arch string, subcmd string, args ...string) *exec.Cmd {
|
||||||
gocmd := filepath.Join(runtime.GOROOT(), "bin", "go")
|
cmd := build.GoTool(subcmd, args...)
|
||||||
cmd := exec.Command(gocmd, subcmd)
|
|
||||||
cmd.Args = append(cmd.Args, args...)
|
|
||||||
|
|
||||||
if subcmd == "build" || subcmd == "install" || subcmd == "test" {
|
if subcmd == "build" || subcmd == "install" || subcmd == "test" {
|
||||||
// Go CGO has a Windows linker error prior to 1.8 (https://github.com/golang/go/issues/8756).
|
// Go CGO has a Windows linker error prior to 1.8 (https://github.com/golang/go/issues/8756).
|
||||||
// Work around issue by allowing multiple definitions for <1.8 builds.
|
// Work around issue by allowing multiple definitions for <1.8 builds.
|
||||||
|
|
|
@ -138,6 +138,19 @@ func CopyFile(dst, src string, mode os.FileMode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GoTool returns the command that runs a go tool. This uses go from GOROOT instead of PATH
|
||||||
|
// so that go commands executed by build use the same version of Go as the 'host' that runs
|
||||||
|
// build code. e.g.
|
||||||
|
//
|
||||||
|
// /usr/lib/go-1.8/bin/go run build/ci.go ...
|
||||||
|
//
|
||||||
|
// runs using go 1.8 and invokes go 1.8 tools from the same GOROOT. This is also important
|
||||||
|
// because runtime.Version checks on the host should match the tools that are run.
|
||||||
|
func GoTool(tool string, args ...string) *exec.Cmd {
|
||||||
|
args = append([]string{tool}, args...)
|
||||||
|
return exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
|
||||||
|
}
|
||||||
|
|
||||||
// ExpandPackagesNoVendor expands a cmd/go import path pattern, skipping
|
// ExpandPackagesNoVendor expands a cmd/go import path pattern, skipping
|
||||||
// vendored packages.
|
// vendored packages.
|
||||||
func ExpandPackagesNoVendor(patterns []string) []string {
|
func ExpandPackagesNoVendor(patterns []string) []string {
|
||||||
|
@ -148,8 +161,7 @@ func ExpandPackagesNoVendor(patterns []string) []string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if expand {
|
if expand {
|
||||||
args := append([]string{"list"}, patterns...)
|
cmd := GoTool("list", patterns...)
|
||||||
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
|
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("package listing failed: %v\n%s", err, string(out))
|
log.Fatalf("package listing failed: %v\n%s", err, string(out))
|
||||||
|
|
Loading…
Reference in New Issue