Skip to content

Commit 008aa93

Browse files
hajimehoshiRoman Odermatt
authored and
Roman Odermatt
committed
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 <[email protected]>
1 parent 7d43d04 commit 008aa93

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

cmd/gomobile/bind.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,14 @@ func getModuleVersions(targetOS string, targetArch string, src string) (*modfile
263263
return nil, err
264264
}
265265
if mod != nil {
266-
switch {
267-
case mod.Replace != nil:
266+
if mod.Replace != nil {
268267
p, v := mod.Replace.Path, mod.Replace.Version
269268
if modfile.IsDirectoryPath(p) {
270269
// replaced by a local directory
271270
p = mod.Replace.Dir
272271
}
273272
f.AddReplace(mod.Path, mod.Version, p, v)
274-
case mod.Main, mod.Path == "golang.org/x/mobile":
275-
// We are binding this module or it has
276-
// explicit dependency on golang.org/x/mobile.
273+
} else {
277274
// When the version part is empty, the module is local and mod.Dir represents the location.
278275
if v := mod.Version; v == "" {
279276
f.AddReplace(mod.Path, mod.Version, mod.Dir, "")

0 commit comments

Comments
 (0)