Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind: added pkglink flag to use gopath pkg #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/gomobile/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
`,
Expand Down Expand Up @@ -142,6 +144,7 @@ var (
bindJavaPkg string // -javapkg
bindClasspath string // -classpath
bindBootClasspath string // -bootclasspath
bindGoPathPkgLink bool //-pkglink
)

func init() {
Expand All @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions cmd/gomobile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down