go/build: explain -tags better in the go/build documentation

Created on 18 Sep 2014  Â·  8Comments  Â·  Source: golang/go

by kyle.[email protected]:

The help text for the "go build" command says:

    -tags 'tag list'
        a list of build tags to consider satisfied during the build.
        For more information about build tags, see the description of
        build constraints in the documentation for the go/build package.

however, nothing in the go/build documentation page
(http://golang.org/pkg/go/build/#hdr-Build_Constraints)  says anything about the
"-tags" option. There is one reference to "ctxt.BuildTags," but no
examples of actually calling "go build" with -tags set.

It would be great if the documentation included an example of using -tags to pass in
custom build constraints. As it is, there are no examples of this powerful feature,
aside from a test shell script that ships with the go source.
Documentation FrozenDueToAge

Most helpful comment

@davecheney No luck. A have two different files: first with "debug" (in lib) tag and second with "lowlevel" (in test).

$ go test -tags debug ./...    # OK
$ go test -tags lowlevel ./...    # OK
$ go test -tags lowlevel,debug ./...
... [no test files]

If I remove // +build lowlevel from test file - tests runs. But with "-tags lowlevel,debug" "debug" tag has no effect.

UPD: This works

$ go test -tags="lowlevel debug" ./...

All 8 comments

Comment 1:

_Labels changed: added repo-main, release-none, documentation._

Are custom build tags intended to be used? I just tried to set up a build program using them but ran into the fact that vet doesn't have a -tags option.

I've been looking for about 20 minutes to find out how to use multiple build tags and still haven't found the answer.

@derekperkins find anything? also looking.

-tag a,b,c

On Fri, 7 Oct 2016, 08:35 Ryan Couto [email protected] wrote:

@derekperkins https://github.com/derekperkins find anything? also
looking.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/8772#issuecomment-252095603, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAcA-MO8B6N8f6vy4hqhe7lKhBooy8Wks5qxWmIgaJpZM4Ej5ol
.

@davecheney No luck. A have two different files: first with "debug" (in lib) tag and second with "lowlevel" (in test).

$ go test -tags debug ./...    # OK
$ go test -tags lowlevel ./...    # OK
$ go test -tags lowlevel,debug ./...
... [no test files]

If I remove // +build lowlevel from test file - tests runs. But with "-tags lowlevel,debug" "debug" tag has no effect.

UPD: This works

$ go test -tags="lowlevel debug" ./...

This bit me too recently. IIRC, one tool wanted commas and another wanted spaces.

Dupe of #17148

Was this page helpful?
0 / 5 - 0 ratings