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

x/mobile: fix issue 62142 about reverse binding #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions cmd/gomobile/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func packagesConfig(t targetInfo) *packages.Config {
}

// getModuleVersions returns a module information at the directory src.
func getModuleVersions(targetPlatform string, targetArch string, src string) (*modfile.File, error) {
func getModuleVersions(targetPlatform string, targetArch string, src string, dir string) (*modfile.File, error) {
cmd := exec.Command("go", "list")
cmd.Env = append(os.Environ(), "GOOS="+platformOS(targetPlatform), "GOARCH="+targetArch)

Expand Down Expand Up @@ -289,6 +289,17 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m
}
}

for _, subdir := range []string{"Java", "ObjC"} {
if _, err := os.Stat(filepath.Join(dir, subdir)); err == nil {
if err := f.AddReplace(subdir, "", filepath.Join(dir, subdir), ""); err != nil {
return nil, err
}
if err := os.WriteFile(filepath.Join(dir, subdir, "go.mod"), []byte("module "+subdir+"\n"), 0644); err != nil {
return nil, err
}
}
}

v, err := ensureGoVersion()
if err != nil {
return nil, err
Expand Down Expand Up @@ -316,7 +327,7 @@ func writeGoMod(dir, targetPlatform, targetArch string) error {
}

return writeFile(filepath.Join(dir, "go.mod"), func(w io.Writer) error {
f, err := getModuleVersions(targetPlatform, targetArch, ".")
f, err := getModuleVersions(targetPlatform, targetArch, ".", dir)
if err != nil {
return err
}
Expand Down