/
build_context.go
38 lines (34 loc) · 951 Bytes
/
build_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
package main
import (
"go/build"
"os"
"path/filepath"
"strings"
)
var buildContext = makeBuildContext()
func makeBuildContext() *build.Context {
bctx := &build.Context{
GOOS: getenvDefault("GOOS", build.Default.GOOS),
GOARCH: getenvDefault("GOARCH", build.Default.GOARCH),
GOROOT: getenvDefault("GOROOT", build.Default.GOROOT),
GOPATH: getenvDefault("GOPATH", build.Default.GOPATH),
BuildTags: strings.Split(getenvDefault("GOTAGS", ""), ","),
ReleaseTags: build.Default.ReleaseTags[:],
}
if v, ok := os.LookupEnv("CGO_ENABLED"); ok {
bctx.CgoEnabled = v == "1"
} else {
bctx.CgoEnabled = build.Default.CgoEnabled
}
return bctx
}
func filterSourceFilesForTags(files []string) []string {
ret := make([]string, 0, len(files))
for _, f := range files {
dir, filename := filepath.Split(f)
if match, _ := buildContext.MatchFile(dir, filename); match {
ret = append(ret, f)
}
}
return ret
}