diff options
author | Russ Cox <rsc@golang.org> | 2019-04-23 12:19:57 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2019-04-24 14:25:19 +0000 |
commit | 80e7832733fd245181af3394077f2df21303a4aa (patch) | |
tree | 6760ca0cf9725f285fa9ff98077b3639d39c3b9b /src/cmd/go/internal/work/build.go | |
parent | 74695644e0c38586a85b9b483830c546efbb6642 (diff) | |
download | go-80e7832733fd245181af3394077f2df21303a4aa.tar.gz go-80e7832733fd245181af3394077f2df21303a4aa.zip |
cmd/go: change -tags to a comma-separated list
Using commas makes it possible to put multiple tags into GOFLAGS.
The space-separated form is still recognized and will be maintained.
Alleviates #26849 somewhat.
Fixes #18800 (again).
Change-Id: I6f4cf28ea31e53e21ccbdad6ef1a0aee63b007d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/173438
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Diffstat (limited to 'src/cmd/go/internal/work/build.go')
-rw-r--r-- | src/cmd/go/internal/work/build.go | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 355c1477f5..9c03f0818d 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -104,10 +104,12 @@ and test commands: install and load all packages from dir instead of the usual locations. For example, when building with a non-standard configuration, use -pkgdir to keep generated packages in a separate location. - -tags 'tag list' - a space-separated list of build tags to consider satisfied during the + -tags tag,list + a comma-separated 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. + (Earlier versions of Go used a space-separated list, and that form + is deprecated but still recognized.) -trimpath remove all file system paths from the resulting executable. Instead of absolute file system paths, the recorded file names @@ -233,7 +235,7 @@ func AddBuildFlags(cmd *base.Command) { cmd.Flag.StringVar(&cfg.BuildPkgdir, "pkgdir", "", "") cmd.Flag.BoolVar(&cfg.BuildRace, "race", false, "") cmd.Flag.BoolVar(&cfg.BuildMSan, "msan", false, "") - cmd.Flag.Var((*base.StringsFlag)(&cfg.BuildContext.BuildTags), "tags", "") + cmd.Flag.Var((*tagsFlag)(&cfg.BuildContext.BuildTags), "tags", "") cmd.Flag.Var((*base.StringsFlag)(&cfg.BuildToolexec), "toolexec", "") cmd.Flag.BoolVar(&cfg.BuildTrimpath, "trimpath", false, "") cmd.Flag.BoolVar(&cfg.BuildWork, "work", false, "") @@ -242,6 +244,29 @@ func AddBuildFlags(cmd *base.Command) { cmd.Flag.StringVar(&cfg.DebugActiongraph, "debug-actiongraph", "", "") } +// tagsFlag is the implementation of the -tags flag. +type tagsFlag []string + +func (v *tagsFlag) Set(s string) error { + // For compatibility with Go 1.12 and earlier, allow "-tags='a b c'" or even just "-tags='a'". + if strings.Contains(s, " ") || strings.Contains(s, "'") { + return (*base.StringsFlag)(v).Set(s) + } + + // Split on commas, ignore empty strings. + *v = []string{} + for _, s := range strings.Split(s, ",") { + if s != "" { + *v = append(*v, s) + } + } + return nil +} + +func (v *tagsFlag) String() string { + return "<TagsFlag>" +} + // fileExtSplit expects a filename and returns the name // and ext (without the dot). If the file has no // extension, ext will be empty. |