From e4cad488a2baa509a071e4e9a4432ceca12fb8a0 Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Sat, 10 Feb 2018 22:32:40 +0000 Subject: [PATCH] pkg/golang: use GOROOT to find the correct compiler. Previously, if one set the GOROOT environment variable, we would not actually use the the compiler found in $GOROOT/bin/go, but the compiler found in $PATH. build.Context.GOROOT is by default the compiled code's GOROOT, unless the GOROOT environment variable is set. --- pkg/golang/build.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/golang/build.go b/pkg/golang/build.go index 93308a24d3..abc793b9b4 100644 --- a/pkg/golang/build.go +++ b/pkg/golang/build.go @@ -53,14 +53,17 @@ type ListPackage struct { ImportPath string } +func (c Environ) goCmd(args ...string) *exec.Cmd { + cmd := exec.Command(filepath.Join(c.GOROOT, "bin", "go"), args...) + cmd.Env = append(os.Environ(), c.Env()...) + return cmd +} + // Deps lists all dependencies of the package given by `importPath`. func (c Environ) Deps(importPath string) (*ListPackage, error) { // The output of this is almost the same as build.Import, except for // the dependencies. - cmd := exec.Command("go", "list", "-json", importPath) - env := os.Environ() - env = append(env, c.Env()...) - cmd.Env = env + cmd := c.goCmd("list", "-json", importPath) out, err := cmd.CombinedOutput() if err != nil { return nil, err @@ -126,9 +129,8 @@ func (c Environ) Build(importPath string, binaryPath string, opts BuildOpts) err // We always set the working directory, so this is always '.'. args = append(args, ".") - cmd := exec.Command("go", args...) + cmd := c.goCmd(args...) cmd.Dir = p.Dir - cmd.Env = append(os.Environ(), c.Env()...) if o, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("error building go package %v: %v, %v", importPath, string(o), err)