bind,misc: guard reverse generated import with mobile os tags
Running go get golang.org/x/mobile/... results in errors because the go tool fails to find the reverse generated Java ("Java/...") and Objective-C ("ObjC/...") packages. Work around the errors by adding the android and ios tags, respectively, to files importing those packages. The gobind gradle plugin is updated to pass along GOOS=android to ensure the gobind tool continues to build Android reverse packages. Fixes golang/go#17750 Change-Id: Id66a3c6cdfe249c6ed494192eb12195d6509332f Reviewed-on: https://go-review.googlesource.com/34956 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
2f5693b8d8
commit
d8b1e1aab8
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build android
|
||||
|
||||
package javapkg
|
||||
|
||||
import (
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ios
|
||||
|
||||
package objcpkg
|
||||
|
||||
import (
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ios
|
||||
|
||||
package objcpkg
|
||||
|
||||
import (
|
||||
|
|
|
@ -6,6 +6,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
@ -14,12 +15,13 @@ var tests = []struct {
|
|||
name string
|
||||
lang string
|
||||
pkg string
|
||||
goos string
|
||||
}{
|
||||
{"ObjC-Testpkg", "objc", "golang.org/x/mobile/bind/testpkg"},
|
||||
{"Java-Testpkg", "java", "golang.org/x/mobile/bind/testpkg"},
|
||||
{"Go-Testpkg", "go", "golang.org/x/mobile/bind/testpkg"},
|
||||
{"Java-Javapkg", "java", "golang.org/x/mobile/bind/testpkg/javapkg"},
|
||||
{"Go-Javapkg", "go", "golang.org/x/mobile/bind/testpkg/javapkg"},
|
||||
{"ObjC-Testpkg", "objc", "golang.org/x/mobile/bind/testpkg", ""},
|
||||
{"Java-Testpkg", "java", "golang.org/x/mobile/bind/testpkg", ""},
|
||||
{"Go-Testpkg", "go", "golang.org/x/mobile/bind/testpkg", ""},
|
||||
{"Java-Javapkg", "java", "golang.org/x/mobile/bind/testpkg/javapkg", "android"},
|
||||
{"Go-Javapkg", "go", "golang.org/x/mobile/bind/testpkg/javapkg", "android"},
|
||||
}
|
||||
|
||||
func installGobind() error {
|
||||
|
@ -29,8 +31,11 @@ func installGobind() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func runGobind(lang, pkg string) error {
|
||||
func runGobind(lang, pkg, goos string) error {
|
||||
cmd := exec.Command("gobind", "-lang", lang, pkg)
|
||||
if goos != "" {
|
||||
cmd.Env = append(os.Environ(), "GOOS="+goos)
|
||||
}
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("gobind -lang %s %s failed: %v: %s", lang, pkg, err, out)
|
||||
}
|
||||
|
@ -43,7 +48,7 @@ func TestGobind(t *testing.T) {
|
|||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if err := runGobind(test.lang, test.pkg); err != nil {
|
||||
if err := runGobind(test.lang, test.pkg, test.goos); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
@ -57,7 +62,7 @@ func BenchmarkGobind(b *testing.B) {
|
|||
for _, test := range tests {
|
||||
b.Run(test.name, func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := runGobind(test.lang, test.pkg); err != nil {
|
||||
if err := runGobind(test.lang, test.pkg, test.goos); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ buildscript {
|
|||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2+'
|
||||
classpath "gradle.plugin.org.golang.mobile.bind:gobindPlugin:0.2.7"
|
||||
classpath "gradle.plugin.org.golang.mobile.bind:gobindPlugin:0.2.8"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package reverse implements an Android app in 100% Go.
|
||||
|
||||
// +build android
|
||||
|
||||
package reverse
|
||||
|
||||
import (
|
||||
|
|
|
@ -27,7 +27,7 @@ dependencies {
|
|||
testCompile 'junit:junit:4.11'
|
||||
}
|
||||
|
||||
version = '0.2.7'
|
||||
version = '0.2.8'
|
||||
|
||||
pluginBundle {
|
||||
website = 'https://golang.org/x/mobile'
|
||||
|
|
|
@ -153,6 +153,7 @@ class BindTask extends DefaultTask {
|
|||
throw new GradleException('Neither sdk.dir or ANDROID_HOME is set')
|
||||
}
|
||||
environment("GOPATH", gopath)
|
||||
environment("GOOS", "android")
|
||||
environment("PATH", paths.join(File.pathSeparator))
|
||||
environment("ANDROID_HOME", androidHome)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue