Skip to content

Commit

Permalink
cmd/go: fail with nice error message on bad GOOS/GOARCH pair
Browse files Browse the repository at this point in the history
Fixes #12272

Change-Id: I2115ec62ed4061084c482eb385a583a1c1909888
Reviewed-on: https://go-review.googlesource.com/22838
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
  • Loading branch information
bradfitz committed May 6, 2016
1 parent 30bfafc commit b90cb3f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ misc/cgo/stdio/run.out
misc/cgo/testso/main
src/cmd/cgo/zdefaultcc.go
src/cmd/go/zdefaultcc.go
src/cmd/go/zosarch.go
src/cmd/internal/obj/zbootstrap.go
src/go/build/zcgo.go
src/go/doc/headscan
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ var deptab = []struct {
}{
{"cmd/go", []string{
"zdefaultcc.go",
"zosarch.go",
}},
{"runtime/internal/sys", []string{
"zversion.go",
Expand All @@ -485,6 +486,7 @@ var gentab = []struct {
gen func(string, string)
}{
{"zdefaultcc.go", mkzdefaultcc},
{"zosarch.go", mkzosarch},
{"zversion.go", mkzversion},
{"zcgo.go", mkzcgo},

Expand Down
15 changes: 11 additions & 4 deletions src/cmd/dist/buildgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (
// It is invoked to write cmd/go/zdefaultcc.go
// but we also write cmd/cgo/zdefaultcc.go
func mkzdefaultcc(dir, file string) {
var out string

out = fmt.Sprintf(
out := fmt.Sprintf(
"// auto generated by go tool dist\n"+
"\n"+
"package main\n"+
Expand All @@ -42,7 +40,16 @@ func mkzdefaultcc(dir, file string) {
writefile(out, file, writeSkipSame)
}

// mkzcgo writes zcgo.go for go/build package:
// mkzcgo writes zosarch.go for cmd/go.
func mkzosarch(dir, file string) {
var buf bytes.Buffer
buf.WriteString("// auto generated by go tool dist\n\n")
buf.WriteString("package main\n\n")
fmt.Fprintf(&buf, "var osArchSupportsCgo = %#v", cgoEnabled)
writefile(buf.String(), file, writeSkipSame)
}

// mkzcgo writes zcgo.go for the go/build package:
//
// package build
// var cgoEnabled = map[string]bool{}
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/go/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ var (
func init() {
goarch = buildContext.GOARCH
goos = buildContext.GOOS

if _, ok := osArchSupportsCgo[goos+"/"+goarch]; !ok {
fmt.Fprintf(os.Stderr, "cmd/go: unsupported GOOS/GOARCH pair %s/%s\n", goos, goarch)
os.Exit(2)
}

if goos == "windows" {
exeSuffix = ".exe"
}
Expand Down

0 comments on commit b90cb3f

Please sign in to comment.