diff options
author | Felix Lange <fjl@twurst.com> | 2017-08-07 21:50:31 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2017-08-07 22:08:50 +0800 |
commit | f59a49d591e3311b030b57d2be488a6303a3747a (patch) | |
tree | bf98aa63d62d02226bb0f4a186127b4741a177ca /internal | |
parent | 46cf0a616b597dfb8b1feff80ad58b6eb81e57d5 (diff) | |
download | go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.tar go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.tar.gz go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.tar.bz2 go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.tar.lz go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.tar.xz go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.tar.zst go-tangerine-f59a49d591e3311b030b57d2be488a6303a3747a.zip |
internal/build: add GoTool and document why it uses GOROOT
Diffstat (limited to 'internal')
-rw-r--r-- | internal/build/util.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/internal/build/util.go b/internal/build/util.go index 44f6760b9..ade9cbe93 100644 --- a/internal/build/util.go +++ b/internal/build/util.go @@ -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 // vendored packages. func ExpandPackagesNoVendor(patterns []string) []string { @@ -148,8 +161,7 @@ func ExpandPackagesNoVendor(patterns []string) []string { } } if expand { - args := append([]string{"list"}, patterns...) - cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...) + cmd := GoTool("list", patterns...) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("package listing failed: %v\n%s", err, string(out)) |