2
0
mirror of synced 2025-02-22 14:28:14 +00:00

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 <crawshaw@golang.org>
This commit is contained in:
Burcu Dogan 2015-07-08 14:36:07 -06:00
parent 80eb606a0f
commit 08407a4b1b

View File

@ -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{}) {