cmd/gomobile: make gomobile-init support Go modules

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 <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
Hajime Hoshi
2019-12-10 15:19:39 +00:00
committed by Daniel Martí
parent 5c0e7e404a
commit 1a1fef8273
6 changed files with 15 additions and 4 deletions
+2
View File
@@ -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(
+2
View File
@@ -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
+4 -2
View File
@@ -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)
}
+2
View File
@@ -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)
+4 -1
View File
@@ -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 {
+1 -1
View File
@@ -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