Skip to content

Commit 2ebcbb6

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

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
@@ -68,6 +68,9 @@ with the app.
6868
The -o flag specifies the output file name. If not specified, the
6969
output file name depends on the package built.
7070
71+
The -cache flag specifies the build cache directory. If not specified,
72+
ioutil.TempDir() is used.
73+
7174
The -v flag provides verbose output, including the list of packages built.
7275
7376
The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are
@@ -243,6 +246,7 @@ var (
243246
buildTarget string // -target
244247
buildTrimpath bool // -trimpath
245248
buildWork bool // -work
249+
buildCache string // -cache
246250
buildBundleID string // -bundleid
247251
buildIOSVersion string // -iosversion
248252
buildAndroidAPI int // -androidapi
@@ -264,26 +268,27 @@ func addBuildFlags(cmd *command) {
264268
cmd.flag.Var(&buildTags, "tags", "")
265269
}
266270

267-
func addBuildFlagsNVXWork(cmd *command) {
271+
func addBuildFlagsNVXWorkCache(cmd *command) {
268272
cmd.flag.BoolVar(&buildN, "n", false, "")
269273
cmd.flag.BoolVar(&buildV, "v", false, "")
270274
cmd.flag.BoolVar(&buildX, "x", false, "")
271275
cmd.flag.BoolVar(&buildWork, "work", false, "")
276+
cmd.flag.StringVar(&buildCache, "cache", "", "")
272277
}
273278

274279
func init() {
275280
addBuildFlags(cmdBuild)
276-
addBuildFlagsNVXWork(cmdBuild)
281+
addBuildFlagsNVXWorkCache(cmdBuild)
277282

278283
addBuildFlags(cmdInstall)
279-
addBuildFlagsNVXWork(cmdInstall)
284+
addBuildFlagsNVXWorkCache(cmdInstall)
280285

281-
addBuildFlagsNVXWork(cmdInit)
286+
addBuildFlagsNVXWorkCache(cmdInit)
282287

283288
addBuildFlags(cmdBind)
284-
addBuildFlagsNVXWork(cmdBind)
289+
addBuildFlagsNVXWorkCache(cmdBind)
285290

286-
addBuildFlagsNVXWork(cmdClean)
291+
addBuildFlagsNVXWorkCache(cmdClean)
287292
}
288293

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

cmd/gomobile/env.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,18 @@ func buildEnvInit() (cleanup func(), err error) {
128128
fmt.Printf("WORK=%s\n", tmpdir)
129129
return
130130
}
131-
removeAll(tmpdir)
131+
if buildCache == "" {
132+
removeAll(tmpdir)
133+
}
132134
}
133135
if buildN {
134136
tmpdir = "$WORK"
135137
cleanupFn = func() {}
138+
} else if buildCache != "" {
139+
tmpdir = buildCache
140+
if err = os.MkdirAll(tmpdir, 0700); err != nil {
141+
return nil, err
142+
}
136143
} else {
137144
tmpdir, err = ioutil.TempDir("", "gomobile-work-")
138145
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)