Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: Build tags not being passed along properly #18515

Closed
adam-p opened this issue Jan 4, 2017 · 1 comment

Comments

Projects
None yet
4 participants
@adam-p
Copy link

commented Jan 4, 2017

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.)

@gopherbot

This comment has been minimized.

Copy link

commented Jan 8, 2017

CL https://golang.org/cl/34955 mentions this issue.

@golang golang locked and limited conversation to collaborators Jan 12, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.