cmd/gomobile: say why a version is unknown
Fixes golang/go#13238 Change-Id: Ib44f9833891d721843a0fa255d9a86f1c7d43902 Reviewed-on: https://go-review.googlesource.com/16929 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
parent
8835366576
commit
a6a27b7fc9
@ -27,25 +27,25 @@ func runVersion(cmd *command) (err error) {
|
||||
// source code in GOPATH. If they don't match, currently there is no
|
||||
// way to reliably identify the revision number this binary was built
|
||||
// against.
|
||||
version := func() string {
|
||||
version, err := func() (string, error) {
|
||||
bin, err := exec.LookPath(os.Args[0])
|
||||
if err != nil {
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
bindir := filepath.Dir(bin)
|
||||
cmd := exec.Command("go", "install", "-x", "-n", "golang.org/x/mobile/cmd/gomobile")
|
||||
cmd.Env = append(os.Environ(), "GOBIN="+bindir)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil || len(out) != 0 {
|
||||
return ""
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot test gomobile binary: %v, %s", err, out)
|
||||
}
|
||||
if rev, err := mobileRepoRevision(); err == nil {
|
||||
return rev
|
||||
if len(out) != 0 {
|
||||
return "", fmt.Errorf("binary is out of date, re-install it")
|
||||
}
|
||||
return ""
|
||||
return mobileRepoRevision()
|
||||
}()
|
||||
if version == "" {
|
||||
fmt.Println("gomobile version unknown")
|
||||
if err != nil {
|
||||
fmt.Printf("gomobile version unknown: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ func runVersion(cmd *command) (err error) {
|
||||
func mobileRepoRevision() (rev string, err error) {
|
||||
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", err)
|
||||
return "", fmt.Errorf("mobile repo not found: %v, %s", err, b)
|
||||
}
|
||||
|
||||
repo := filepath.Dir(string(b))
|
||||
@ -74,7 +74,7 @@ func mobileRepoRevision() (rev string, err error) {
|
||||
}
|
||||
revision, err := exec.Command("git", "log", "-n", "1", "--format=format: +%h %cd", "HEAD").CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", fmt.Errorf("mobile repo git log failed: %v, %s", err, revision)
|
||||
}
|
||||
return string(bytes.Trim(revision, " \t\r\n")), nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user