aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-10-19 09:20:21 -0400
committerGopher Robot <gobot@golang.org>2022-10-25 16:47:27 +0000
commitddaa25b5dd5ec8d66712c12c2a1ef4f12c1b583b (patch)
tree5f77e3e29b83d61200c7361cd8cb812d7d9fb231 /src
parent2d63305b8446c69d79730ff556385cabe09f54ec (diff)
downloadgo-ddaa25b5dd5ec8d66712c12c2a1ef4f12c1b583b.tar.xz
cmd/go: split quotes in GOFLAGS same as in other env vars
GOFLAGS didn't split on quotes because no other env vars (such as CC, CXX, ...) did either. This kept them all consistent. CL 341936 changed everything but GOFLAGS, making them inconsistent. Split GOFLAGS the same way as the other environment variables. Fixes #26849. Change-Id: I99bb450fe30cab949da48af133b6a36ff320532f Reviewed-on: https://go-review.googlesource.com/c/go/+/443956 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/base/goflags.go23
-rw-r--r--src/cmd/go/internal/work/exec.go2
-rw-r--r--src/cmd/go/testdata/script/goflags.txt5
3 files changed, 22 insertions, 8 deletions
diff --git a/src/cmd/go/internal/base/goflags.go b/src/cmd/go/internal/base/goflags.go
index 267006be7a..eced2c5d58 100644
--- a/src/cmd/go/internal/base/goflags.go
+++ b/src/cmd/go/internal/base/goflags.go
@@ -11,6 +11,7 @@ import (
"strings"
"cmd/go/internal/cfg"
+ "cmd/internal/quoted"
)
var goflags []string // cached $GOFLAGS list; can be -x or --x form
@@ -30,19 +31,27 @@ func InitGOFLAGS() {
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.
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index fb1a9bbc14..79d5615f89 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -2822,7 +2822,7 @@ func (b *Builder) gccArchArgs() []string {
// 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)
diff --git a/src/cmd/go/testdata/script/goflags.txt b/src/cmd/go/testdata/script/goflags.txt
index f4872ffd35..112086059c 100644
--- a/src/cmd/go/testdata/script/goflags.txt
+++ b/src/cmd/go/testdata/script/goflags.txt
@@ -55,5 +55,10 @@ go list -tags=magic
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