Skip to content

Commit d4c1c0d

Browse files
committed
bind: added pkglink flag to use gopath pkg
(cherry picked from commit 014373cb7c9856ede6ed6bb0091a1ef7fc01c623)
1 parent 8578da9 commit d4c1c0d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cmd/gomobile/bind.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ classes.
6464
6565
The -v flag provides verbose output, including the list of packages built.
6666
67+
The -pkglink flag is use link to gopath pkg
68+
6769
The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work
6870
are shared with the build command. For documentation, see 'go help build'.
6971
`,
@@ -142,6 +144,7 @@ var (
142144
bindJavaPkg string // -javapkg
143145
bindClasspath string // -classpath
144146
bindBootClasspath string // -bootclasspath
147+
bindGoPathPkgLink bool //-pkglink
145148
)
146149

147150
func init() {
@@ -152,6 +155,7 @@ func init() {
152155
"custom Objective-C name prefix. Valid only with -target=ios.")
153156
cmdBind.flag.StringVar(&bindClasspath, "classpath", "", "The classpath for imported Java classes. Valid only with -target=android.")
154157
cmdBind.flag.StringVar(&bindBootClasspath, "bootclasspath", "", "The bootstrap classpath for imported Java classes. Valid only with -target=android.")
158+
cmdBind.flag.BoolVar(&bindGoPathPkgLink, "pkglink", true, "pkglink link gopath pkg")
155159
}
156160

157161
func bootClasspath() (string, error) {

cmd/gomobile/build.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,22 @@ func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...stri
337337
return runCmd(cmd)
338338
}
339339

340+
func pkgSoftLink(at string) error {
341+
if bindGoPathPkgLink {
342+
symlink := at + "/../pkg"
343+
target := goEnv("GOPATH") + "/pkg"
344+
if buildV {
345+
fmt.Fprintf(os.Stderr, "try to create link, %v->%v", symlink, target)
346+
}
347+
return os.Symlink(target, symlink)
348+
}
349+
return nil
350+
}
351+
340352
func goModTidyAt(at string, env []string) error {
353+
if err := pkgSoftLink(at); err != nil {
354+
return err
355+
}
341356
cmd := exec.Command("go", "mod", "tidy")
342357
if buildV {
343358
cmd.Args = append(cmd.Args, "-v")

0 commit comments

Comments
 (0)