mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
mobile/bind: allow bound packages to refer to imported bound packages
Multiple packages are already supported, but only as if each packages were bound in isolation. This CL lets a bound package refer to other bound packages in its exported functions, types and fields. In Java, the JNI class jclass and constructor jmethodID are exported so other packages can construct proxies of other packages' interfaces. In ObjC, the class @interface declarations are moved from the package .m file to its .h file to allow other packages to constructs its interface proxies. Add a supporting test package, secondpkg, and add Java and ObjC tests for the new cross package functionality. Also add simplepkg for testing corner cases where the generated Go file must not include its bound package. While we're here, stop generating Go proxy types for struct types; only Go interfaces can be implemented in the foreign language. Change-Id: Icbfa739c893703867d38a9100ed0928fbd7a660d Reviewed-on: https://go-review.googlesource.com/20575 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import go.testpkg.Testpkg;
|
||||
import go.secondpkg.Secondpkg;
|
||||
|
||||
public class SeqTest extends InstrumentationTestCase {
|
||||
public SeqTest() {
|
||||
@@ -472,4 +473,23 @@ public class SeqTest extends InstrumentationTestCase {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testImportedPkg() {
|
||||
assertEquals("imported string should match", Secondpkg.HelloString, Secondpkg.Hello());
|
||||
Secondpkg.I i = Testpkg.NewImportedI();
|
||||
Secondpkg.S s = Testpkg.NewImportedS();
|
||||
i = Testpkg.getImportedVarI();
|
||||
s = Testpkg.getImportedVarS();
|
||||
assertEquals("numbers should match", 8, i.F(8));
|
||||
assertEquals("numbers should match", 8, s.F(8));
|
||||
Testpkg.setImportedVarI(i);
|
||||
Testpkg.setImportedVarS(s);
|
||||
Testpkg.ImportedFields fields = Testpkg.NewImportedFields();
|
||||
i = fields.getI();
|
||||
s = fields.getS();
|
||||
fields.setI(i);
|
||||
fields.setS(s);
|
||||
Testpkg.WithImportedI(i);
|
||||
Testpkg.WithImportedS(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ import (
|
||||
// This requires the gradle command in PATH and
|
||||
// the Android SDK whose path is available through ANDROID_HOME environment variable.
|
||||
func TestJavaSeqTest(t *testing.T) {
|
||||
runTest(t, "golang.org/x/mobile/bind/testpkg", "SeqTest")
|
||||
runTest(t, []string{
|
||||
"golang.org/x/mobile/bind/testpkg",
|
||||
"golang.org/x/mobile/bind/testpkg/secondpkg",
|
||||
"golang.org/x/mobile/bind/testpkg/simplepkg",
|
||||
}, "SeqTest")
|
||||
}
|
||||
|
||||
// TestJavaSeqBench runs java test SeqBench.java, with the same
|
||||
@@ -34,10 +38,10 @@ func TestJavaSeqTest(t *testing.T) {
|
||||
//
|
||||
// while running the benchmark to see the results.
|
||||
func TestJavaSeqBench(t *testing.T) {
|
||||
runTest(t, "golang.org/x/mobile/bind/benchmark", "SeqBench")
|
||||
runTest(t, []string{"golang.org/x/mobile/bind/benchmark"}, "SeqBench")
|
||||
}
|
||||
|
||||
func runTest(t *testing.T, pkgName, javaCls string) {
|
||||
func runTest(t *testing.T, pkgNames []string, javaCls string) {
|
||||
if _, err := run("which gradle"); err != nil {
|
||||
t.Skip("command gradle not found, skipping")
|
||||
}
|
||||
@@ -80,7 +84,7 @@ func runTest(t *testing.T, pkgName, javaCls string) {
|
||||
}
|
||||
}
|
||||
|
||||
buf, err := run("gomobile bind -o pkg.aar " + pkgName)
|
||||
buf, err := run("gomobile bind -o pkg.aar " + strings.Join(pkgNames, " "))
|
||||
if err != nil {
|
||||
t.Logf("%s", buf)
|
||||
t.Fatalf("failed to run gomobile bind: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user