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>
1 file changed
tree: bbf94a361e9755eac1a0762965e3e187c53700c7
  1. app/
  2. asset/
  3. bind/
  4. cmd/
  5. doc/
  6. event/
  7. example/
  8. exp/
  9. geom/
  10. gl/
  11. internal/
  12. testdata/
  13. .gitattributes
  14. .gitignore
  15. AUTHORS
  16. codereview.cfg
  17. CONTRIBUTING.md
  18. CONTRIBUTORS
  19. go.mod
  20. go.sum
  21. LICENSE
  22. PATENTS
  23. README.md
README.md

Go support for Mobile devices

The Go mobile repository holds packages and build tools for using Go on mobile platforms.

Package documentation as a starting point:

Caution image

The Go Mobile project is experimental. Use this at your own risk. While we are working hard to improve it, neither Google nor the Go team can provide end-user support.

This is early work and installing the build system requires Go 1.5. Follow the instructions on golang.org/wiki/Mobile to install the gomobile command, build the basic and the bind example apps.


Contributions to Go are appreciated. See https://golang.org/doc/contribute.html.