Skip to content

Commit

Permalink
cmd/gomobile: add a flag to manually specify a work dir golang#58
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Aug 22, 2021
2 parents c396df0 + bfaf3f5 commit c3be6f4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmd/gomobile/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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
Expand Down
17 changes: 11 additions & 6 deletions cmd/gomobile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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
Expand Down Expand Up @@ -224,6 +227,7 @@ var (
buildTarget string // -target
buildTrimpath bool // -trimpath
buildWork bool // -work
buildCache string // -cache
buildBundleID string // -bundleid
buildIOSVersion string // -iosversion
buildAndroidAPI int // -androidapi
Expand All @@ -245,11 +249,12 @@ 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", "", "")
}

type binInfo struct {
Expand All @@ -259,17 +264,17 @@ type binInfo struct {

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 {
Expand Down
9 changes: 8 additions & 1 deletion cmd/gomobile/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,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 {
Expand Down
3 changes: 3 additions & 0 deletions cmd/gomobile/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down

0 comments on commit c3be6f4

Please sign in to comment.