Commit Graph

1063 Commits

Author SHA1 Message Date
Hajime Hoshi 973feb4309 cmd/gomobile: skip TestWriter
TestWriter is flaky and often fails on the trybots. Skip this as a
tentative solution.

Updates golang/go#40290

Change-Id: I3a8aa74fb6cb727a216da4046edaa159f9aa2dc3
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/243839
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-08-01 11:21:45 +00:00
Hajime Hoshi bcce011712 cmd/gomobile: remove darwin/386 support
Go 1.15 no longer supports darwin/386 and supports only arm64 and amd64
for darwin.

Updates golang/go#39575

Change-Id: I89e43f195f87baf5ea647da40614c579fbe45f88
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/243838
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-07-21 16:15:23 +00:00
Hajime Hoshi 68de546597 cmd/gomobile: fix the test for Go 1.15
This is a remaining task for golang/go#39575.

Updates golang/go#39575

Change-Id: I10c021a9349461a7a773d4e93e80601b906741b2
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/243837
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-07-21 16:14:50 +00:00
Hajime Hoshi 1a48f808d8 cmd/gomobile: use arm64 at packagesConfig
Go 1.15 no longer supports darwin/arm. arm64 is still supported by
Android and iOS.

Updates golang/go#39575

Change-Id: I91f09477ae68de148e4d63eef38d7d28f553d16c
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/241717
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-07-20 14:09:40 +00:00
Hajime Hoshi 588b2b2fb0 cmd/gomobile: fix the error when specifying -target=ios with Go 1.15
Go 1.15 no longer supports darwin/arm. This CL fixes by replacing
'allArchs' variable with a function taking a target OS, and excludes
'arm' when the target OS is iOS.

Updates golang/go#39575

Change-Id: I0623ed4cda2c679d2762fd80a7919f24dd5ce016
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/243477
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-07-20 14:09:13 +00:00
Hajime Hoshi 33b8054058 cmd/gomobile: use the specified output name for the module name on iOS
When the module name in *.modulemap and the framework name don't match,
Xcode fails to find the framework.

This CL fixes this issue by using the specified .framework name for the
module name.

Fixes golang/go#35641

Change-Id: I0df5335f2d64f0529e7357c2d04af5eaf760a879
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/239237
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-06-29 15:35:29 +00:00
Hajime Hoshi 4c31acba00 cmd/gomobile: keep the module version information as much as possible
Before this change, the main module specifies the module version of the
package to bind, the version might not be adopted by gomobile because
gomobile trims some dependencies information. If a dependency is not
a main module nor a replaced module, the dependency information is
omitted.

For example, if you have this go.mod in a workspace:

    module example.com/m

    requier (
        github.com/foo/bar v0.1.0-123456
    )

and then run `gomobile bind github.com/foo/bar` there, the specified
version might not be used because github.com/foo/bar is not a main nor
a replaced module.

This change keeps the dependency information as much as possible
to avoid this confusion.

Updates golang/go#37048

Change-Id: I875a1b9485438bdee336f3fc2d131775353004f5
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/226279
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-03-29 12:56:38 +00:00
Hajime Hoshi 3c8601c510 app: fix comparison of keys' direction
KeyEvent's getAction returns ACTION_DOWN (0), ACTION_UP (1) or
other values, and not AKEY_STATE_DOWN (1) or AKEY_STATE_UP (0).
This change fixes the wrong comparison.

Fixes golang/go#37374

Change-Id: Ia65ac881e57cc29d4bdde2365e177c2b4499a2d9
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/220538
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-02-22 14:29:34 +00:00
Hana Kim 2b26a4705d cmd/gomobile: handle modules replaced by other versioned modules
Previously, gomobile bind's go.mod generation logic assumed
replacing module was always located in the disk, but is not
always true. It's valid to replace a module(version) with
another module&version.

For example,

replace golang.org/x/tools => ../

causes:

{
        "Path": "golang.org/x/tools",
        "Version": "v0.0.0-20191017151554-a3bc800455d5",
        "Replace": {
                "Path": "../",
                "Dir": "/usr/local/google/home/hakim/go/src/golang.org/x/tools",
                "GoMod": "/usr/local/google/home/hakim/go/src/golang.org/x/tools/go.mod",
                "GoVersion": "1.11"
        },
        "Dir": "/usr/local/google/home/hakim/go/src/golang.org/x/tools",
        "GoMod": "/usr/local/google/home/hakim/go/src/golang.org/x/tools/go.mod",
        "GoVersion": "1.11"
}

replace github.com/anacrolix/torrent v1.13.0 => gitlab.com/axet/torrent v0.0.0-20200205141541-92b4b9e7387e

causes:

{
        "Path": "github.com/anacrolix/torrent",
        "Version": "v1.13.0",
        "Replace": {
                "Path": "gitlab.com/axet/torrent",
                "Version": "v0.0.0-20200205141541-92b4b9e7387e",
                "Time": "2020-02-05T14:15:41Z",
                "Dir": "/usr/local/google/home/hakim/go/pkg/mod/gitlab.com/axet/torrent@v0.0.0-20200205141541-92b4b9e7387e",
                "GoMod": "/usr/local/google/home/hakim/go/pkg/mod/cache/download/gitlab.com/axet/torrent/@v/v0.0.0-20200205141541-92b4b9e7387e.mod"
        },
        "Dir": "/usr/local/google/home/hakim/go/pkg/mod/gitlab.com/axet/torrent@v0.0.0-20200205141541-92b4b9e7387e",
        "GoMod": "/usr/local/google/home/hakim/go/pkg/mod/cache/download/gitlab.com/axet/torrent/@v/v0.0.0-20200205141541-92b4b9e7387e.mod"
}

Also, while we are here, trim down the entries added to the generated
go.mod. We need the main module, and the replaced module info.
We may want to pin golang.org/x/mobile version if possible, but I don't
know a reliable way to achieve that yet.

Fixes golang/go#37048

Change-Id: Ibd7332338c0a3c4165a642c3e86852061f6ab13b
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/218057
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
2020-02-12 15:27:14 +00:00
Hajime Hoshi 0df4eb2385 cmd/mobile: add an arbitrary package to go-list at gomobile-init
go-list without a given module/package tries to analyze the module
at the current directory. If the current directory's module doesn't
have any Go files and is empty, go-list fails. This is the cause
of the problem that gomobile-init fails if the current directory
is such module.

This CL fixes this issue by giving an arbitrary standard library
when executing go-list.

Fixes golang/go#36668

Change-Id: If72d88081c94c2b9ef19d2870b41956a07102122
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/217700
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-02-05 17:02:28 +00:00
Hajime Hoshi 82c397c4c5 cmd/gomobile: always use abolute paths to replace in go.mod
A replative path in go.mod works only in the directory of the
go.mod. When creating go.mod for gobind, copying relative paths
did not work since go.mod is in a different temporary directory.

This CL fixes the issue to use Dir, which is an absolute path to
the module, instead of Path.

Updates golang/go#27234

Change-Id: Ib009ec508aa3ce3d092af14f921a57192feaac61
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/215421
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-01-23 02:49:42 +00:00
Hajime Hoshi 23a0503ab4 cmd/gomobile: enable Cgo
This CL gives CGO_ENABLED=1 explicitly when executing gobind since
Cgo is disabled by default when GOOS is given.

This CL also adds importing C to the tests to confirm that Cgo
works correctly.

This CL also updates go.mod since this change requries the change
in go/packages: golang.org/cl/214943

Updates golang/go#27234
Updates golang/go#36547

Change-Id: I66f9697f992f15b52fca7871e4e0ed64ca2b4965
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214498
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-01-23 02:49:29 +00:00
Hajime Hoshi 1d4ecbb920 cmd/gomobile: output an error message at gomobile-init
Updates golang/go#36668

Change-Id: Ic93ea6334dae3fef953bbb928c5246b03279a22f
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/215419
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2020-01-21 16:05:05 +00:00
Hajime Hoshi 0c13fd3166 gl: enable use of buffer objects for TexSubImage2D by nil
This CL enables use of a bound buffer at TexSubImage2D by allowing
nil (0) data, which indicates the head of the bound buffer.

In the long run, we need to be able to pass non-0 integer to not
only TexSubImage2D but also other functions like TexImage2D. As we
might change the API, let's revisit this issue later.

Fixes golang/go#36355

Change-Id: I66f6650b10fca9a346cfa6eba246ea9286ed3a85
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/213077
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-01-19 07:00:23 +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 875e90d6f7 cmd/gomobile: disable bitcode on Go 1.13 or older
iOS's bitcode conflicts with headerpad on Go 1.13 or older. This
problem is fixed on Go 1.14.

This CL disables bitcode only on Go 1.13 or older.

Fixes golang/go#32963

Change-Id: Iac9edd56aaf7819288e8f46b9e29d310305acd9d
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214899
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-01-15 17:48:49 +00:00
Hajime Hoshi af4a92906a cmd/gomobile: enable Go modules at gomobile-build
This CL enables Go modules at gomobile-build command. This CL is
a counterpart for the change gomobile-bind: https://golang.org/cl/210380

This CL also reformats the tests in bind_test.go

Updates golang/go#27234

Change-Id: I9fb9612be6b08f5f61259879f563c8586fb1efef
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214897
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>
2020-01-15 16:36:13 +00:00
Hajime Hoshi 56347cccba cmd: replace goBin() with a plain string "go"
This was introduced at https://go-review.googlesource.com/c/mobile/+/191518
originally, but this change was against the decision at
golang/go#26845.

"go" always works even when Go command that name is not "go", like
"go1.14beta1" is used. See also the discussion at golang/go#28043

Change-Id: Ifebe969edaeda0373b2840d25a4f4030509176fa
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214898
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2020-01-15 09:57:20 +00:00
Hajime Hoshi b9f03b3fa3 cmd/gomobile: remove the logic to clean the given path
This CL fixes an issue that a relative path didn't work with
gomobile. path.Clean removed the prefix './' and this was too
aggressive. path.Clean was needed for go/build.Context.Import
(see golang/go#18876), but they have already been replaced with
packages.Load, so clearning paths is no longer needed.

Updates golang/go#27234

Change-Id: Ife28da6d845baaf94e627a7a44a5e962b8a1d013
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214497
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-01-13 19:03:25 +00:00
Hajime Hoshi 1d13e329d2 cmd/gomobile: enable Go modules in gomobile-bind
This CL enables Go modules in gomobile-bind command. This CL
generates go.mod at $WORK/src based on the modules state of the
working directory, and use it when executing go-build.

Updates golang/go#27234

Change-Id: I6958f29a317c0d2fb9ffa373f6e3c4cabdc4e898
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/210380
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-01-13 15:31:55 +00:00
Hajime Hoshi 1a1fef8273 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>
2019-12-10 15:19:39 +00:00
Hajime Hoshi 5c0e7e404a cmd/gomobile: change the working directory to $WORK/src/gobind when go-building
This is a preparation to enable Go modules for gomobile commands.

When Go modules is used, $GOPATH is not available. To build a
local package with Go modules, changing the working directory and
specifying the package by a relative path begining with `./` is
required. Changing the working directory is necessary because
building outside of modules is forbidden.

Specifying $GOPATH is still needed for reverse bindings (i.e.
special packages begining with `Java/` or `ObjC/`). Note that
gomobile with Go modules cannot support reverse bindings so far.

Updates golang/go#27234

Change-Id: Ib19300e1b8a973e76e06d24472c63a98605d65f7
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/209137
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-30 19:14:48 +00:00
Hajime Hoshi d9e324ca8c cmd/gomobile: remove go/build usages from build.go
This CL is a pure refactoring. This removes a global variable ctx,
which is a build.Default.

Before this change, ctx was used to keep build tags and its state
affected go command executions. As the variable is mutable, the
code was not readable.

This changes introduces another global variable buildTags instead,
but this is more consistent with other build flags, and this is
immutable.

Updates golang/go#27234

Change-Id: Id8d0c779de21b249e96febd2f40833cd0c84534f
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/208060
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-23 05:49:42 +00:00
Hajime Hoshi 08e574b148 cmd/gomobile: replace go/build with go/packages in gomobile-build
This is a preparation to use Go modules at gomobile command.

Updates golang/go#27234

Change-Id: I8ee47cb53f5b748592a0c8c9f383abab27a7fdad
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/208059
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>
2019-11-23 05:48:59 +00:00
Hajime Hoshi 8715129287 cmd/gomobile: remove an unsed function
Change-Id: I2d5fcebd96de1d81d01c2b0765a292897b404a5a
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/208058
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-20 16:19:35 +00:00
Hajime Hoshi 26e634b6c9 cmd/gomobile: remove a global variable
This CL is a pure refactoring to remove a global variable.

Change-Id: I996c6a15354163e90148bc2540bda6b56296271c
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/208057
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-20 16:19:11 +00:00
Hajime Hoshi f0c40035f2 cmd/gomobile: replace go/build with go/packages in bind
This is a preparation to use Go modules at gomobile-bind.

Updates golang/go#27234

Change-Id: I33684888b4181cc1ebd4d3c8872a6b2e62950855
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/206777
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-15 02:22:31 +00:00
Hajime Hoshi 6a1b097663 cmd/gobind: enable TestDocs tested with Go modules
This CL fixes TestDocs to test with Go modules by packagestest.

Updates golang/go#27234

Change-Id: I9055f52d26e494cd3b71b59d3db0755d415df356
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/206737
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-15 01:59:51 +00:00
Hajime Hoshi c2e8f9e9c7 cmd/gobind: add tests enabling Go modules
This CL adds tests with Go modules enabled.

Updates golang/go#27234.

Change-Id: I8a583c929ed9151e3b3220b4e669ff572361bb0e
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/195937
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-11-12 16:56:57 +00:00
Hajime Hoshi 0945064e01 cmd/gobind: remove go/build and go/import usages from main.go
This change removes the usages of go/build and go/import, that don't
work with Go module.

Before this change:

  1) Package information is retrieved by go/packages
  2) Files for reverse bindings are generated
  3) Package information is retrieved by go/imports

After this change, only 3) will be changed:

  3) Package information is retrieved by go/packages again only when
     reverse binding is used.

This is preparation to support Go modules.

Updates golang/go#27234

Change-Id: I1997f71f23455fdd3b3c6b2643d35ec33ad147a3
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/203399
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-10-31 02:03:45 +00:00
Hajime Hoshi 73ccc5ba04 cmd/gobind: replace go/build with go/packages in gen.go
This is preparation to support Go module.

Updates golang/go#27234

Change-Id: I8dcaed231e877e81d2072c7c85321c0acb6a8b1b
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/203397
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-25 11:06:07 +00:00
Hajime Hoshi d309294bef bind: update the golden data for Objective-C
Fixes golang/go#35148

Change-Id: I4ee2b667e1eb3df3f263a66671cf7d6a89804830
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/203398
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-10-25 10:49:55 +00:00
Hana Kim 6d0d39b2ca bind: format generated go code before comparing with golden files
bind_test.go compares the generated Go files against golden files
checked in the repository. The bind package formats some of the
generated Go files, so any changes in the go formatter can break
the tests.

This change makes the test more robust by applying formatting based
on the currently used go version. Since a golden file often
includes multiple go files generated by the bind, the `gofmt`
function splits the golden file using the gobindPreamble marker
and then run format.Source for each chunk. In order to ease the
golden file splitting, this CL also moves the gobindPreamble
to the beginning of each generated file consistently.

It turned out bind omits formatting for some go files (generated
for reverse binding). That needs to be fixed but it is a much
bigger fix. Thus, in this CL, we apply the formatting on the
bind's output as well.

This CL also updates the gobindPreamble to follow the style guide
for generated code. https://golang.org/s/generatedcode

Fixes golang/go#34619

Change-Id: Ia2957693154face2848e051ebbb2373e95d79593
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/198322
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-10-02 17:59:09 +00:00
Robin Zhong d3ece3b6da add -trimpath build flag.
Add the "-trimpath" flag from Go 1.13.

Change-Id: I10938fb5f7efd701f4025e451ddf438dc3e011ee
GitHub-Last-Rev: 4e82381342e2c13c318514800bc82af7f6ed9e1a
GitHub-Pull-Request: golang/mobile#39
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/196877
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-23 20:44:09 +00:00
Hajime Hoshi b558ed8633 all: update go.mod
The latest x/tools includes the fix
https://go-review.googlesource.com/c/tools/+/192330 for
golang/go#33937.

Updates golang/go#33937

Change-Id: I4af068315fb16aa3d526214f89e4005d792d0c49
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/194497
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-09-10 18:44:05 +00:00
Hajime Hoshi c6da959549 bind/java, bind/objc: do not use module for reverse binding
Reverse binding is not available with Go module, and some tests
fail due to this. This CL suppresses the errors by disabling Go
modules explicitly.

Updates golang/go#27234

Change-Id: I7483c1dab468548a2efa05ca426addf5c3d97b6e
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/192599
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-30 20:13:51 +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 30c70e3810 all: use GOROOT/bin/go instead of go everywhere
This is a non-test code version of CL 191517.

Using 'go' command in tests is confusing when using a different version
of Go (e.g., go1.13rc1). Use GOROOT/bin/go so that the same Go is used.

Change-Id: Id5937cfa6dd6d3164d5f774e3fc0fd15b7f613b5
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/191518
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-08-23 17:37:32 +00:00
Hajime Hoshi fe31116dde all: use GOROOT/bin/go instead of go for tests
Using 'go' command in tests is confusing when using a different version
of Go (e.g., go1.13rc1). Use GOROOT/bin/go so that the same Go is used.

Change-Id: I0ca297207acc5e7fd8b291f544302f6c7b0d38e1
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/191517
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-08-23 15:22:30 +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
Hajime Hoshi 597adff16a x/mobile: update dependencies
Change-Id: I830b0afbd9ac67a24302e56b3109a8b822e16b46
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/188837
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-08-06 16:23:12 +00:00
Nigel Tao d2bd2a29d0 gl: provide dummy impl when cgo is disabled
The dummy implementation doesn't do anything (at runtime), but it does
compile (when CGO_ENABLED=0), which e.g. unbreaks some build bots.

The work_other.go file is new, faking what's in work.go.

The changes to the other (existing) files simply re-order the
GOOS-related build constraints to be in a consistent order (alphabetical
order), the same as the existing order in work.go.

Fixes golang/go#32837

Change-Id: I19a196d4307b9ebc2f770fe41e1aec717a699288
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/185017
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2019-07-19 00:42:57 +00:00
Tim Cooijmans e47acb2ca7 bind/java: Do not get ApplicationContext via reflection, ask for it when needed.
Previously any library created using gobind used reflection to get the ApplicationContext. The methods used are disallowed in Android 9 causing any library to crash.  However the ApplictionContext is not required and only needed when using RunOnJvm. This change adds an method to set the ApplicationContext when needed, but will not get it by default by using reflection.

Fixes #31364

Change-Id: I83ce69f3b4b59d2cc4a275928f0439e5e4651ba8
GitHub-Last-Rev: b563af1d7fa8f4b3e62751ce9a78c8e2f291d232
GitHub-Pull-Request: golang/mobile#31
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/175103
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-07-11 16:50:09 +00:00
Junda Liu 6fa95d984e bind: keep package function comments in java file
previously package level function comments are ignored. this change
keeps the comment in generated java files

Change-Id: I86dcd93b1026c4455d2c4782cbc9f30b514b3107
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/181038
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-06-07 21:45:18 +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
Chotepud Teo ab05907dce cmd/gomobile: add arg to set android api level
Fixes golang/go#31905

Change-Id: Icee0ece2e78028fa4afd8b273b86e4eed404d99a
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/176077
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2019-05-09 16:47:12 +00:00
Hana Kim 12c8d8ccab cmd/gomobile: update doc
Ran `gomobile help documentation doc.go`

Change-Id: Ie7f89349520393e63a8d72495d69c299e3218876
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/176157
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-09 15:01:47 +00:00
Daniel Lublin 3e0bab5405 cmd/gomobile: fall back to $ANDROID_NDK_HOME for the NDK path
After trying $ANDROID_HOME/ndk-bundle, we also try $ANDROID_NDK_HOME.

ANDROID_NDK_HOME is advised in this NDK sample code wiki:
https://github.com/googlesamples/android-ndk/wiki
Mentioned in the Bazel buildsystem Android app tutorial:
https://docs.bazel.build/versions/master/tutorial/android-app.html

On Ubuntu, the google-android-ndk-installer leaves the NDK in
/usr/lib/android-ndk, and it seems to be up to the user to set
ANDROID_NDK_HOME.

On Arch Linux, the android-ndk package installs the NDK into /opt/android-ndk
and sets ANDROID_NDK_HOME to there using an /etc/profile.d/file

Fixes golang/go#31461

Change-Id: I9f7f7e24b19e0047419f9725b67bd6daf2b1d328
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/171938
Run-TryBot: Elias Naur <mail@eliasnaur.com>
Reviewed-by: Elias Naur <mail@eliasnaur.com>
2019-04-15 19:13:53 +00:00
Juan Pablo Civile 28c689b77b bind: annotate all remaining ObjC types for nullability
From Xcode 10.2 onwards, these annotations are required in all interface
declarations. The behaviour can be disabled, but since we were already
annotated most types it made sense to just annotate the rest.

Change-Id: Iacd09a2fea4dfb3e22fec97cf4ca22966fc783bf
GitHub-Last-Rev: a431572a83ea8b29f55813bcdafc9a00f8d15972
GitHub-Pull-Request: golang/mobile#29
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/171957
Reviewed-by: Elias Naur <mail@eliasnaur.com>
2019-04-12 20:20:09 +00:00
Elias Naur 167ebed0ec cmd/gomobile: require NDK r19c and delete workaround for NDK r19b
The prebuilt toolchains introduced in NDK r19b didn't work on Windows.
NDK r19c contains a fix, so remove our workaround and check for r19c
on Windows.

Change-Id: I3bcfedbc156f10c3cab8e74dcbd7de68575669e7
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/168067
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-27 16:31:28 +00:00