Fixes test failure in build, probably a good idea anyway.
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/
131210043
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strconv"
"strings"
"unicode"
Go generate sets several variables when it runs the generator:
+ $GOARCH
+ The execution architecture (arm, amd64, etc.)
+ $GOOS
+ The execution operating system (linux, windows, etc.)
$GOFILE
The base name of the file.
$GOPACKAGE
envVar := word[i+1 : i+w]
var sub string
switch envVar {
+ case "GOARCH":
+ sub = runtime.GOARCH
+ case "GOOS":
+ sub = runtime.GOOS
case "GOFILE":
sub = g.file
case "GOPACKAGE":
cmd.Stderr = os.Stderr
// Run the command in the package directory.
cmd.Dir = g.dir
- cmd.Env = mergeEnvLists([]string{"GOFILE=" + g.file, "GOPACKAGE=" + g.pkg}, os.Environ())
+ env := []string{
+ "GOARCH=" + runtime.GOARCH,
+ "GOOS=" + runtime.GOOS,
+ "GOFILE=" + g.file,
+ "GOPACKAGE=" + g.pkg,
+ }
+ cmd.Env = mergeEnvLists(env, os.Environ())
err := cmd.Run()
if err != nil {
g.errorf("running %q: %s", words[0], err)
{"x", []string{"x"}},
{" a b\tc ", []string{"a", "b", "c"}},
{` " a " `, []string{" a "}},
+ {"$GOARCH", []string{runtime.GOARCH}},
+ {"$GOOS", []string{runtime.GOOS}},
{"$GOFILE", []string{"proc.go"}},
+ {"$GOPACKAGE", []string{"sys"}},
{"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
{"/$XXNOTDEFINED/", []string{"//"}},
{"$GOARCH", []string{runtime.GOARCH}},