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 <elias.naur@gmail.com>
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 @@
 		"-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 @@
 	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.