From e1125eeafdfd3d7bb12356c66761000bf749bb64 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sun, 25 Jun 2017 18:52:56 -0700 Subject: [PATCH] cmd/gobind: add GOROOT to cmd.Env from ctx.GOROOT In two places gobind launches go commands but does not pass along the system's GOROOT causing the subprocess go's to look in /usr/local/go and fail if GOROOT is not there. Fixes golang/go#18209 Change-Id: Ica9455c0b15ba57afc5699b7757d67aa4231c508 Reviewed-on: https://go-review.googlesource.com/46671 Reviewed-by: Elias Naur --- cmd/gobind/gen.go | 3 ++- cmd/gobind/main.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/gobind/gen.go b/cmd/gobind/gen.go index d0399d3..27f71fb 100644 --- a/cmd/gobind/gen.go +++ b/cmd/gobind/gen.go @@ -180,7 +180,8 @@ func genJavaPackages(ctx *build.Context, dir string, classes []*java.Class, embe "-pkgdir="+filepath.Join(dir, "pkg", ctx.GOOS+"_"+ctx.GOARCH), "Java/...", ) - cmd.Env = append(cmd.Env, "GOPATH="+dir) + cmd.Env = append(os.Environ(), "GOPATH="+dir) + cmd.Env = append(cmd.Env, "GOROOT="+ctx.GOROOT) if out, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("failed to go install the generated Java wrappers: %v: %s", err, string(out)) } diff --git a/cmd/gobind/main.go b/cmd/gobind/main.go index 928a3ac..e4eeb08 100644 --- a/cmd/gobind/main.go +++ b/cmd/gobind/main.go @@ -92,6 +92,7 @@ func main() { cmd := exec.Command("go", "install") cmd.Args = append(cmd.Args, flag.Args()...) cmd.Env = append(os.Environ(), "GOPATH="+ctx.GOPATH) + cmd.Env = append(cmd.Env, "GOROOT="+ctx.GOROOT) if err := cmd.Run(); err != nil { // Only report I/O errors. Errors from go install is expected for as-yet // undefined Java wrappers.