mirror of
https://github.com/golang/go
synced 2024-11-17 13:04:54 -07:00
cmd/go: for generate, use build context values for GOOS/GOARCH
Fixes #16120 Change-Id: Ia352558231e00baab5c698e93d7267564c07ec0c Reviewed-on: https://go-review.googlesource.com/24242 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Andrew Gerrand <adg@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e1a6e71e74
commit
109823ec93
@ -14,7 +14,6 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -276,8 +275,8 @@ func isGoGenerate(buf []byte) bool {
|
||||
// single go:generate command.
|
||||
func (g *Generator) setEnv() {
|
||||
g.env = []string{
|
||||
"GOARCH=" + runtime.GOARCH,
|
||||
"GOOS=" + runtime.GOOS,
|
||||
"GOARCH=" + buildContext.GOARCH,
|
||||
"GOOS=" + buildContext.GOOS,
|
||||
"GOFILE=" + g.file,
|
||||
"GOLINE=" + strconv.Itoa(g.lineNum),
|
||||
"GOPACKAGE=" + g.pkg,
|
||||
|
@ -2920,3 +2920,27 @@ func TestAlwaysLinkSysoFiles(t *testing.T) {
|
||||
tg.run("list", "-f", "{{.SysoFiles}}", "syso")
|
||||
tg.grepStdout("a.syso", "missing syso file with CGO_ENABLED=0")
|
||||
}
|
||||
|
||||
// Issue 16120.
|
||||
func TestGenerateUsesBuildContext(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("this test won't run under Windows")
|
||||
}
|
||||
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
tg.parallel()
|
||||
tg.tempDir("src/gen")
|
||||
tg.tempFile("src/gen/gen.go", "package gen\n//go:generate echo $GOOS $GOARCH\n")
|
||||
tg.setenv("GOPATH", tg.path("."))
|
||||
|
||||
tg.setenv("GOOS", "linux")
|
||||
tg.setenv("GOARCH", "amd64")
|
||||
tg.run("generate", "gen")
|
||||
tg.grepStdout("linux amd64", "unexpected GOOS/GOARCH combination")
|
||||
|
||||
tg.setenv("GOOS", "darwin")
|
||||
tg.setenv("GOARCH", "386")
|
||||
tg.run("generate", "gen")
|
||||
tg.grepStdout("darwin 386", "unexpected GOOS/GOARCH combination")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user