diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go index c4552e3e3..00efcffee 100644 --- a/cmd/gomobile/bind.go +++ b/cmd/gomobile/bind.go @@ -62,6 +62,9 @@ For -target android, the -bootclasspath and -classpath flags are used to control the bootstrap classpath and the classpath for Go wrappers to Java classes. +The -cache flag specifies the build cache directory. If not specified, +ioutil.TempDir() is used. + The -v flag provides verbose output, including the list of packages built. The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index 64a28fe68..5913ade2c 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -69,6 +69,9 @@ with the app. The -o flag specifies the output file name. If not specified, the output file name depends on the package built. +The -cache flag specifies the build cache directory. If not specified, +ioutil.TempDir() is used. + The -v flag provides verbose output, including the list of packages built. The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are @@ -244,6 +247,7 @@ var ( buildTarget string // -target buildTrimpath bool // -trimpath buildWork bool // -work + buildCache string // -cache buildBundleID string // -bundleid buildIOSVersion string // -iosversion buildAndroidAPI int // -androidapi @@ -265,26 +269,27 @@ func addBuildFlags(cmd *command) { cmd.flag.Var(&buildTags, "tags", "") } -func addBuildFlagsNVXWork(cmd *command) { +func addBuildFlagsNVXWorkCache(cmd *command) { cmd.flag.BoolVar(&buildN, "n", false, "") cmd.flag.BoolVar(&buildV, "v", false, "") cmd.flag.BoolVar(&buildX, "x", false, "") cmd.flag.BoolVar(&buildWork, "work", false, "") + cmd.flag.StringVar(&buildCache, "cache", "", "") } func init() { addBuildFlags(cmdBuild) - addBuildFlagsNVXWork(cmdBuild) + addBuildFlagsNVXWorkCache(cmdBuild) addBuildFlags(cmdInstall) - addBuildFlagsNVXWork(cmdInstall) + addBuildFlagsNVXWorkCache(cmdInstall) - addBuildFlagsNVXWork(cmdInit) + addBuildFlagsNVXWorkCache(cmdInit) addBuildFlags(cmdBind) - addBuildFlagsNVXWork(cmdBind) + addBuildFlagsNVXWorkCache(cmdBind) - addBuildFlagsNVXWork(cmdClean) + addBuildFlagsNVXWorkCache(cmdClean) } func goBuild(src string, env []string, args ...string) error { diff --git a/cmd/gomobile/env.go b/cmd/gomobile/env.go index 43f24b99d..d8ce38c8e 100644 --- a/cmd/gomobile/env.go +++ b/cmd/gomobile/env.go @@ -132,11 +132,18 @@ func buildEnvInit() (cleanup func(), err error) { fmt.Printf("WORK=%s\n", tmpdir) return } - removeAll(tmpdir) + if buildCache == "" { + removeAll(tmpdir) + } } if buildN { tmpdir = "$WORK" cleanupFn = func() {} + } else if buildCache != "" { + tmpdir = buildCache + if err = os.MkdirAll(tmpdir, 0700); err != nil { + return nil, err + } } else { tmpdir, err = ioutil.TempDir("", "gomobile-work-") if err != nil { diff --git a/cmd/gomobile/init.go b/cmd/gomobile/init.go index e7392df71..f2d3e45ef 100644 --- a/cmd/gomobile/init.go +++ b/cmd/gomobile/init.go @@ -220,6 +220,14 @@ func mkdir(dir string) error { } func symlink(src, dst string) error { + if _, err := os.Lstat(dst); err == nil { + if err = removeAll(dst); err != nil { + return err + } + } else if !os.IsNotExist(err) { + return err + } + if buildX || buildN { printcmd("ln -s %s %s", src, dst) } diff --git a/cmd/gomobile/install.go b/cmd/gomobile/install.go index beb7e5262..a1481a3f8 100644 --- a/cmd/gomobile/install.go +++ b/cmd/gomobile/install.go @@ -23,6 +23,9 @@ attached mobile device. Only -target android is supported. The 'adb' tool must be on the PATH. +The -cache flag specifies the build cache directory. If not specified, +ioutil.TempDir() is used. + The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are shared with the build command. For documentation, see 'go help build'.