Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/gomobile: add a flag to manually specify a work dir #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/gomobile/bind.go
Original file line number Diff line number Diff line change
@@ -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
17 changes: 11 additions & 6 deletions cmd/gomobile/build.go
Original file line number Diff line number Diff line change
@@ -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 {
9 changes: 8 additions & 1 deletion cmd/gomobile/env.go
Original file line number Diff line number Diff line change
@@ -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 {
8 changes: 8 additions & 0 deletions cmd/gomobile/init.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions cmd/gomobile/install.go
Original file line number Diff line number Diff line change
@@ -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'.