"strings"
"cmd/go/internal/cfg"
+ "cmd/internal/quoted"
)
var goflags []string // cached $GOFLAGS list; can be -x or --x form
return
}
- goflags = strings.Fields(cfg.Getenv("GOFLAGS"))
- if len(goflags) == 0 {
- // nothing to do; avoid work on later InitGOFLAGS call
- goflags = []string{}
- return
- }
-
// Ignore bad flag in go env and go bug, because
// they are what people reach for when debugging
// a problem, and maybe they're debugging GOFLAGS.
// (Both will show the GOFLAGS setting if let succeed.)
hideErrors := cfg.CmdName == "env" || cfg.CmdName == "bug"
+ var err error
+ goflags, err = quoted.Split(cfg.Getenv("GOFLAGS"))
+ if err != nil {
+ if hideErrors {
+ return
+ }
+ Fatalf("go: parsing $GOFLAGS: %v", err)
+ }
+
+ if len(goflags) == 0 {
+ // nothing to do; avoid work on later InitGOFLAGS call
+ goflags = []string{}
+ return
+ }
+
// Each of the words returned by strings.Fields must be its own flag.
// To set flag arguments use -x=value instead of -x value.
// For boolean flags, -x is fine instead of -x=true.
// into fields, using the default value when the variable is empty.
//
// The environment variable must be quoted correctly for
-// str.SplitQuotedFields. This should be done before building
+// quoted.Split. This should be done before building
// anything, for example, in BuildInit.
func envList(key, def string) []string {
v := cfg.Getenv(key)
go test -tags=magic -c -o $devnull
go vet -tags=magic
+# GOFLAGS uses the same quoting rules (quoted.Split) as the rest of
+# the go command env variables
+env GOFLAGS='"-tags=magic wizardry"'
+go list
+
-- foo_test.go --
package foo