Skip to content

Commit b45ab8b

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

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
@@ -62,6 +62,9 @@ For -target android, the -bootclasspath and -classpath flags are used to
6262
control the bootstrap classpath and the classpath for Go wrappers to Java
6363
classes.
6464
65+
The -cache flag specifies the build cache directory. If not specified,
66+
ioutil.TempDir() is used.
67+
6568
The -v flag provides verbose output, including the list of packages built.
6669
6770
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
@@ -69,6 +69,9 @@ with the app.
6969
The -o flag specifies the output file name. If not specified, the
7070
output file name depends on the package built.
7171
72+
The -cache flag specifies the build cache directory. If not specified,
73+
ioutil.TempDir() is used.
74+
7275
The -v flag provides verbose output, including the list of packages built.
7376
7477
The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are
@@ -244,6 +247,7 @@ var (
244247
buildTarget string // -target
245248
buildTrimpath bool // -trimpath
246249
buildWork bool // -work
250+
buildCache string // -cache
247251
buildBundleID string // -bundleid
248252
buildIOSVersion string // -iosversion
249253
buildAndroidAPI int // -androidapi
@@ -265,26 +269,27 @@ func addBuildFlags(cmd *command) {
265269
cmd.flag.Var(&buildTags, "tags", "")
266270
}
267271

268-
func addBuildFlagsNVXWork(cmd *command) {
272+
func addBuildFlagsNVXWorkCache(cmd *command) {
269273
cmd.flag.BoolVar(&buildN, "n", false, "")
270274
cmd.flag.BoolVar(&buildV, "v", false, "")
271275
cmd.flag.BoolVar(&buildX, "x", false, "")
272276
cmd.flag.BoolVar(&buildWork, "work", false, "")
277+
cmd.flag.StringVar(&buildCache, "cache", "", "")
273278
}
274279

275280
func init() {
276281
addBuildFlags(cmdBuild)
277-
addBuildFlagsNVXWork(cmdBuild)
282+
addBuildFlagsNVXWorkCache(cmdBuild)
278283

279284
addBuildFlags(cmdInstall)
280-
addBuildFlagsNVXWork(cmdInstall)
285+
addBuildFlagsNVXWorkCache(cmdInstall)
281286

282-
addBuildFlagsNVXWork(cmdInit)
287+
addBuildFlagsNVXWorkCache(cmdInit)
283288

284289
addBuildFlags(cmdBind)
285-
addBuildFlagsNVXWork(cmdBind)
290+
addBuildFlagsNVXWorkCache(cmdBind)
286291

287-
addBuildFlagsNVXWork(cmdClean)
292+
addBuildFlagsNVXWorkCache(cmdClean)
288293
}
289294

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

cmd/gomobile/env.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,18 @@ func buildEnvInit() (cleanup func(), err error) {
132132
fmt.Printf("WORK=%s\n", tmpdir)
133133
return
134134
}
135-
removeAll(tmpdir)
135+
if buildCache == "" {
136+
removeAll(tmpdir)
137+
}
136138
}
137139
if buildN {
138140
tmpdir = "$WORK"
139141
cleanupFn = func() {}
142+
} else if buildCache != "" {
143+
tmpdir = buildCache
144+
if err = os.MkdirAll(tmpdir, 0700); err != nil {
145+
return nil, err
146+
}
140147
} else {
141148
tmpdir, err = ioutil.TempDir("", "gomobile-work-")
142149
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)