@@ -104,10 +104,12 @@ and test commands:
104
104
install and load all packages from dir instead of the usual locations.
105
105
For example, when building with a non-standard configuration,
106
106
use -pkgdir to keep generated packages in a separate location.
107
- -tags ' tag list'
108
- a space -separated list of build tags to consider satisfied during the
107
+ -tags tag, list
108
+ a comma -separated list of build tags to consider satisfied during the
109
109
build. For more information about build tags, see the description of
110
110
build constraints in the documentation for the go/build package.
111
+ (Earlier versions of Go used a space-separated list, and that form
112
+ is deprecated but still recognized.)
111
113
-trimpath
112
114
remove all file system paths from the resulting executable.
113
115
Instead of absolute file system paths, the recorded file names
@@ -233,7 +235,7 @@ func AddBuildFlags(cmd *base.Command) {
233
235
cmd .Flag .StringVar (& cfg .BuildPkgdir , "pkgdir" , "" , "" )
234
236
cmd .Flag .BoolVar (& cfg .BuildRace , "race" , false , "" )
235
237
cmd .Flag .BoolVar (& cfg .BuildMSan , "msan" , false , "" )
236
- cmd .Flag .Var ((* base . StringsFlag )(& cfg .BuildContext .BuildTags ), "tags" , "" )
238
+ cmd .Flag .Var ((* tagsFlag )(& cfg .BuildContext .BuildTags ), "tags" , "" )
237
239
cmd .Flag .Var ((* base .StringsFlag )(& cfg .BuildToolexec ), "toolexec" , "" )
238
240
cmd .Flag .BoolVar (& cfg .BuildTrimpath , "trimpath" , false , "" )
239
241
cmd .Flag .BoolVar (& cfg .BuildWork , "work" , false , "" )
@@ -242,6 +244,29 @@ func AddBuildFlags(cmd *base.Command) {
242
244
cmd .Flag .StringVar (& cfg .DebugActiongraph , "debug-actiongraph" , "" , "" )
243
245
}
244
246
247
+ // tagsFlag is the implementation of the -tags flag.
248
+ type tagsFlag []string
249
+
250
+ func (v * tagsFlag ) Set (s string ) error {
251
+ // For compatibility with Go 1.12 and earlier, allow "-tags='a b c'" or even just "-tags='a'".
252
+ if strings .Contains (s , " " ) || strings .Contains (s , "'" ) {
253
+ return (* base .StringsFlag )(v ).Set (s )
254
+ }
255
+
256
+ // Split on commas, ignore empty strings.
257
+ * v = []string {}
258
+ for _ , s := range strings .Split (s , "," ) {
259
+ if s != "" {
260
+ * v = append (* v , s )
261
+ }
262
+ }
263
+ return nil
264
+ }
265
+
266
+ func (v * tagsFlag ) String () string {
267
+ return "<TagsFlag>"
268
+ }
269
+
245
270
// fileExtSplit expects a filename and returns the name
246
271
// and ext (without the dot). If the file has no
247
272
// extension, ext will be empty.
0 commit comments