Commit 733cae6a authored by Shenghou Ma's avatar Shenghou Ma Committed by Minux Ma

cmd/dist, go/build: make cmd/dist generate cgoEnabled map for go/build

This reduces the amount of duplication. Now there is only one list
of platforms supporting cgo.

Update #12270.

Change-Id: I5dcd55cb6be7c5bb6ce560383c71d90ab1189dc9
Reviewed-on: https://go-review.googlesource.com/14278
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 1e4e0961
...@@ -463,6 +463,9 @@ var deptab = []struct { ...@@ -463,6 +463,9 @@ var deptab = []struct {
{"runtime/internal/sys", []string{ {"runtime/internal/sys", []string{
"zversion.go", "zversion.go",
}}, }},
{"go/build", []string{
"zcgo.go",
}},
} }
// depsuffix records the allowed suffixes for source files. // depsuffix records the allowed suffixes for source files.
...@@ -478,6 +481,7 @@ var gentab = []struct { ...@@ -478,6 +481,7 @@ var gentab = []struct {
}{ }{
{"zdefaultcc.go", mkzdefaultcc}, {"zdefaultcc.go", mkzdefaultcc},
{"zversion.go", mkzversion}, {"zversion.go", mkzversion},
{"zcgo.go", mkzcgo},
// not generated anymore, but delete the file if we see it // not generated anymore, but delete the file if we see it
{"enam.c", nil}, {"enam.c", nil},
...@@ -1061,9 +1065,9 @@ func cmdbootstrap() { ...@@ -1061,9 +1065,9 @@ func cmdbootstrap() {
} }
} }
// Copied from go/build/build.go.
// Cannot use go/build directly because cmd/dist for a new release // Cannot use go/build directly because cmd/dist for a new release
// builds against an old release's go/build, which may be out of sync. // builds against an old release's go/build, which may be out of sync.
// To reduce duplication, we generate the list for go/build from this.
var cgoEnabled = map[string]bool{ var cgoEnabled = map[string]bool{
"darwin/386": true, "darwin/386": true,
"darwin/amd64": true, "darwin/amd64": true,
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
package main package main
import "fmt" import (
"bytes"
"fmt"
)
/* /*
* Helpers for building cmd/go and cmd/cgo. * Helpers for building cmd/go and cmd/cgo.
...@@ -37,3 +40,26 @@ func mkzdefaultcc(dir, file string) { ...@@ -37,3 +40,26 @@ func mkzdefaultcc(dir, file string) {
file = file[:i] + "c" + file[i:] file = file[:i] + "c" + file[i:]
writefile(out, file, writeSkipSame) writefile(out, file, writeSkipSame)
} }
// mkzcgo writes zcgo.go for go/build package:
//
// package build
// var cgoEnabled = map[string]bool{}
//
// It is invoked to write go/build/zcgo.go.
func mkzcgo(dir, file string) {
var buf bytes.Buffer
fmt.Fprintf(&buf,
"// auto generated by go tool dist\n"+
"\n"+
"package build\n"+
"\n"+
"var cgoEnabled = map[string]bool{\n")
for plat := range cgoEnabled {
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
}
fmt.Fprintf(&buf, "}")
writefile(buf.String(), file, writeSkipSame)
}
...@@ -256,34 +256,6 @@ func (ctxt *Context) SrcDirs() []string { ...@@ -256,34 +256,6 @@ func (ctxt *Context) SrcDirs() []string {
// if set, or else the compiled code's GOARCH, GOOS, and GOROOT. // if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
var Default Context = defaultContext() var Default Context = defaultContext()
// Also known to cmd/dist/build.go.
var cgoEnabled = map[string]bool{
"darwin/386": true,
"darwin/amd64": true,
"darwin/arm": true,
"darwin/arm64": true,
"dragonfly/amd64": true,
"freebsd/386": true,
"freebsd/amd64": true,
"freebsd/arm": true,
"linux/386": true,
"linux/amd64": true,
"linux/arm": true,
"linux/arm64": true,
"linux/ppc64le": true,
"android/386": true,
"android/amd64": true,
"android/arm": true,
"netbsd/386": true,
"netbsd/amd64": true,
"netbsd/arm": true,
"openbsd/386": true,
"openbsd/amd64": true,
"solaris/amd64": true,
"windows/386": true,
"windows/amd64": true,
}
func defaultContext() Context { func defaultContext() Context {
var c Context var c Context
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment