cmd/gomobile: test for XCode in gomobile init

Previously, gomobile init assumed that the XCode developer tools
were available when running on darwin. That is not always the case,
in particular for Android developers on macOS.

Replace the GOOS check with an explicit check for the xcrun binary.

Change-Id: Ie5ae917288932cc641a17f904ed9822a105367cc
Reviewed-on: https://go-review.googlesource.com/35852
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur
2017-01-28 13:36:49 +00:00
parent c243211167
commit e7109766ab
4 changed files with 11 additions and 7 deletions
+2 -3
View File
@@ -14,7 +14,6 @@ import (
"os"
"os/exec"
"regexp"
"runtime"
"strings"
)
@@ -110,8 +109,8 @@ func runBuild(cmd *command) (err error) {
}
case "darwin":
// TODO: use targetArchs?
if runtime.GOOS != "darwin" {
return fmt.Errorf("-target=ios requires darwin host")
if !xcodeAvailable() {
return fmt.Errorf("-target=ios requires XCode")
}
if pkg.Name != "main" {
if err := goBuild(pkg.ImportPath, darwinArmEnv); err != nil {
+6 -1
View File
@@ -149,7 +149,7 @@ func envInit() (err error) {
}
}
if runtime.GOOS != "darwin" {
if !xcodeAvailable() {
return nil
}
@@ -378,3 +378,8 @@ var ndk = ndkConfig{
minGoVer: go1_6,
},
}
func xcodeAvailable() bool {
_, err := exec.LookPath("xcrun")
return err == nil
}
+2 -2
View File
@@ -315,8 +315,8 @@ var commonPkgs = []string{
}
func installDarwin() error {
if goos != "darwin" {
return nil // Only build iOS compilers on OS X.
if !xcodeAvailable() {
return nil
}
if err := installStd(darwinArmEnv); err != nil {
return err
+1 -1
View File
@@ -51,7 +51,7 @@ func runVersion(cmd *command) (err error) {
// Supported platforms
platforms := "android"
if goos == "darwin" {
if xcodeAvailable() {
platforms = "android,ios"
}