]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: quote fragments in CGO_ env variables reported by 'go env'
authorBryan C. Mills <bcmills@google.com>
Fri, 1 Apr 2022 18:54:39 +0000 (14:54 -0400)
committerBryan Mills <bcmills@google.com>
Tue, 5 Apr 2022 14:15:59 +0000 (14:15 +0000)
These fields have been parsed as quoted fields since CL 334732,
but we missed the unparsing side in 'go env'.

Certain scripts (notably make.ba{sh,t}) expect to be able to set the
environment to exactly what 'go env' reports, so for round-trip
purposes it is important to match the marshaling and unmarshaling
functions.

(Noticed while debugging #52009.)
Updates #41400

Change-Id: I0ff39b7a6e1328111c285c97cd23f79b723f3c73
Reviewed-on: https://go-review.googlesource.com/c/go/+/398058
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/internal/envcmd/env.go

index fcabc8d1c71a3fc4f5f5f164f22724846b737840..aab21af8557c49531943e42aba9a696feed803ce 100644 (file)
@@ -184,15 +184,23 @@ func ExtraEnvVarsCostly() []cfg.EnvVar {
        }
        cmd := b.GccCmd(".", "")
 
+       join := func(s []string) string {
+               q, err := quoted.Join(s)
+               if err != nil {
+                       return strings.Join(s, " ")
+               }
+               return q
+       }
+
        return []cfg.EnvVar{
                // Note: Update the switch in runEnv below when adding to this list.
-               {Name: "CGO_CFLAGS", Value: strings.Join(cflags, " ")},
-               {Name: "CGO_CPPFLAGS", Value: strings.Join(cppflags, " ")},
-               {Name: "CGO_CXXFLAGS", Value: strings.Join(cxxflags, " ")},
-               {Name: "CGO_FFLAGS", Value: strings.Join(fflags, " ")},
-               {Name: "CGO_LDFLAGS", Value: strings.Join(ldflags, " ")},
+               {Name: "CGO_CFLAGS", Value: join(cflags)},
+               {Name: "CGO_CPPFLAGS", Value: join(cppflags)},
+               {Name: "CGO_CXXFLAGS", Value: join(cxxflags)},
+               {Name: "CGO_FFLAGS", Value: join(fflags)},
+               {Name: "CGO_LDFLAGS", Value: join(ldflags)},
                {Name: "PKG_CONFIG", Value: b.PkgconfigCmd()},
-               {Name: "GOGCCFLAGS", Value: strings.Join(cmd[3:], " ")},
+               {Name: "GOGCCFLAGS", Value: join(cmd[3:])},
        }
 }