Commit Graph

1063 Commits

Author SHA1 Message Date
Elias Naur d05d36a362 misc/androidstudio: fix the classpath for gobind and gomobile
Before this CL, the JavaCompile.classpath property was evaluated early,
which resulted in missing classpath entries for first-time runs of
gradle. Delay the evaluation, making sure gobind and gomobile receives
the complete classpath.

Change-Id: Iba9be0bbf9f563eb18b2549ac8267f8db3b7dec1
Reviewed-on: https://go-review.googlesource.com/35177
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-01-17 14:22:50 +00:00
Elias Naur d8b1e1aab8 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>
2017-01-17 14:22:42 +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 1aa9ad5c48 bind: generate reverse functions the same way as methods
This CL restructures function generation to match the way methods
are generated, to avoid two different code paths for a coming CL.

Change-Id: I5a4f15e51ea5df101f9aa419ed4170ab36506418
Reviewed-on: https://go-review.googlesource.com/35185
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:01:43 +00:00
Elias Naur 100a59ffc1 bind: fix reverse binding generation on Windows
The filepath package works on native paths, not package paths. Replace
it with the path package. Do it for Objective-C as well, for correctness.

No new tests; the existing reverse tests fails on Windows without
this CL.

Change-Id: I8963db992d4bed30e8828579fb83ecaf8c9d9ade
Reviewed-on: https://go-review.googlesource.com/35176
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-01-13 10:02:40 +00:00
Elias Naur 64505ab867 exp/audio/al: use the correct native library dir to locate libopenal.so
Use Context.getApplicationInfo().nativeLibraryDir to locate
libopenal.so. That path is always correct, even on newer devices.

Found while testing external NDK use on Windows.

Manually tested; there are no existing OpenAL tests or examples.

Change-Id: Ie204a7d7139566f85c9121126722ad597f9d6b19
Reviewed-on: https://go-review.googlesource.com/35175
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-01-13 01:38:11 +00:00
Elias Naur 91f2c8983e bind/java: fix tests on Windows
Make the golang.org/x/mobile/bind/java buildable without CGO, and
replace the which tool with exec.LookPath. Both helps on Windows that
often don't have a C compiler available and no which command.

Found while testing external NDK use on Windows.

Change-Id: I6d3311aae3fa97acb61b5ab9bed334e4a608c386
Reviewed-on: https://go-review.googlesource.com/35174
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-01-13 01:37:47 +00:00
Elias Naur 2802a0168e bind: include all generated code in tests
The tests was missing the generated code for the universe package
and some parts of the reverse generated code. Include it.

Change-Id: Id5e2f215c8f6f717c30377965255c4b64f31e923
Reviewed-on: https://go-review.googlesource.com/34992
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-12 22:17:26 +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 9ec2d17db2 cmd: fix handling of (multiple) tags
The gomobile tool mishandled build tags in two ways, first by
ignoring tags for iOS, second by passing multiple tags along to
the go tool incorrectly. This CL fixes both.

Fixes golang/go#18523
Fixes golang/go#18515

Change-Id: I28a49c1e23670adb085617d9f5fb5cd5e22a4b65
Reviewed-on: https://go-review.googlesource.com/34955
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-12 22:00:16 +00:00
Elias Naur 82c03f1188 cmd/gomobile: document the GOMOBILEFLAGS, GOARCH, GOBIND plugin settings
Change-Id: I681ac02869e137f67880416743352951960f7d8a
Reviewed-on: https://go-review.googlesource.com/33950
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-12 21:57:09 +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 f5d8ba6777 bind: support Java packages with the same last component
Before this CL, using the reverse bindings to access two Java packages
with the same last component would fail with a duplicate package import
error. This CL renames generated import statements to use unique
aliases.

Change-Id: I94696281e58f011f45811445cf81aea02af69c4f
Reviewed-on: https://go-review.googlesource.com/34774
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-05 11:50:37 +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 e0bb90a948 bind: clear JNI return values when an exception was raised
The return value of a JNI call is undefined when an exception was
raised during the call. To make sure comparisons with NULL works,
clear the value when an exception is raised.

No new tests; some devices, like the Samsung S2, crashes with the
existing tests without this CL.

Change-Id: I85eb983e9444fff1f05e0f83a0640d106280e54d
Reviewed-on: https://go-review.googlesource.com/34631
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-27 15:54:01 +00:00
Elias Naur 6a96d4c7cf bind: make the default name prefix empty on ObjC
Since generated names now have their package names prefixed, the
extra prefix, "Go", is both confusing and counter-productive to
making the generated ObjC code look like any other native code.

Change the default to the empty prefix, while preserving support
for an explicit prefix if needed.

This is a backwards incompatible change; to keep the old behaviour,
specify "-prefix Go" to the gobind or gomobile command.

While we're here, fix the Ivy example for the recent change in
error returns.

Change-Id: I7fef4a92a18ddadee972ccf359652e3b31624f33
Reviewed-on: https://go-review.googlesource.com/34643
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-24 13:37:27 +00:00
Elias Naur 60feeb77f4 bind,cmd: support the empty ObjC prefix
Since the Go package name is already prefixed to generated ObjC
names, the empty extra prefix is useful. Support that by not reverting
to the default extra prefix, "Go", if -prefix "" is specified.

To avoid file name clashes with the Go header files, add ".objc" to
the ObjC-facing header names.

Change-Id: I559fe60d7474521617f23894af247c6019ff2a21
Reviewed-on: https://go-review.googlesource.com/33954
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-23 09:44:24 +00:00
Péter Szilágyi e1ac2f46b8 bind: don't use output arg for T in (T, error) returns if T is nullable
The current iOS binding generator only generates returns if the
function being bound does not return an error. If a second error
return type is also present, the binder always generates both the
primary as well as the error as an output parameter.

This is undersirable because most decent functions in Go will
also return errors, so all of those get converted to plain methods
iOS side, each of them requiring allocating the return variable
first and only then execute the call. This gets even more annoying
with the Swift error wrapping protocol which converts errors to
throw statements automatically, but which still needs the ugly pre-
allocs caused by the genrated bindings not returning the result,
just placing it in an output argument.

This CL changes that so that if a nullable result is being returned
by a bound method from Go, then it is generated as a proper return
and not an output argument. This allows erroring functions to still
be called as a function in ObjC, and even more elegantly drop even
the error part in Swift.

Change-Id: I35152d7d2fd2a132eba836fa23be8fd4f317f097
Reviewed-on: https://go-review.googlesource.com/34072
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-12-08 14:50:39 +00:00
Elias Naur 72eef9d093 bind: avoid crashes from SIGPIPE
The Go runtime doesn't handle SIGIPE signals from writing to closed
sockets or pipes in c-archive and c-shared mode (issue 17393).
Work around it in gomobile by simply ignoring all SIGPIPE signals;
they're not useful in mobile apps anyway.

Change-Id: Ibd7ee41058856c5eddb4a519345a3851a29e9b44
Reviewed-on: https://go-review.googlesource.com/33771
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-12-01 16:06:28 +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
Takuya Ueda 98823363be misc/androidstudio: An example setting is wrong in README
REAME shows an example like this:

```
gobind {
  // Package to bind. Separate multiple packages with spaces.
  pkg "github.com/someone/somepackage"

  // GOPATH
  GOPATH "/home/gopher"

  // Optional list of architectures. Defaults to all supported architectures.
  GOARCH="arm amd64"

  // Absolute path to the gomobile binary. Optional.
  GOMOBILE "/mypath/bin/gomobile"

  // Absolute path to the gomobile binary. Optional.
  GOBIND "/mypath/bin/gobind"

  // Absolute path to the go binary. Optional.
  GO "/usr/local/go/bin/go"

  // Pass extra parameters to command line. Optional.
  GOMOBILEFLAGS "-javapkg my.java.package"
}
```

But this example is wrong because each settings need `=` between a key and value.

Fixes golang/go#17996

Change-Id: I0f7acca78aee1032a67c35308b4ce78f97b1aa43
Reviewed-on: https://go-review.googlesource.com/33372
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-21 14:18:27 +00:00
Elias Naur b8794a2669 cmd: update documentation and add pure Go Android app example
Update outdated documentation and add documentation and references
for the the new reverse binding support.

Add a new example, reverse, that demonstrates how to use Android
API directly from Go and thereby implement an Android app in pure
Go.

Change-Id: Iac054dbc015d00a37c0cc234931f9bd90172848e
Reviewed-on: https://go-review.googlesource.com/31170
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-03 14:40:43 +00:00
Elias Naur 276a798324 misc/androidstudio: fix gobind gradle plugin test
Change-Id: Icbec67cbc000e4770ccc82a95a1a9ce1e22bbc18
Reviewed-on: https://go-review.googlesource.com/32592
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-11-03 14:21:49 +00:00
Egon Elbre d3620154ae x/mobile/gl: fix building on windows/386
Fixes golang/go#15763

Change-Id: Iead7d69367ee5c821aefd1faed56bb3b259b6a62
Reviewed-on: https://go-review.googlesource.com/32113
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-26 17:46:18 +00:00
Elias Naur 27a7c7e186 bind: add -Werror to gomobile bind CFLAGS
C compiler warnings are hidden in the gomobile build process. Expose
them through -Werror.

Change-Id: I2d87e5985f9ff874dc6feb836ba35c2bd848bfa6
Reviewed-on: https://go-review.googlesource.com/31517
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-21 19:49:24 +00:00
Elias Naur 23d9c7b685 bind: skip benchmarks in short mode
The bind benchmarks are implemented as Go tests, but take quite a
while to run. Skip them in short mode.

Change-Id: I49ede84863b047aa8307bc0ef752fc7aa21e2d65
Reviewed-on: https://go-review.googlesource.com/31637
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-21 19:42:06 +00:00
Elias Naur e107ad8ed2 bind: sanitize parameter names
Package names, type names and method names are already sanitized.
Extend that to parameter names as well.

Change-Id: I408024c5e2f9561c37e8059a2b53199ee1afaef6
Reviewed-on: https://go-review.googlesource.com/31519
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-21 09:25:03 +00:00
Elias Naur 7f64fd241f bind: fix compiler warnings
CL 29298 got rid of error type wrappers, but failed to update a
variable type accordingly.

Exposed by CL 31517 that enables -Werror.

Change-Id: I2c2b75dcd43b89ffa7fb008150b1aee09ec25229
Reviewed-on: https://go-review.googlesource.com/31518
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-21 09:24:50 +00:00
Péter Szilágyi 2ea7e2cc92 bind, bind/java: support generating exceptional constructors
In Go type constructors can often return an error type too
beside an instance of the type being created. This is useful
in cases where the parameters might be wrong and instantiaion
cannot succeed. This CL extends the Java generator so that
these methods are also converted into class constructors that
also can throw.

Change-Id: I5e531eec126904a026767a8503968255b9fd833b
Reviewed-on: https://go-review.googlesource.com/31184
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-10-17 14:21:52 +00:00
Elias Naur 4cb3e7f634 bind: accept implicit `self` parameters in all methods
This is the ObjC equiivalent to CL 30276. It expands support for
implicit `self` parameters to every exported method.

Change-Id: Iff8a956b38448213866a93dc02ca59cac592feef
Reviewed-on: https://go-review.googlesource.com/30277
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-17 10:37:36 +00:00
Elias Naur 1c49d29d1c bind,cmd: accept ObjC wrapper types in bound packages
Accept ObjC API wrapper types as arguments and return values from
bound Go package functions and methods. Also, allow Go structs
to extend ObjC classes and implement ObjC protocols as well as override
and implement methods.

This is the third and final part of the implementation of the golang/go#17102
proposal.

Fixes golang/go#17102

Change-Id: I601d90fb6d22b8d6f8b7d5fe0130daa1a4dd4734
Reviewed-on: https://go-review.googlesource.com/29175
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-17 10:37:16 +00:00
Elias Naur 63993740dd bind: fix field accessors for Go implemented Java classes
The go_seq_to_refnum function handles its argument object as a Java
object if it doesn't implement Seq.Proxy. Java classes implemented in
Go does not implement Seq.Proxy, but when passing "this" references to
Go, instances must be treated as a Go object.

Use go_seq_to_refnum_go everywhere "this" is passed to Go, which fixes
field accessors and simplifies the method call case.

Change-Id: I3d01c63d7b2081e6344ece431f5e5021a9dd7662
Reviewed-on: https://go-review.googlesource.com/31171
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-17 10:26:22 +00:00
Alex Brainman eb6d6dca20 cmd/gomobile: use correct version of clang on windows/386
Fixes golang/go#16823
Fixes golang/go#17376

Change-Id: Ia9c15242cce66eca1d36a5e1dc6106b3549c251d
Reviewed-on: https://go-review.googlesource.com/31110
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-10-17 00:13:54 +00:00
Elias Naur 6ecf8eedb8 bind,cmd: add generator for ObjC API wrappers
Using the new ObjC type analyzer API, scan the bound packages for
references to ObjC classes and protocols and generate Go wrappers for them.

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

For golang/go#17102

Change-Id: I773db7b0362a7ff526d0a0fd6da5b2fa33301144
Reviewed-on: https://go-review.googlesource.com/29174
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-16 10:25:40 +00:00
Elias Naur a82bb3c8ba cmd/gobind,bind: generate complete Java interface with gobind
Output every Java class, including the support classes, from gobind
-lang=java. In addition, replace Go package export data parsing with
converting from go/ast to go/types. That way, gobind can tolerate
unknown imports as long as the exported Go API doesn't use them.

In a follow-up CL, the gobind gradle plugin will use gobind for a first
pass to expose the generated Java classes to the android plugin.

Change-Id: I8134899ec818c7fee79e4d9df8afcae9dd679add
Reviewed-on: https://go-review.googlesource.com/30093
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-14 13:14:45 +00:00
Egon Elbre 91c29e2bb7 x/mobile/gl: fix windows context3 and dlls
Add missing context3 for Windows.
Add missing d3dcompiler_47.dll loading.
Check whether dll architecture matches.
Search ANGLE from Chrome path.

Fixes golang/go#16991

Change-Id: Ia042f75241c2398fabda03bb2d0e683eb34545c7
Reviewed-on: https://go-review.googlesource.com/28814
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2016-10-13 20:58:55 +00:00
Russ Cox a4f0a77f2f bind: param name replacement for invalid unicode names
The are three generators that currently call this method:
    A  -> B
(1) go -> java
(2) go -> objective-c
(3) go -> go

As discussed below, we only substitute for invalid unicode characters
in case (1).

**Case 1**
Go:
From golang.org/ref/spec:
Identifiers name program entities such as variables and types.
An identifier is a sequence of one or more letters and digits(unicode_digit).
The first character in an identifier must be a letter(unicode_letter | "_" ).

Java:
From https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8
`The "Java letters" include uppercase and lowercase ASCII Latin letters
A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons,
the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $
character should be used only in mechanically generated source code or,
rarely, to access pre-existing names on legacy systems.`

Therefore, Go's identifiers are checked in case they break these Java rules.

**Case 2**
There is no objective-c standard specification for valid identifiers.
From some testing it seems that Go and objective-c have identical
valid identifier rules.

**Case 3**
Requires no checking.

Change-Id: I881810eb9355af6a418727ace32cb6ce4266b2a0
Reviewed-on: https://go-review.googlesource.com/14044
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-12 18:37:41 +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 4db6347e33 misc/androidstudio: add support for the android gradle plugin
The gobind plugin exposes a set of Go packages as a AAR file ready to be
used by and Android project. Unfortunately, being a library project
limits the Go packages to access only the Java API from the standard
library and the Android SDK.

This CL tightens the integration with the Android plugin to support access
to project dependencies such as the Android Support Library, to the generated
R.* resource classes and finally to the Android databinding classes.

When the gradle project has loaded the Android plugin, the generation of
the Go library is split in two.
First, the gobind tool generates the Java classes for the bound Go
packages. In this step, Go packages can access the standard Java and Android
libraries as well as project dependencies. After this step, Android
databinding layout files can refer to Go classes.
In step two, the gomobile tool generates the JNI libraries
with the Go implementation of the generated Java classes. In this
step, Go can access the standard Java and Android libraries,
dependencies as well as R.* and generated databinding classes.

Change-Id: If853ecabdbd01eec5f89d064a6bc715cb20a4d83
Reviewed-on: https://go-review.googlesource.com/30094
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-05 13:08:54 +00:00
Elias Naur e76ec53021 bind: support casting of Java objects
Generate Cast functions that take a proxy for a Java class or interface,
and return a new proxy with the same reference. The Cast functions
panic if the underlying Java object is not an instance of the expected
type.

Change-Id: I08a5bf9a79139f0fac5dd102c7b028c8c989fc6d
Reviewed-on: https://go-review.googlesource.com/30095
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-05 08:40:06 +00:00
Elias Naur 69dc8e1c38 bind: allow implicit `this` argument on every exported method
Before this CL, the implicit `this` arguments to methods on Java classes
implemented in Go was only supported on overriding methods, because
their parameter count are known. This CL expands support for the `this`
parameter to every exported method. It only recognizes parameters named
`this` declared with a Java wrapper type.

Change-Id: I8a9d3417d259bdfcc28512a72f07d6a05f483adc
Reviewed-on: https://go-review.googlesource.com/30276
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-05 07:49:55 +00:00
Elias Naur 3f7b83ffd4 bind: generate Java constructors for every exported struct
A recent CL added Java constructors to generated classes that extends
or implements other Java classes and interfaces. Constructors for a
struct S are Go functions on the form

func NewS...(...) *S

If no such constructors exists, a default empty constructor is
generated.

Expand that to cover every exported Go struct.

Fixes golang/go#17086

Change-Id: I910aba13d5884c3f67c946c62a8ac4a3db8e2ea7
Reviewed-on: https://go-review.googlesource.com/29710
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-05 07:47:24 +00:00