mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: add GOOS and GOARCH to generate
Fixes test failure in build, probably a good idea anyway. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/131210043
This commit is contained in:
parent
ba8ddc25ca
commit
c6f7c176a3
2 changed files with 19 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
@ -48,6 +49,10 @@ quoted string appears a single argument to the generator.
|
||||||
|
|
||||||
Go generate sets several variables when it runs the generator:
|
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
|
$GOFILE
|
||||||
The base name of the file.
|
The base name of the file.
|
||||||
$GOPACKAGE
|
$GOPACKAGE
|
||||||
|
|
@ -287,6 +292,10 @@ func (g *Generator) expandEnv(word string) string {
|
||||||
envVar := word[i+1 : i+w]
|
envVar := word[i+1 : i+w]
|
||||||
var sub string
|
var sub string
|
||||||
switch envVar {
|
switch envVar {
|
||||||
|
case "GOARCH":
|
||||||
|
sub = runtime.GOARCH
|
||||||
|
case "GOOS":
|
||||||
|
sub = runtime.GOOS
|
||||||
case "GOFILE":
|
case "GOFILE":
|
||||||
sub = g.file
|
sub = g.file
|
||||||
case "GOPACKAGE":
|
case "GOPACKAGE":
|
||||||
|
|
@ -332,7 +341,13 @@ func (g *Generator) exec(words []string) {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
// Run the command in the package directory.
|
// Run the command in the package directory.
|
||||||
cmd.Dir = g.dir
|
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()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.errorf("running %q: %s", words[0], err)
|
g.errorf("running %q: %s", words[0], err)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ var splitTests = []splitTest{
|
||||||
{"x", []string{"x"}},
|
{"x", []string{"x"}},
|
||||||
{" a b\tc ", []string{"a", "b", "c"}},
|
{" a b\tc ", []string{"a", "b", "c"}},
|
||||||
{` " a " `, []string{" a "}},
|
{` " a " `, []string{" a "}},
|
||||||
|
{"$GOARCH", []string{runtime.GOARCH}},
|
||||||
|
{"$GOOS", []string{runtime.GOOS}},
|
||||||
{"$GOFILE", []string{"proc.go"}},
|
{"$GOFILE", []string{"proc.go"}},
|
||||||
|
{"$GOPACKAGE", []string{"sys"}},
|
||||||
{"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
|
{"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
|
||||||
{"/$XXNOTDEFINED/", []string{"//"}},
|
{"/$XXNOTDEFINED/", []string{"//"}},
|
||||||
{"$GOARCH", []string{runtime.GOARCH}},
|
{"$GOARCH", []string{runtime.GOARCH}},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue