forked from goplus/gop
/
context.go
65 lines (59 loc) · 1.67 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"go/build"
"log"
"strings"
)
// contexts are the default contexts which are scanned, unless
// overridden by the -contexts flag.
var contexts = []*build.Context{
{GOOS: "linux", GOARCH: "386", CgoEnabled: true},
{GOOS: "linux", GOARCH: "amd64", CgoEnabled: true},
{GOOS: "linux", GOARCH: "arm", CgoEnabled: true},
{GOOS: "darwin", GOARCH: "386", CgoEnabled: true},
{GOOS: "darwin", GOARCH: "amd64", CgoEnabled: true},
{GOOS: "windows", GOARCH: "amd64", CgoEnabled: true},
{GOOS: "windows", GOARCH: "386", CgoEnabled: true},
{GOOS: "freebsd", GOARCH: "386", CgoEnabled: true},
{GOOS: "freebsd", GOARCH: "amd64", CgoEnabled: true},
{GOOS: "freebsd", GOARCH: "arm", CgoEnabled: true},
{GOOS: "netbsd", GOARCH: "386", CgoEnabled: true},
{GOOS: "netbsd", GOARCH: "amd64", CgoEnabled: true},
{GOOS: "netbsd", GOARCH: "arm", CgoEnabled: true},
{GOOS: "openbsd", GOARCH: "386", CgoEnabled: true},
{GOOS: "openbsd", GOARCH: "amd64", CgoEnabled: true},
}
func contextName(c *build.Context) string {
s := c.GOOS + "-" + c.GOARCH
if c.CgoEnabled {
return s + "-cgo"
}
return s
}
func osArchName(c *build.Context) string {
return c.GOOS + "-" + c.GOARCH
}
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 setCustomContexts(customctx string) {
contexts = []*build.Context{}
for _, c := range strings.Split(customctx, ",") {
contexts = append(contexts, parseContext(c))
}
}