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>
This commit is contained in:
Родитель
b9f03b3fa3
Коммит
56347cccba
|
@ -78,7 +78,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" {
|
||||||
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)
|
log.Fatalf("gobind build failed: %v: %s", err, out)
|
||||||
}
|
}
|
||||||
gobindBin = bin.Name()
|
gobindBin = bin.Name()
|
||||||
|
|
|
@ -15,7 +15,6 @@ 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"
|
||||||
|
@ -45,10 +44,6 @@ 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 != "" {
|
||||||
|
@ -129,7 +124,7 @@ func run() {
|
||||||
// Add a new directory to GOPATH where the file for reverse bindings exist, and recreate allPkg.
|
// 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.
|
// It is because the current allPkg did not solve imports for reverse bindings.
|
||||||
var gopath string
|
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)
|
log.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
gopath = string(bytes.TrimSpace(out))
|
gopath = string(bytes.TrimSpace(out))
|
||||||
|
|
|
@ -227,7 +227,7 @@ func packagesConfig(targetOS string) *packages.Config {
|
||||||
|
|
||||||
// getModuleVersions returns a module information at the directory src.
|
// getModuleVersions returns a module information at the directory src.
|
||||||
func getModuleVersions(targetOS string, targetArch string, src string) (*modfile.File, error) {
|
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)
|
cmd.Env = append(os.Environ(), "GOOS="+targetOS, "GOARCH="+targetArch)
|
||||||
|
|
||||||
tags := buildTags
|
tags := buildTags
|
||||||
|
@ -308,7 +308,7 @@ func writeGoMod(targetOS string, targetArch string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func areGoModulesUsed() (bool, error) {
|
func areGoModulesUsed() (bool, error) {
|
||||||
out, err := exec.Command(goBin(), "env", "GOMOD").Output()
|
out, err := exec.Command("go", "env", "GOMOD").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,10 +207,10 @@ func TestBindWithGoModules(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
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))
|
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))
|
t.Fatalf("%v: %s", err, string(out))
|
||||||
}
|
}
|
||||||
path := dir
|
path := dir
|
||||||
|
|
|
@ -296,10 +296,7 @@ func goCmd(subcmd string, srcs []string, env []string, args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...string) error {
|
func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...string) error {
|
||||||
cmd := exec.Command(
|
cmd := exec.Command("go", subcmd)
|
||||||
goBin(),
|
|
||||||
subcmd,
|
|
||||||
)
|
|
||||||
tags := buildTags
|
tags := buildTags
|
||||||
targetOS, _, err := parseBuildTarget(buildTarget)
|
targetOS, _, err := parseBuildTarget(buildTarget)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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(goBin(), "env", name).Output()
|
val, err := exec.Command("go", "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,12 +338,7 @@ func runCmd(cmd *exec.Cmd) error {
|
||||||
if env != "" {
|
if env != "" {
|
||||||
env += " "
|
env += " "
|
||||||
}
|
}
|
||||||
args := make([]string, len(cmd.Args))
|
printcmd("%s%s%s", dir, env, strings.Join(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,8 +18,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
@ -86,12 +84,8 @@ func main() {
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func goBin() string {
|
|
||||||
return filepath.Join(runtime.GOROOT(), "bin", "go")
|
|
||||||
}
|
|
||||||
|
|
||||||
func determineGoVersion() error {
|
func determineGoVersion() error {
|
||||||
goVersionOut, err := exec.Command(goBin(), "version").CombinedOutput()
|
goVersionOut, err := exec.Command("go", "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(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)
|
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(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 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче