Skip to content

Commit bfaf3f5

Browse files
committed
feat: add a flag to manually specify a work dir
Signed-off-by: aeddi <[email protected]>
1 parent bdb1ca9 commit bfaf3f5

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

cmd/gomobile/bind.go

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ For -target android, the -bootclasspath and -classpath flags are used to
6060
control the bootstrap classpath and the classpath for Go wrappers to Java
6161
classes.
6262
63+
The -cache flag specifies the build cache directory. If not specified,
64+
ioutil.TempDir() is used.
65+
6366
The -v flag provides verbose output, including the list of packages built.
6467
6568
The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work

cmd/gomobile/build.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ with the app.
5858
The -o flag specifies the output file name. If not specified, the
5959
output file name depends on the package built.
6060
61+
The -cache flag specifies the build cache directory. If not specified,
62+
ioutil.TempDir() is used.
63+
6164
The -v flag provides verbose output, including the list of packages built.
6265
6366
The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are
@@ -224,6 +227,7 @@ var (
224227
buildTarget string // -target
225228
buildTrimpath bool // -trimpath
226229
buildWork bool // -work
230+
buildCache string // -cache
227231
buildBundleID string // -bundleid
228232
buildIOSVersion string // -iosversion
229233
buildAndroidAPI int // -androidapi
@@ -245,11 +249,12 @@ func addBuildFlags(cmd *command) {
245249
cmd.flag.Var(&buildTags, "tags", "")
246250
}
247251

248-
func addBuildFlagsNVXWork(cmd *command) {
252+
func addBuildFlagsNVXWorkCache(cmd *command) {
249253
cmd.flag.BoolVar(&buildN, "n", false, "")
250254
cmd.flag.BoolVar(&buildV, "v", false, "")
251255
cmd.flag.BoolVar(&buildX, "x", false, "")
252256
cmd.flag.BoolVar(&buildWork, "work", false, "")
257+
cmd.flag.StringVar(&buildCache, "cache", "", "")
253258
}
254259

255260
type binInfo struct {
@@ -259,17 +264,17 @@ type binInfo struct {
259264

260265
func init() {
261266
addBuildFlags(cmdBuild)
262-
addBuildFlagsNVXWork(cmdBuild)
267+
addBuildFlagsNVXWorkCache(cmdBuild)
263268

264269
addBuildFlags(cmdInstall)
265-
addBuildFlagsNVXWork(cmdInstall)
270+
addBuildFlagsNVXWorkCache(cmdInstall)
266271

267-
addBuildFlagsNVXWork(cmdInit)
272+
addBuildFlagsNVXWorkCache(cmdInit)
268273

269274
addBuildFlags(cmdBind)
270-
addBuildFlagsNVXWork(cmdBind)
275+
addBuildFlagsNVXWorkCache(cmdBind)
271276

272-
addBuildFlagsNVXWork(cmdClean)
277+
addBuildFlagsNVXWorkCache(cmdClean)
273278
}
274279

275280
func goBuild(src string, env []string, args ...string) error {

cmd/gomobile/env.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,18 @@ func buildEnvInit() (cleanup func(), err error) {
6161
fmt.Printf("WORK=%s\n", tmpdir)
6262
return
6363
}
64-
removeAll(tmpdir)
64+
if buildCache == "" {
65+
removeAll(tmpdir)
66+
}
6567
}
6668
if buildN {
6769
tmpdir = "$WORK"
6870
cleanupFn = func() {}
71+
} else if buildCache != "" {
72+
tmpdir = buildCache
73+
if err = os.MkdirAll(tmpdir, 0700); err != nil {
74+
return nil, err
75+
}
6976
} else {
7077
tmpdir, err = ioutil.TempDir("", "gomobile-work-")
7178
if err != nil {

cmd/gomobile/install.go

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ attached mobile device.
2323
2424
Only -target android is supported. The 'adb' tool must be on the PATH.
2525
26+
The -cache flag specifies the build cache directory. If not specified,
27+
ioutil.TempDir() is used.
28+
2629
The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are
2730
shared with the build command.
2831
For documentation, see 'go help build'.

0 commit comments

Comments
 (0)