-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
gomobile build
and bind
are not passing along -tags
properly.
What version of Go are you using (go version
)?
go1.7.4
What operating system and processor architecture are you using (go env
)?
darwin/amd64
What did you do?
Modify the "basic" example (example/basic/main.go
) like so:
- // +build darwin linux windows
+ // +build aaa,bbb
This will require the tags aaa
and bbb
to be passed in order for it to build. Confirm that it initially doesn't build like so:
$ gomobile build -v -x golang.org/x/mobile/example/basic
...resulting in something like...
gomobile: no buildable Go source files in GOPATH/src/golang.org/x/mobile/example/basic
As expected.
Now supply the required tags. It still fails, and you can see how the tags are getting mangled.
$ gomobile build -v -x -tags "aaa bbb" golang.org/x/mobile/example/basic
...resulting in something like...
can't load package: package golang.org/x/mobile/example/basic: no buildable Go source files in GOPATH/src/golang.org/x/mobile/example/basic
...
gomobile: go build -pkgdir=GOPATH/pkg/gomobile/pkg_android_arm64 -tags="aaa,bbb" -v -x -buildmode=c-shared -o /var/folders/xh/mp5b069545n32zn6ds3dbn100000gn/T/gomobile-work-217015845/lib/arm64-v8a/libtest.so golang.org/x/mobile/example/basic failed: exit status 1
Note the -tags="aaa,bbb"
.
Here's the fix diff:
diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go
index 3ed4576..e4c4db6 100644
--- a/cmd/gomobile/build.go
+++ b/cmd/gomobile/build.go
@@ -15,7 +15,6 @@ import (
"os/exec"
"regexp"
"runtime"
- "strconv"
"strings"
)
@@ -270,7 +269,7 @@ func goCmd(subcmd string, srcs []string, env []string, args ...string) error {
"go",
subcmd,
"-pkgdir="+pkgdir(env),
- "-tags="+strconv.Quote(strings.Join(ctx.BuildTags, ",")),
+ "-tags",strings.Join(ctx.BuildTags, " "),
)
if buildV {
cmd.Args = append(cmd.Args, "-v")
So, the tags should be passed as a separate argument to exec.Command
, space-separated. The =
, the quoting, and the comma-joining all need to go.
After applying that patch, the code builds as expected.
Impact
We discovered this the hard way and had to hack around it by patching gomobile before building it. This can be seen here. (I'll be filing another bug for the hack below it.)