From d4c1c0d8d5370ceb49c97c776c3a611548579dee Mon Sep 17 00:00:00 2001 From: zouxu Date: Tue, 24 May 2022 15:31:06 +0800 Subject: [PATCH] bind: added pkglink flag to use gopath pkg (cherry picked from commit 014373cb7c9856ede6ed6bb0091a1ef7fc01c623) --- cmd/gomobile/bind.go | 4 ++++ cmd/gomobile/build.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go index c4552e3e3..348c5c6e7 100644 --- a/cmd/gomobile/bind.go +++ b/cmd/gomobile/bind.go @@ -64,6 +64,8 @@ classes. The -v flag provides verbose output, including the list of packages built. +The -pkglink flag is use link to gopath pkg + The build flags -a, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are shared with the build command. For documentation, see 'go help build'. `, @@ -142,6 +144,7 @@ var ( bindJavaPkg string // -javapkg bindClasspath string // -classpath bindBootClasspath string // -bootclasspath + bindGoPathPkgLink bool //-pkglink ) func init() { @@ -152,6 +155,7 @@ func init() { "custom Objective-C name prefix. Valid only with -target=ios.") cmdBind.flag.StringVar(&bindClasspath, "classpath", "", "The classpath for imported Java classes. Valid only with -target=android.") cmdBind.flag.StringVar(&bindBootClasspath, "bootclasspath", "", "The bootstrap classpath for imported Java classes. Valid only with -target=android.") + cmdBind.flag.BoolVar(&bindGoPathPkgLink, "pkglink", true, "pkglink link gopath pkg") } func bootClasspath() (string, error) { diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index 64a28fe68..997579de2 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -337,7 +337,22 @@ func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...stri return runCmd(cmd) } +func pkgSoftLink(at string) error { + if bindGoPathPkgLink { + symlink := at + "/../pkg" + target := goEnv("GOPATH") + "/pkg" + if buildV { + fmt.Fprintf(os.Stderr, "try to create link, %v->%v", symlink, target) + } + return os.Symlink(target, symlink) + } + return nil +} + func goModTidyAt(at string, env []string) error { + if err := pkgSoftLink(at); err != nil { + return err + } cmd := exec.Command("go", "mod", "tidy") if buildV { cmd.Args = append(cmd.Args, "-v")