cmd: replace goBin() with a plain string "go"

This was introduced at https://go-review.googlesource.com/c/mobile/+/191518
originally, but this change was against the decision at
golang/go#26845.

"go" always works even when Go command that name is not "go", like
"go1.14beta1" is used. See also the discussion at golang/go#28043

Change-Id: Ifebe969edaeda0373b2840d25a4f4030509176fa
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214898
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
diff --git a/cmd/gobind/gobind_test.go b/cmd/gobind/gobind_test.go
index 405ac10..c31fce2 100644
--- a/cmd/gobind/gobind_test.go
+++ b/cmd/gobind/gobind_test.go
@@ -78,7 +78,7 @@
 	bin.Close()
 	defer os.Remove(bin.Name())
 	if runtime.GOOS != "android" {
-		if out, err := exec.Command(goBin(), "build", "-o", bin.Name(), "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
+		if out, err := exec.Command("go", "build", "-o", bin.Name(), "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
 			log.Fatalf("gobind build failed: %v: %s", err, out)
 		}
 		gobindBin = bin.Name()
diff --git a/cmd/gobind/main.go b/cmd/gobind/main.go
index 88a6c6e..530032f 100644
--- a/cmd/gobind/main.go
+++ b/cmd/gobind/main.go
@@ -15,7 +15,6 @@
 	"os"
 	"os/exec"
 	"path/filepath"
-	"runtime"
 	"strings"
 
 	"golang.org/x/mobile/internal/importers"
@@ -45,10 +44,6 @@
 	os.Exit(exitStatus)
 }
 
-func goBin() string {
-	return filepath.Join(runtime.GOROOT(), "bin", "go")
-}
-
 func run() {
 	var langs []string
 	if *lang != "" {
@@ -129,7 +124,7 @@
 		// Add a new directory to GOPATH where the file for reverse bindings exist, and recreate allPkg.
 		// It is because the current allPkg did not solve imports for reverse bindings.
 		var gopath string
-		if out, err := exec.Command(goBin(), "env", "GOPATH").Output(); err != nil {
+		if out, err := exec.Command("go", "env", "GOPATH").Output(); err != nil {
 			log.Fatal(err)
 		} else {
 			gopath = string(bytes.TrimSpace(out))
diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go
index c203791..5a74d93 100644
--- a/cmd/gomobile/bind.go
+++ b/cmd/gomobile/bind.go
@@ -227,7 +227,7 @@
 
 // getModuleVersions returns a module information at the directory src.
 func getModuleVersions(targetOS string, targetArch string, src string) (*modfile.File, error) {
-	cmd := exec.Command(goBin(), "list")
+	cmd := exec.Command("go", "list")
 	cmd.Env = append(os.Environ(), "GOOS="+targetOS, "GOARCH="+targetArch)
 
 	tags := buildTags
@@ -308,7 +308,7 @@
 }
 
 func areGoModulesUsed() (bool, error) {
-	out, err := exec.Command(goBin(), "env", "GOMOD").Output()
+	out, err := exec.Command("go", "env", "GOMOD").Output()
 	if err != nil {
 		return false, err
 	}
diff --git a/cmd/gomobile/bind_test.go b/cmd/gomobile/bind_test.go
index 752d9d7..9b5f43c 100644
--- a/cmd/gomobile/bind_test.go
+++ b/cmd/gomobile/bind_test.go
@@ -207,10 +207,10 @@
 	}
 	defer os.RemoveAll(dir)
 
-	if out, err := exec.Command(goBin(), "build", "-o="+dir, "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
+	if out, err := exec.Command("go", "build", "-o="+dir, "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
 		t.Fatalf("%v: %s", err, string(out))
 	}
-	if out, err := exec.Command(goBin(), "build", "-o="+dir, "golang.org/x/mobile/cmd/gomobile").CombinedOutput(); err != nil {
+	if out, err := exec.Command("go", "build", "-o="+dir, "golang.org/x/mobile/cmd/gomobile").CombinedOutput(); err != nil {
 		t.Fatalf("%v: %s", err, string(out))
 	}
 	path := dir
diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go
index 3c33571..450cd22 100644
--- a/cmd/gomobile/build.go
+++ b/cmd/gomobile/build.go
@@ -296,10 +296,7 @@
 }
 
 func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...string) error {
-	cmd := exec.Command(
-		goBin(),
-		subcmd,
-	)
+	cmd := exec.Command("go", subcmd)
 	tags := buildTags
 	targetOS, _, err := parseBuildTarget(buildTarget)
 	if err != nil {
diff --git a/cmd/gomobile/init.go b/cmd/gomobile/init.go
index f71e853..0ada746 100644
--- a/cmd/gomobile/init.go
+++ b/cmd/gomobile/init.go
@@ -321,7 +321,7 @@
 	if val := os.Getenv(name); val != "" {
 		return val
 	}
-	val, err := exec.Command(goBin(), "env", name).Output()
+	val, err := exec.Command("go", "env", name).Output()
 	if err != nil {
 		panic(err) // the Go tool was tested to work earlier
 	}
@@ -338,12 +338,7 @@
 		if env != "" {
 			env += " "
 		}
-		args := make([]string, len(cmd.Args))
-		copy(args, cmd.Args)
-		if args[0] == goBin() {
-			args[0] = "go"
-		}
-		printcmd("%s%s%s", dir, env, strings.Join(args, " "))
+		printcmd("%s%s%s", dir, env, strings.Join(cmd.Args, " "))
 	}
 
 	buf := new(bytes.Buffer)
diff --git a/cmd/gomobile/main.go b/cmd/gomobile/main.go
index a8af7cb..91b90b4 100644
--- a/cmd/gomobile/main.go
+++ b/cmd/gomobile/main.go
@@ -18,8 +18,6 @@
 	"log"
 	"os"
 	"os/exec"
-	"path/filepath"
-	"runtime"
 	"unicode"
 	"unicode/utf8"
 )
@@ -86,12 +84,8 @@
 	os.Exit(2)
 }
 
-func goBin() string {
-	return filepath.Join(runtime.GOROOT(), "bin", "go")
-}
-
 func determineGoVersion() error {
-	goVersionOut, err := exec.Command(goBin(), "version").CombinedOutput()
+	goVersionOut, err := exec.Command("go", "version").CombinedOutput()
 	if err != nil {
 		return fmt.Errorf("'go version' failed: %v, %s", err, goVersionOut)
 	}
diff --git a/cmd/gomobile/version.go b/cmd/gomobile/version.go
index ff23f5c..8c09a44 100644
--- a/cmd/gomobile/version.go
+++ b/cmd/gomobile/version.go
@@ -34,7 +34,7 @@
 			return "", err
 		}
 		bindir := filepath.Dir(bin)
-		cmd := exec.Command(goBin(), "list", "-f", "{{.Stale}}", "golang.org/x/mobile/cmd/gomobile")
+		cmd := exec.Command("go", "list", "-f", "{{.Stale}}", "golang.org/x/mobile/cmd/gomobile")
 		cmd.Env = append(os.Environ(), "GOBIN="+bindir)
 		out, err := cmd.CombinedOutput()
 		if err != nil {
@@ -64,7 +64,7 @@
 }
 
 func mobileRepoRevision() (rev string, err error) {
-	b, err := exec.Command(goBin(), "list", "-f", "{{.Dir}}", "golang.org/x/mobile/app").CombinedOutput()
+	b, err := exec.Command("go", "list", "-f", "{{.Dir}}", "golang.org/x/mobile/app").CombinedOutput()
 	if err != nil {
 		return "", fmt.Errorf("mobile repo not found: %v, %s", err, b)
 	}