Skip to content

Commit 62bceae

Browse files
author
Bryan C. Mills
committed
cmd/go: quote fragments in CGO_ env variables reported by 'go env'
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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a5f801f commit 62bceae

File tree

1 file changed

+14
-6
lines changed
  • src/cmd/go/internal/envcmd

1 file changed

+14
-6
lines changed

src/cmd/go/internal/envcmd/env.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,23 @@ func ExtraEnvVarsCostly() []cfg.EnvVar {
184184
}
185185
cmd := b.GccCmd(".", "")
186186

187+
join := func(s []string) string {
188+
q, err := quoted.Join(s)
189+
if err != nil {
190+
return strings.Join(s, " ")
191+
}
192+
return q
193+
}
194+
187195
return []cfg.EnvVar{
188196
// Note: Update the switch in runEnv below when adding to this list.
189-
{Name: "CGO_CFLAGS", Value: strings.Join(cflags, " ")},
190-
{Name: "CGO_CPPFLAGS", Value: strings.Join(cppflags, " ")},
191-
{Name: "CGO_CXXFLAGS", Value: strings.Join(cxxflags, " ")},
192-
{Name: "CGO_FFLAGS", Value: strings.Join(fflags, " ")},
193-
{Name: "CGO_LDFLAGS", Value: strings.Join(ldflags, " ")},
197+
{Name: "CGO_CFLAGS", Value: join(cflags)},
198+
{Name: "CGO_CPPFLAGS", Value: join(cppflags)},
199+
{Name: "CGO_CXXFLAGS", Value: join(cxxflags)},
200+
{Name: "CGO_FFLAGS", Value: join(fflags)},
201+
{Name: "CGO_LDFLAGS", Value: join(ldflags)},
194202
{Name: "PKG_CONFIG", Value: b.PkgconfigCmd()},
195-
{Name: "GOGCCFLAGS", Value: strings.Join(cmd[3:], " ")},
203+
{Name: "GOGCCFLAGS", Value: join(cmd[3:])},
196204
}
197205
}
198206

0 commit comments

Comments
 (0)