From 08407a4b1bec72f1c64076393f5db9829be9b7fe Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Wed, 8 Jul 2015 14:36:07 -0600 Subject: [PATCH] cmd/gomobile: don't build apps that doesn't import the app package In order to keep consistency with target=android, this CL turns off gomobile build support for target=ios for programs that don't import golang.org/x/mobile/app. Change-Id: I423b042144aecfdc127726d0b97733c4d6532a81 Reviewed-on: https://go-review.googlesource.com/11985 Reviewed-by: David Crawshaw --- cmd/gomobile/build.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index 92fd5c5..00cc31a 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -89,6 +89,9 @@ func runBuild(cmd *command) (err error) { if pkg.Name != "main" { return fmt.Errorf("cannot build non-main packages") } + if err := importsApp(pkg); err != nil { + return err + } return goIOSBuild(pkg.ImportPath) } return fmt.Errorf("-target=ios requires darwin host") @@ -101,16 +104,8 @@ func runBuild(cmd *command) (err error) { return goAndroidBuild(pkg.ImportPath, "") } - // Building a program, make sure it is appropriate for mobile. - importsApp := false - for _, path := range pkg.Imports { - if path == "golang.org/x/mobile/app" { - importsApp = true - break - } - } - if !importsApp { - return fmt.Errorf(`%s does not import "golang.org/x/mobile/app"`, pkg.ImportPath) + if err := importsApp(pkg); err != nil { + return err } if buildN { @@ -297,6 +292,16 @@ func runBuild(cmd *command) (err error) { return nil } +func importsApp(pkg *build.Package) error { + // Building a program, make sure it is appropriate for mobile. + for _, path := range pkg.Imports { + if path == "golang.org/x/mobile/app" { + return nil + } + } + return fmt.Errorf(`%s does not import "golang.org/x/mobile/app"`, pkg.ImportPath) +} + var xout io.Writer = os.Stderr func printcmd(format string, args ...interface{}) {