Skip to content

Commit 0bdf708

Browse files
committed
Add flag to manually specify a work dir, based on golang#58
1 parent 858099f commit 0bdf708

4 files changed

Lines changed: 25 additions & 7 deletions

File tree

cmd/gomobile/bind.go

Lines changed: 3 additions & 0 deletions
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

Lines changed: 11 additions & 6 deletions
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,11 +268,12 @@ 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
type binInfo struct {
@@ -278,17 +283,17 @@ type binInfo struct {
278283

279284
func init() {
280285
addBuildFlags(cmdBuild)
281-
addBuildFlagsNVXWork(cmdBuild)
286+
addBuildFlagsNVXWorkCache(cmdBuild)
282287

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

286-
addBuildFlagsNVXWork(cmdInit)
291+
addBuildFlagsNVXWorkCache(cmdInit)
287292

288293
addBuildFlags(cmdBind)
289-
addBuildFlagsNVXWork(cmdBind)
294+
addBuildFlagsNVXWorkCache(cmdBind)
290295

291-
addBuildFlagsNVXWork(cmdClean)
296+
addBuildFlagsNVXWorkCache(cmdClean)
292297
}
293298

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

cmd/gomobile/env.go

Lines changed: 8 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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)