all: use GOROOT/bin/go instead of go everywhere
This is a non-test code version of CL 191517. Using 'go' command in tests is confusing when using a different version of Go (e.g., go1.13rc1). Use GOROOT/bin/go so that the same Go is used. Change-Id: Id5937cfa6dd6d3164d5f774e3fc0fd15b7f613b5 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/191518 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
parent
fe31116dde
commit
30c70e3810
@ -47,8 +47,7 @@ func testMain(m *testing.M) int {
|
|||||||
bin.Close()
|
bin.Close()
|
||||||
defer os.Remove(bin.Name())
|
defer os.Remove(bin.Name())
|
||||||
if runtime.GOOS != "android" {
|
if runtime.GOOS != "android" {
|
||||||
gocmd := filepath.Join(runtime.GOROOT(), "bin", "go")
|
if out, err := exec.Command(goBin(), "build", "-o", bin.Name(), "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
|
||||||
if out, err := exec.Command(gocmd, "build", "-o", bin.Name(), "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
|
|
||||||
log.Fatalf("gobind build failed: %v: %s", err, out)
|
log.Fatalf("gobind build failed: %v: %s", err, out)
|
||||||
}
|
}
|
||||||
gobindBin = bin.Name()
|
gobindBin = bin.Name()
|
||||||
@ -110,8 +109,7 @@ type Struct struct{
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gocmd := filepath.Join(runtime.GOROOT(), "bin", "go")
|
gopath, err := exec.Command(goBin(), "env", "GOPATH").Output()
|
||||||
gopath, err := exec.Command(gocmd, "env", "GOPATH").Output()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/mobile/internal/importers"
|
"golang.org/x/mobile/internal/importers"
|
||||||
@ -46,6 +47,10 @@ func main() {
|
|||||||
os.Exit(exitStatus)
|
os.Exit(exitStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func goBin() string {
|
||||||
|
return filepath.Join(runtime.GOROOT(), "bin", "go")
|
||||||
|
}
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
var langs []string
|
var langs []string
|
||||||
if *lang != "" {
|
if *lang != "" {
|
||||||
@ -104,7 +109,7 @@ func run() {
|
|||||||
|
|
||||||
// Determine GOPATH from go env GOPATH in case the default $HOME/go GOPATH
|
// Determine GOPATH from go env GOPATH in case the default $HOME/go GOPATH
|
||||||
// is in effect.
|
// is in effect.
|
||||||
if out, err := exec.Command("go", "env", "GOPATH").Output(); err != nil {
|
if out, err := exec.Command(goBin(), "env", "GOPATH").Output(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.GOPATH = string(bytes.TrimSpace(out))
|
ctx.GOPATH = string(bytes.TrimSpace(out))
|
||||||
|
@ -287,7 +287,7 @@ func goInstall(srcs []string, env []string, args ...string) error {
|
|||||||
|
|
||||||
func goCmd(subcmd string, srcs []string, env []string, args ...string) error {
|
func goCmd(subcmd string, srcs []string, env []string, args ...string) error {
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"go",
|
goBin(),
|
||||||
subcmd,
|
subcmd,
|
||||||
)
|
)
|
||||||
if len(ctx.BuildTags) > 0 {
|
if len(ctx.BuildTags) > 0 {
|
||||||
|
@ -321,7 +321,7 @@ func goEnv(name string) string {
|
|||||||
if val := os.Getenv(name); val != "" {
|
if val := os.Getenv(name); val != "" {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
val, err := exec.Command("go", "env", name).Output()
|
val, err := exec.Command(goBin(), "env", name).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // the Go tool was tested to work earlier
|
panic(err) // the Go tool was tested to work earlier
|
||||||
}
|
}
|
||||||
@ -338,7 +338,12 @@ func runCmd(cmd *exec.Cmd) error {
|
|||||||
if env != "" {
|
if env != "" {
|
||||||
env += " "
|
env += " "
|
||||||
}
|
}
|
||||||
printcmd("%s%s%s", dir, env, strings.Join(cmd.Args, " "))
|
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, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
@ -18,6 +18,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@ -84,12 +86,12 @@ func main() {
|
|||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func goBin() string {
|
||||||
|
return filepath.Join(runtime.GOROOT(), "bin", "go")
|
||||||
|
}
|
||||||
|
|
||||||
func determineGoVersion() error {
|
func determineGoVersion() error {
|
||||||
gobin, err := exec.LookPath("go")
|
goVersionOut, err := exec.Command(goBin(), "version").CombinedOutput()
|
||||||
if err != nil {
|
|
||||||
return errors.New("go not found")
|
|
||||||
}
|
|
||||||
goVersionOut, err = exec.Command(gobin, "version").CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("'go version' failed: %v, %s", err, goVersionOut)
|
return fmt.Errorf("'go version' failed: %v, %s", err, goVersionOut)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func runVersion(cmd *command) (err error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
bindir := filepath.Dir(bin)
|
bindir := filepath.Dir(bin)
|
||||||
cmd := exec.Command("go", "list", "-f", "{{.Stale}}", "golang.org/x/mobile/cmd/gomobile")
|
cmd := exec.Command(goBin(), "list", "-f", "{{.Stale}}", "golang.org/x/mobile/cmd/gomobile")
|
||||||
cmd.Env = append(os.Environ(), "GOBIN="+bindir)
|
cmd.Env = append(os.Environ(), "GOBIN="+bindir)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -64,7 +64,7 @@ func runVersion(cmd *command) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mobileRepoRevision() (rev string, err error) {
|
func mobileRepoRevision() (rev string, err error) {
|
||||||
b, err := exec.Command("go", "list", "-f", "{{.Dir}}", "golang.org/x/mobile/app").CombinedOutput()
|
b, err := exec.Command(goBin(), "list", "-f", "{{.Dir}}", "golang.org/x/mobile/app").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("mobile repo not found: %v, %s", err, b)
|
return "", fmt.Errorf("mobile repo not found: %v, %s", err, b)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user