From 1a1fef82734d773fc4e59ec63b8af0bf10ab346f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 9 Dec 2019 13:57:27 +0900 Subject: [PATCH] cmd/gomobile: make gomobile-init support Go modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, all the gomobile commands forced Go modules to be off internally, regardless of the current Go modules state. After this change, gomobile-init command follows the current Go modules state. The other gomobile commands are not changed. This is also a preparation to support Go modules in gomobile-bind and gomobile-build. Updates golang/go#27234 Change-Id: I3d9eedd667cba4d30de3ac0543f037be36cd3e51 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/210477 Run-TryBot: Hajime Hoshi TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim Reviewed-by: Daniel Martí --- cmd/gomobile/bind_androidapp.go | 2 ++ cmd/gomobile/bind_iosapp.go | 2 ++ cmd/gomobile/build.go | 6 ++++-- cmd/gomobile/build_androidapp.go | 2 ++ cmd/gomobile/build_iosapp.go | 5 ++++- cmd/gomobile/init_test.go | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/gomobile/bind_androidapp.go b/cmd/gomobile/bind_androidapp.go index 0ccb079..31b2e56 100644 --- a/cmd/gomobile/bind_androidapp.go +++ b/cmd/gomobile/bind_androidapp.go @@ -58,6 +58,8 @@ func goAndroidBind(gobind string, pkgs []*packages.Package, androidArchs []strin // Add the generated packages to GOPATH for reverse bindings. gopath := fmt.Sprintf("GOPATH=%s%c%s", tmpdir, filepath.ListSeparator, goEnv("GOPATH")) env = append(env, gopath) + // gomobile-bind does not support modules yet. + env = append(env, "GO111MODULE=off") toolchain := ndk.Toolchain(arch) err := goBuildAt( diff --git a/cmd/gomobile/bind_iosapp.go b/cmd/gomobile/bind_iosapp.go index 4140731..924a474 100644 --- a/cmd/gomobile/bind_iosapp.go +++ b/cmd/gomobile/bind_iosapp.go @@ -178,6 +178,8 @@ var iosModuleMapTmpl = template.Must(template.New("iosmmap").Parse(`framework mo func goIOSBindArchive(name string, env []string, gosrc string) (string, error) { arch := getenv(env, "GOARCH") archive := filepath.Join(tmpdir, name+"-"+arch+".a") + // gobind-bind does not support modules yet. + env = append(env, "GO111MODULE=off") err := goBuildAt(gosrc, "./gobind", env, "-buildmode=c-archive", "-o", archive) if err != nil { return "", err diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index f4b8c09..3c33571 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -119,6 +119,8 @@ func runBuildImpl(cmd *command) (*packages.Package, error) { if pkg.Name != "main" { for _, arch := range targetArchs { env := androidEnv[arch] + // gomobile-build does not support Go modules yet. + env = append(env, "GO111MODULE=off") if err := goBuild(pkg.PkgPath, env); err != nil { return nil, err } @@ -136,6 +138,8 @@ func runBuildImpl(cmd *command) (*packages.Package, error) { if pkg.Name != "main" { for _, arch := range targetArchs { env := darwinEnv[arch] + // gomobile-build does not support Go modules yet. + env = append(env, "GO111MODULE=off") if err := goBuild(pkg.PkgPath, env); err != nil { return nil, err } @@ -331,8 +335,6 @@ func goCmdAt(at string, subcmd string, srcs []string, env []string, args ...stri cmd.Args = append(cmd.Args, args...) cmd.Args = append(cmd.Args, srcs...) cmd.Env = append([]string{}, env...) - // gomobile does not support modules yet. - cmd.Env = append(cmd.Env, "GO111MODULE=off") cmd.Dir = at return runCmd(cmd) } diff --git a/cmd/gomobile/build_androidapp.go b/cmd/gomobile/build_androidapp.go index 1df9891..e538aa0 100644 --- a/cmd/gomobile/build_androidapp.go +++ b/cmd/gomobile/build_androidapp.go @@ -70,6 +70,8 @@ func goAndroidBuild(pkg *packages.Package, androidArchs []string) (map[string]bo for _, arch := range androidArchs { env := androidEnv[arch] + // gomobile-build does not support Go modules yet. + env = append(env, "GO111MODULE=off") toolchain := ndk.Toolchain(arch) libPath := "lib/" + toolchain.abi + "/lib" + libName + ".so" libAbsPath := filepath.Join(tmpdir, libPath) diff --git a/cmd/gomobile/build_iosapp.go b/cmd/gomobile/build_iosapp.go index a0103de..b9db63a 100644 --- a/cmd/gomobile/build_iosapp.go +++ b/cmd/gomobile/build_iosapp.go @@ -73,7 +73,10 @@ func goIOSBuild(pkg *packages.Package, bundleID string, archs []string) (map[str for _, arch := range archs { path := filepath.Join(tmpdir, arch) // Disable DWARF; see golang.org/issues/25148. - if err := goBuild(src, darwinEnv[arch], "-ldflags=-w", "-o="+path); err != nil { + env := darwinEnv[arch] + // gomobile-build does not support Go modules yet. + env = append(env, "GO111MODULE=off") + if err := goBuild(src, env, "-ldflags=-w", "-o="+path); err != nil { return nil, err } if nmpkgs == nil { diff --git a/cmd/gomobile/init_test.go b/cmd/gomobile/init_test.go index e01daad..42a8a5a 100644 --- a/cmd/gomobile/init_test.go +++ b/cmd/gomobile/init_test.go @@ -106,7 +106,7 @@ var initTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/ rm -r -f "$GOMOBILE" mkdir -p $GOMOBILE WORK={{.GOPATH}}/pkg/gomobile/work -GO111MODULE=off go install -x golang.org/x/mobile/cmd/gobind +go install -x golang.org/x/mobile/cmd/gobind cp $OPENAL_PATH/include/AL/al.h $GOMOBILE/include/AL/al.h mkdir -p $GOMOBILE/include/AL cp $OPENAL_PATH/include/AL/alc.h $GOMOBILE/include/AL/alc.h