mirror of
https://github.com/golang/go
synced 2024-11-15 10:30:54 -07:00
[release-branch.go1] cmd/api: add flag to specify contexts
««« backport 287685288ce1 cmd/api: add flag to specify contexts I needed this to explore per-GOOS/GOARCH differences in pkg syscall for a recent CL. Others may find it useful too. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6236046 »»»
This commit is contained in:
parent
3c10f29757
commit
88c11420a3
@ -41,8 +41,11 @@ var (
|
|||||||
allowNew = flag.Bool("allow_new", true, "allow API additions")
|
allowNew = flag.Bool("allow_new", true, "allow API additions")
|
||||||
nextFile = flag.String("next", "", "optional filename of tentative upcoming API features for the next release. This file can be lazily maintained. It only affects the delta warnings from the -c file printed on success.")
|
nextFile = flag.String("next", "", "optional filename of tentative upcoming API features for the next release. This file can be lazily maintained. It only affects the delta warnings from the -c file printed on success.")
|
||||||
verbose = flag.Bool("v", false, "verbose debugging")
|
verbose = flag.Bool("v", false, "verbose debugging")
|
||||||
|
forceCtx = flag.String("contexts", "", "optional comma-separated list of <goos>-<goarch>[-cgo] to override default contexts.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// contexts are the default contexts which are scanned, unless
|
||||||
|
// overridden by the -contexts flag.
|
||||||
var contexts = []*build.Context{
|
var contexts = []*build.Context{
|
||||||
{GOOS: "linux", GOARCH: "386", CgoEnabled: true},
|
{GOOS: "linux", GOARCH: "386", CgoEnabled: true},
|
||||||
{GOOS: "linux", GOARCH: "386"},
|
{GOOS: "linux", GOARCH: "386"},
|
||||||
@ -56,12 +59,6 @@ var contexts = []*build.Context{
|
|||||||
{GOOS: "windows", GOARCH: "386"},
|
{GOOS: "windows", GOARCH: "386"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
for _, c := range contexts {
|
|
||||||
c.Compiler = build.Default.Compiler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func contextName(c *build.Context) string {
|
func contextName(c *build.Context) string {
|
||||||
s := c.GOOS + "-" + c.GOARCH
|
s := c.GOOS + "-" + c.GOARCH
|
||||||
if c.CgoEnabled {
|
if c.CgoEnabled {
|
||||||
@ -70,9 +67,42 @@ func contextName(c *build.Context) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseContext(c string) *build.Context {
|
||||||
|
parts := strings.Split(c, "-")
|
||||||
|
if len(parts) < 2 {
|
||||||
|
log.Fatalf("bad context: %q", c)
|
||||||
|
}
|
||||||
|
bc := &build.Context{
|
||||||
|
GOOS: parts[0],
|
||||||
|
GOARCH: parts[1],
|
||||||
|
}
|
||||||
|
if len(parts) == 3 {
|
||||||
|
if parts[2] == "cgo" {
|
||||||
|
bc.CgoEnabled = true
|
||||||
|
} else {
|
||||||
|
log.Fatalf("bad context: %q", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
func setContexts() {
|
||||||
|
contexts = []*build.Context{}
|
||||||
|
for _, c := range strings.Split(*forceCtx, ",") {
|
||||||
|
contexts = append(contexts, parseContext(c))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *forceCtx != "" {
|
||||||
|
setContexts()
|
||||||
|
}
|
||||||
|
for _, c := range contexts {
|
||||||
|
c.Compiler = build.Default.Compiler
|
||||||
|
}
|
||||||
|
|
||||||
var pkgs []string
|
var pkgs []string
|
||||||
if flag.NArg() > 0 {
|
if flag.NArg() > 0 {
|
||||||
pkgs = flag.Args()
|
pkgs = flag.Args()
|
||||||
|
Loading…
Reference in New Issue
Block a user