-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is done using a brand new build context that is configured using the regular environment variables. Signed-off-by: Steeve Morin <[email protected]>
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters