2
0
mirror of synced 2025-02-23 14:58:12 +00:00

66 Commits

Author SHA1 Message Date
Changkun Ou
80cb72e7af cmd/gomobile: use GOOS=ios for iOS builds
This change permits gomobile to build iOS applications by properly
set GOOS=ios in the build process. The change is locally tested on
darwin/arm64, and golang.org/x/mobile/example/basic can be build
using the following commands:

gomobile build -target=android -o=basic.apk \
golang.org/x/mobile/example/basic

gomobile build -target=ios -bundleid=org.golang.gomobiletest \
-o=basic.app golang.org/x/mobile/example/basic

The built binaries are also tested on iOS 15 beta7 and Android 12 API31.

Updates golang/go#47952
Fixes golang/go#47238

Change-Id: Ibf40a77933ac957640c78d0dbc1af043477e4b3a
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/346150
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-01 15:58:30 +00:00
Changkun Ou
a0f9ae51e3 cmd/gomobile: allow tests to pass on ios builder
There are several tests are skipped for Android but they may still be
tested on iOS. This will leads to trybot failure.

This CL skips those tests and allow them to pass on iOS.

Furthermore, deprecated C function warning are promoted to errors on
builders, this CL also fixes a deprecated asl_log for iOS in mobileinit.

Change-Id: Ie9da57a20dd75ef3d29b393e30aef01051bab454
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/346391
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-09-01 15:13:16 +00:00
Russ Cox
bdb1ca9a1e all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I30822eb504168b037ed3ec0f7759da1f41251f52
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/294374
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-02-20 03:30:13 +00:00
fujimoto kyosuke
d70acc1097 internal/binres: update wrong URL in comment
The URL in the comment was invalid due to a change in the repository directory structure.
That commit is this:
f6113af2d6

Change-Id: I7dcb9c505de0c5ce4f4a2115d48ccb0c6eadbd52
GitHub-Last-Rev: 85c5e3af7ef53611ca8d9ad83f6929e35d114cc6
GitHub-Pull-Request: golang/mobile#42
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/215357
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-01-18 06:27:24 +00:00
Hajime Hoshi
cafc553e1a cmd/gobind: fix build-tag, CGO and load trybot failures
* Correctly format build tags to pass into go/packages
* Removes CGO_ENABLED=0 from a packages.Load configuration
* Calls go/packages.Load twice to work around a build cache
* staleness issue

These bugs were introduced by CL 189597.

Updates golang/go#27234.
Updates golang/go#33687.

Change-Id: I3ae6737bf53bbecda0c7e25885b9c6aea5779332
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/190479
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-26 17:01:11 +00:00
Hajime Hoshi
e8b3e6111d internal/importers: replace go/build usages with go/packages
This CL is a pure refactoring to replace go/build usage with
golang.org/x/tools/go/packages. This is a preparation for Go
modules.

Updates golang/go#27234

Change-Id: I3e6a30b962da1a64bc43a89a7f02c03d559f86d3
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/189597
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-08-14 14:30:26 +00:00
Mark Villacampa
32b2708ab1 cmd/bind: add remaining Objc nullability specifiers
The `TestObjcSeqWrappers` test is failing because there are some missing nullability specifiers:

```
mobile master❯ go test -v ./bind/objc -run TestObjcSeqWrappers
=== RUN   TestObjcSeqWrappers
--- FAIL: TestObjcSeqWrappers (5.45s)
    seq_test.go:80: tmpdir = /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/bind-objc-seq-test-434219564
    seq_test.go:98: gomobile: darwin-arm: go build -tags aaa bbb ios -buildmode=c-archive -o /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/objcpkg-arm.a gobind failed: exit status 2
        # gobind
        In file included from /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/interfaces_darwin.go:5:
        In file included from /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/interfaces.h:8:
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:26:30: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:26:30: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:26:30: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:28:11: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:28:11: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:28:11: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:38:32: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:38:32: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:38:32: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:39:23: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:39:34: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:39:34: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:50:35: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:50:35: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:50:35: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:52:29: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:52:29: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:52:29: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:52:70: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:52:70: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:52:70: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:58:52: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:58:52: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:58:52: note: insert '_Nonnull' if the pointer should never be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:58:26: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:58:26: note: insert '_Nullable' if the pointer may be null
        /var/folders/cm/184j3xgn311dhh1tpm6cbmyr0000gn/T/gomobile-work-254743475/src/gobind/Objcpkg.objc.h:58:26: note: insert '_Nonnull' if the pointer should never be null

    seq_test.go:99: failed to run gomobile bind: exit status 1
FAIL
FAIL	golang.org/x/mobile/bind/objc	5.454s
```

I've decided to set them as `_Nullable`. Even if the implementation seems to raise an exception in case the object is `NULL` in all the cases I've checked, .e.g.:

```objc
- (NSDate * _Nullable)getSelf {
	int32_t refnum = go_seq_go_to_refnum(self._ref);
	int32_t _self = go_seq_to_refnum(self);
	int32_t r0 = proxyobjcpkg_GoNSDate_GetSelf(refnum, _self);
	NSDate* _ret0_ = nil;
	GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
	if (_ret0__ref != NULL) {
		_ret0_ = _ret0__ref.obj;
		if (_ret0_ == nil) {
			LOG_FATAL(@"unexpected NULL reference");
		}
	}
	return _ret0_;
}
```

Because there are cases where we are overriding a method in the superclass that might have different nullability specifiers, .e.g.: 6621de06e1/bind/testdata/testpkg/objcpkg/classes.go (L65)

And I haven't found an easy way to detect those.

Change-Id: I6386e48b1042a234f981fc7c351f54354ebb6cc9
GitHub-Last-Rev: 1cddbaaf785f9daeb1d210e1b6fe17b8ae860698
GitHub-Pull-Request: golang/mobile#32
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/176137
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-05-09 16:48:39 +00:00
Elias Naur
07b47c2b9c internal/importers/objc: fix parsing of newer clang output
Two things broke the clang ast dump parser:

- clang -cc1 didn't parse headers in iPhone mode automatically anymore.
  Add the -triple argument to force it.
- Source positions in the dumps can now contain <scratch space>.

Change-Id: I5d561f781355021f60c94d59e20bf1c1eee76d2a
Reviewed-on: https://go-review.googlesource.com/c/159678
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-01-25 20:03:37 +00:00
Tobias Klauser
ca3c58166e all: use "reports whether" in godoc comments
Go documentation style for boolean funcs is to say:

    // Foo reports whether ...
    func Foo() bool

rather than "returns true if" or "returns whether".

Change-Id: I5d01c45a8867b47462ed142a49ad51bf0a319ce1
Reviewed-on: https://go-review.googlesource.com/c/151957
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2018-11-30 13:31:20 +00:00
Elias Naur
56e3592fa7 internal/mobileinit,app: declare C symbols static
The changes to internal/mobileinit fixes golang/go#26298; the
changes to the app package are only the easy pickings.

Fixes golang/go#26298

Change-Id: I1ac49c57e417b852cb5ab1bdcb18c73db8c4475a
Reviewed-on: https://go-review.googlesource.com/122897
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-10 17:43:32 +00:00
Elias Naur
721e99406c internal/mobileinit,bind/java,app: don't treat jobject as a pointer
On Android, the JNI jobject type doesn't always contain a pointer.
Treating a non-pointer as a pointer can crash the runtime. Use
the more appropriate type uintptr instead.

Change-Id: I2b2049918d60226c4d23d6df0b10e68248d54bc2
Reviewed-on: https://go-review.googlesource.com/110256
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-30 16:43:58 +00:00
Elias Naur
bcd28df570 all: fix non-standard "DO NOT EDIT" comments for generated files
In the spirit of CL 99955, fix all non-standard generated code
headers and re-run the generators. Some generated files needed
git gofmt afterwards, but that problem is left for now.

Change-Id: I6b3131fb1753dc427d05af03107031120755cab0
Reviewed-on: https://go-review.googlesource.com/99975
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-03-14 14:08:28 +00:00
Elias Naur
cdc07529f8 internal/binres: skip resources tests if android.jar of api 15 is missing
Change-Id: I1cf92bb03c420e1eddaa36824cf488c5ed6f5a78
Reviewed-on: https://go-review.googlesource.com/93998
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-02-21 20:21:33 +00:00
Elias Naur
4bfed40def all: fix vet errors from Go 1.10
Change-Id: I624bbbb5aeda923aa48c37af9447bc4903b0de3f
Reviewed-on: https://go-review.googlesource.com/93996
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-02-14 22:03:29 +00:00
Daniel Skinner
eed0461ac2 cmd/gomobile: icon support for android
Provides support for resources.arsc generation enabling
the setting of an application icon.

If an asset/icon.png is encountered during build, then
the resources.arsc is generated to identify a single
xxxhdpi resource and the manifest will be updated to
reference resource as app icon.

References golang/go#9985

Change-Id: I9ef59fff45dcd612a41c479b2c679d22c094ab36
Reviewed-on: https://go-review.googlesource.com/30019
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-10-17 01:04:57 +00:00
Elias Naur
3ef91fec25 cmd/gomobile, internal/mobileinit: update to the NDK unified headers
From r16, the legacy headers no longer ship with the NDK. Update
the gomobile build system to use the unified headers instead.
They're available from r14.

Based on a patch by Steeve Morin.

Fixes golang/go#21802

Change-Id: I098330962c737edb833e968fe82558e15837f23f
Reviewed-on: https://go-review.googlesource.com/69950
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-10-11 16:08:37 +00:00
Elias Naur
0f3174026e internal/importers: reverse bind types from unexported struct fields
Before this CL, unexported fields were ignored for the purposes of
determining which classes a Go struct should extend or implement.
However, the field types were also ignored, resulting in the types
not being generated at all. This CL adds the types of unexported
fields to the set of types to be generated.

Fixes golang/go#17945

Change-Id: I5c6c44b7cdfe0c3d4c4dc44863ae201dca7ae9a4
Reviewed-on: https://go-review.googlesource.com/38635
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-04-19 17:20:05 +00:00
Elias Naur
e89cba38f6 internal/importers: always specify classpath to javap
To avoid picking up a classpath from the CLASSPATH environment
variable, always specify an explicit classpath to javap, even if is
empty.

Updates golang/go#19046.

Change-Id: I2b3d941ba2779f90654117a046ae1600a53d5848
Reviewed-on: https://go-review.googlesource.com/37320
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-02-21 20:01:42 +00:00
Elias Naur
1089cdd3e2 internal/importers: fix test
Updates golang/go#19046

Change-Id: I51990a3e023d0a5339df72cc372565eecf5798e1
Reviewed-on: https://go-review.googlesource.com/37318
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-02-21 17:09:56 +00:00
Elias Naur
60b0aaa3c8 internal/mobileinit: preserve stdout and stderr file descriptors
To ensure correct command line behavior, the Go runtime crashes
when a SIGPIPE is received on either fd 1 or fd 2 (CL 18151).

At the same time, go mobile redirects stdout and stderr to the
Android logcat facility by replacing os.Stderr and os.Stdout with
the writer ends of two pipes.

This in turn allows the original os.Stderr and os.Stdout files to
be garbage finalized, closing fd 1 and 2.

If an Android app then happens to open a pipe or socket, fd 1 and 2
might be reused. If the pipe or socket ever receives a SIGPIPE, the
Go runtime will think the signal was for stdout or stderr and crash
the program.

This CL preserves fd 1 and fd 2 by using dup3 to redirect the file
descriptors.

Change-Id: I5058d729eca52503a43f0e8c87a9fd296ed3667e
Reviewed-on: https://go-review.googlesource.com/35961
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-31 20:25:16 +00:00
Elias Naur
c243211167 bind,internal/importers: add Unwrap methods to unwrap Java wrappers
For Java classes implemented in Go, it is useful to take a Java instance
and extract its wrapped Go instance. For example, consider the
java.lang.Runnable implementation wrapping a Go function:

package somepkg

type GoRunnable struct {
    lang.Runnable
    f func()
}

Java methods that take a java.lang.Runnable cannot directly take a
*GoRunnable, so this CL adds a Unwrap method:

import gorun "Java/somepkg/GoRunnable"

...

r := gorun.New()
r.Unwrap().(*GoRunnable).f = func() { ... }
javapkg.Run(r)

The extra interface conversion is unfortunately needed to avoid
import cycles.

Change-Id: Ib775a5712cd25aa75a19d364a55d76b1e11dce77
Reviewed-on: https://go-review.googlesource.com/35295
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-18 20:31:42 +00:00
Elias Naur
ab8d69d0ab internal,importers: find deeply nested prefixed class references
Before this CL, with code such as

import "Java/some/pkg/Class"

...

Class.StaticFunc().DoSomething()

the reverse generator wouldn't find the the Java/some/pkg.Class
reference.

Change-Id: I1def4b54589fd1c123767ff59438c647cbced0cd
Reviewed-on: https://go-review.googlesource.com/35331
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-18 02:43:28 +00:00
Elias Naur
c4d780faeb bind,internal/importers: handle Java long constants correctly
Change-Id: Idff789038e7470ef5b12798273fc67165d57f4dc
Reviewed-on: https://go-review.googlesource.com/35293
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 15:58:41 +00:00
Elias Naur
2f5693b8d8 bind,internal/importers: always generate toString methods
When wrapping Java exceptions, their toString() methods are called from
the wrapper's Error() method to satisfy the Go error interface. Make
sure toString() is always included, even if it never directly referenced
from bound packages.

Change-Id: I5653f6ad82afbe4b061e02a69d60453000288a83
Reviewed-on: https://go-review.googlesource.com/35189
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:05:11 +00:00
Elias Naur
d96b6de528 internal/importers: skip unexported embedded fields
When determining if a Go struct embeds prefixed types, don't consider
unexported fields. This is important to avoid references cycles with the
Android databinding library; see the reverse example for details.

Change-Id: Ia820ca7ba4d1ec11a1f48651fac248eb753aad75
Reviewed-on: https://go-review.googlesource.com/35188
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:04:58 +00:00
Elias Naur
034bc70521 internal/importers/java: improve class not found error
Change-Id: I37bab4e002238f2701d3e52be898a81d1c2f0db0
Reviewed-on: https://go-review.googlesource.com/35187
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:04:21 +00:00
Elias Naur
3884e8cb98 internal,bind: resolve overloaded methods at runtime
Before this CL, calling overloaded methods on reverse bound Java
classes and interfaces involved confusing and ugly name mangling.
If a set of methods with the same name differed only in argument count,
the mangling was simply adding the argument count to the name:

func F()
func F1(int32)

But if two or more methods had the same number of arguments, the type
had to be appended:

func (...) F() int32
func (...) F1(int32) (int32, error)
func (...) F__I(int32, int32)
func (...) F__JLjava_util_concurrent_TimeUnit_2(int64, concurrent.TimeUnit)

This CL sacrifices a bit of type safety and performance to regain the
convenience and simplicity of Go by resolving overloaded method dispatch
at runtime.

Overloaded Java methods are combined to one Go method that, when invoked,
determines the correct Java method variant at runtime.

The signature of the Go method  is compatible with every Java method with
that name. For the example above, the single Go method becomes the most
general

func (...) F(...interface{}) (interface{}, error)

The method is variadic to cover function with a varying number of
arguments, and it returns interface{} to cover int32, int64 and no
argument. Finally, it returns an error to cover the variant that returns
an error. The generator tries to be specific; for example

func G1(int32) int32
func G2(int32, int32) int32

becomes

func G(int32, ...int32) int32

Overriding Java methods in Go is changed to use the Go parameter types to
determine to correct Java method. To avoid name clashes when overriding
multiple overloaded methods, trailing underscores in the method name are
ignored when matching Java methods.  See the Get methods of GoFuture in
bind/testpkg/javapkg for an example.

Change-Id: I6ac3e024141daa8fc2c35187865c5d7a63368094
Reviewed-on: https://go-review.googlesource.com/35186
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:03:33 +00:00
Elias Naur
103834091a bind,internal: generate reverse bindings for implicit ObjC types
This is the Objective-C version of a similar change to the Java
generaters, CL 34777.

This CL makes sure the types only implicitly referenced through method
parameters or return values are also reverse generated. In doing so,
the anonymous interface{} is never used by the reverse generator,
gaining type safety, removing a special case and making sure passing
values of implicit types can be passed across the language barrier.

To support implicit types, the Objective-C importer is changed to
extract the module of a type from the clang AST dump instead of
relying on the module implied by the Go reference (e.g.
ObjC/Foundation.NSString).

Change-Id: Ie9305f4cd9a9802decbd93f81cec84dd05af11ab
Reviewed-on: https://go-review.googlesource.com/34991
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-12 22:11:22 +00:00
Elias Naur
6f0c9f6df9 bind: generate wrappers for generated ObjC types
This is the Objective-C equivalent of CL 34776, generating reverse
wrappers for generated ObjC types. The implementation follows the same
strategy as the Java implementation: use the Go ast package to find
exported structs with embedded Objective-C types and synthesize their
types as if they were imported through clang.

In turn, the handling of the implicit "self" parameter changes in the
same way as well: the type of self parameters must be the wrapped type
for the generated type. For example:

func (d *GoNSDate) Description(self Foundation.NSDate) string

becomes

import gopkg "ObjC/Objcpkg"

func (d *GoNSDate) Description(self gopkg.GoNSDate) string

Change-Id: I26f838b06a622864be463f81dbb4dcae76f70f20
Reviewed-on: https://go-review.googlesource.com/34780
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 20:07:46 +00:00
Elias Naur
c90c4f7c8a bind,internal: change the default Java package to the empty string
The Objective-C bindings was recently changed to support the empty
name prefix and to use that as the default. This CLs changed the Java
generators in the same way, supporting the empty Java package and using
it as the default.

Change-Id: I857affce686c67638a2b6c4e1da5d6a88d7ba560
Reviewed-on: https://go-review.googlesource.com/34778
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:15:09 +00:00
Elias Naur
fe0977739a bind: generate reverse bindings for implicit Java types
Before this CL, Java types that were only implicitly referenced
were represented as interface{}. However, if a value of such an
implicit type were passed to Java, a runtime crash would occur
because there would be no wrapper class to unwrap.

Fix this by generating implicit types, fixing the crashes,
gaining type safety, and removing the interface{} special case in
the generator.

While we're here, remove a redundant insert to the clsMap map in
java.go.

Change-Id: Ic50125da3d7cd6075899bf628d419b084c630490
Reviewed-on: https://go-review.googlesource.com/34777
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:09:27 +00:00
Elias Naur
ff6f6e8d8e bind,cmd,internal: generate reverse bindings for exported Go structs
Before this CL, the type of the implicit "this" parameter to Java methods
implemented in Go could only be a super class of the generated Java
class. For example, the following GoRunnable type is an implementation of
the Java interface java.lang.Runnable with a toString method:

package somepkg

import "Java/java/lang"

type GoRunnable struct {
    lang.Runnable
}

func (r *GoRunnable) ToString(this lang.Runnable) string {
    ...
}

The "this" parameter is implicit in the sense that the reverse generator
automatically fills it with a reference to the Java instance of
GoRunnable.

Note that "this" has the type Java/java/lang.Runnable, not
Java/go/somepkg.GoRunnable, which renders it impossible to call Java
methods and functions that expect GoRunnable. The most practical example
of this is the Android databinding libraries.

This CL changes the implicit this parameter to always match the exact
type. In the example, the toString implementation becomes:

import gopkg "Java/go/somepkg"

func (r *GoRunnable) ToString(this gopkg.GoRunnable) string {
    ...
}

One strategy would be to simply treat the generated Java classes
(GoRunnable in our example) as any other Java class and import it
through javap. However, since the Java classes are generated after
importing, this present a chicken-and-egg problem.

Instead, use the newly added support for structs with embedded prefixed types
and synthesize class descriptors for every exported Go struct type.

Change-Id: Ic5ce4a151312bd89f91798ed4088c9959225b448
Reviewed-on: https://go-review.googlesource.com/34776
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:06:53 +00:00
Elias Naur
ca30483620 internal/importers: find structs with embedded types
Add support for using the Go AST package to find exported Go structs
that embed prefixed types. This is needed for a later CL to generate
wrappers for Go generated Java classes.

Change-Id: Ia304a7924a4e09332b74dc42a572932b7498cdca
Reviewed-on: https://go-review.googlesource.com/34775
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-05 11:51:35 +00:00
Elias Naur
fa10d8888b bind: fix inner class argument and return types
Change-Id: I1e74a7475ee3af491605e289685cda001ec80bb6
Reviewed-on: https://go-review.googlesource.com/34647
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-04 17:11:03 +00:00
Elias Naur
aa9922ad4c internal/importers/java: fix test
The recent change to specify the Java bootclasspath for the Java
importer wasn't propagated to the test. Fix that.

Change-Id: I740fb14e17b4406fe0ccf97d46f28852e0630b5d
Reviewed-on: https://go-review.googlesource.com/33393
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-21 15:27:45 +00:00
Takuya Ueda
48338d0785 internal/importers/java: specify language for javap command by -J-Duser.language=en
In Japanese environment, `javap` report errors in Japanese.

```
$ /usr/bin/javap -s -protected -constants com.example.ExampleClass
エラー: クラスが見つかりません: com.example.ExampleClass
```

But `java.Importer.Import` handles errors using `javap`'s output in
English.

So `javap` should be called with `-J-Duser.language=en` option.

Fixes golang/go#17987

Change-Id: I63d30cd49446523e54df2beae8d3f09f9de9bca5
Reviewed-on: https://go-review.googlesource.com/33371
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-11-21 14:51:32 +00:00
Elias Naur
6ea0bb5370 internal/importers: introduce package to analyze ObjC types
The objc package adds a parser that uses the clang -cc1 -ast-dump
command to extract type information about ObjC classes and protocol.

The resulting type information is needed to generate ObjC API wrappers
in Go.

This is the first part of the implementation of proposal golang/go#17102.

For golang/go#17102

Change-Id: I8382b54c0bd315703ec5a62cc177e1a2ace061e9
Reviewed-on: https://go-review.googlesource.com/29173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-05 13:16:13 +00:00
Elias Naur
16fd47fa04 bind: don't inherit java.lang.Object methods to Java interfaces
Before, the Java generator let Java interfaces inherit java.lang.Object
methods. However, interfaces strictly doesn't inherit Object and since
the JNI GetMethodID returns NULL for Object methods on interface classes,
stop making Object a super class to interfaces.

Change-Id: I3757c1ed02c07ccffab74a30132d5197742c6513
Reviewed-on: https://go-review.googlesource.com/30096
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-10-01 18:55:04 +00:00
Elias Naur
e04a76eb64 cmd/gomobile,internal: add bootclasspath and classpath flags to gomobile
Add -bootclasspath and -classpath flags to the gomobile tool. In a
follow-up CL, the gobind gradle plugin will use them to support R and
databinding classes from Go.

Change-Id: Id33acf0c3fe1ec3908740b2a736ed241fa6391c2
Reviewed-on: https://go-review.googlesource.com/30092
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-09-30 20:31:20 +00:00
Elias Naur
2dcaa053a0 bind: preserve no-arg Java constructors
When the Java class parser began culling unused constructors, the
logic for determining whether a given Java class has a no-arg
constructor broke when the no-arg constructor is culled. Add
an explicit field for tracking the no-arg constructor property.

Change-Id: Ib68929ae1108bd6fa1fd23de1d134332eb0d97a2
Reviewed-on: https://go-review.googlesource.com/29875
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-09-30 14:00:14 +00:00
Elias Naur
e4531be66f internal/importers: introduce package to analyze Java classes
The importers package adds functions to traverse the AST of a Go
file or set of packages and extract references to Java packages and
types.

The java package adds a parser that uses the javap command to extract
type information about Java classes and interfaces.

The resulting type information is needed to generate Java API wrappers
in Go.

This is the first part of the implementation of proposal golang/go#16876.

For golang/go#16876

Change-Id: Ic844472a1101354d61401d9e8c120acdee2519df
Reviewed-on: https://go-review.googlesource.com/28595
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-16 17:24:51 +00:00
Elias Naur
94417f6861 mobile/internal/binres: skip test if ANDROID_HOME is unset
Change-Id: I68ac06ad2f56dcd15e325a039c4d5d22ee1f862f
Reviewed-on: https://go-review.googlesource.com/20256
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-06 14:48:51 +00:00
Daniel Skinner
4e994ac070 internal/binres: use pkg binres for manifest encode
Current output byte-for-byte of pkg binres is close,
but not exact, to output of aapt.
The current exceptions to this are as follows:
 * sort order of certain attributes
 * typed value of minSdkVersion
These differences do not appear to affect the encoded
manifest from working correctly. Further details on
the byte differences can be seen in TestEncode.

Fixes golang/go#13109

Change-Id: Ibfb7731143f0e2baeeb7dd5b04aa649566606a53
Reviewed-on: https://go-review.googlesource.com/20030
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-05 06:30:01 +00:00
Daniel Skinner
0ee7f82d68 internal/binres: move test-related code out of package source
Change-Id: I5989c9395ff1aa40869ccd123cb277eea992a64c
Reviewed-on: https://go-review.googlesource.com/19991
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-03 05:14:23 +00:00
Daniel Skinner
1fb745cd55 internal/binres: encode manifest correctly for packaging
This fixes remaining issues that prevented use of package
to encode manifest for packaging correctly.

* Chunk headers are now encoded based on content
* Fixes for namespace and value fields
* Improved sorting based on native aapt output

Change-Id: Ic63046973a7b0431533463ed4dd2de50f1d73191
Reviewed-on: https://go-review.googlesource.com/19224
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-16 04:56:14 +00:00
Daniel Skinner
002f07f8be internal/binres: sort element attributes
Change-Id: I3ff6b98aa1c729600f154272b8250f673ae2778f
Reviewed-on: https://go-review.googlesource.com/19040
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-05 00:56:26 +00:00
Daniel Skinner
789dd7a15a internal/binres: provide validation for all remaining bootstrap resource types
Change-Id: I1f9b030e4230706ea5bbf9b7d9e1f398b93abe0b
Reviewed-on: https://go-review.googlesource.com/19005
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-05 00:56:17 +00:00
Daniel Skinner
c24337bea7 internal/binres: unmarshal map from xml
Change-Id: Ica95827fcf192f181b73fdf65b0158b8d3e24fdc
Reviewed-on: https://go-review.googlesource.com/18589
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-01-29 00:58:43 +00:00
Daniel Skinner
b8ddff8878 internal/binres: table marshal methods with pack func
The OpenTable func now references a prepacked version of the
resources.arsc file with a number of entries removed. The current
size of this file is 62KB. This could be dropped further by
implementing utf8 in string pool during marshal, utf16 encoding exploded
the original size by approximately 20%. Another potential improvement
is to allow type entries to be packed sparsely which may provide
significant savings if not zipping.

Change-Id: Ie139c2bdb0e3c5a9212516d18cf627d75774e187
Reviewed-on: https://go-review.googlesource.com/18649
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-25 00:55:53 +00:00
Daniel Skinner
db7fc23f7b internal/binres: unmarshal pool from xml doc, update tests to target api-15
Change-Id: Iaa13d4352ef88b58e805d5c0d8ee8a1e107db3c3
Reviewed-on: https://go-review.googlesource.com/18583
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-25 00:55:03 +00:00