diff options
author | Terin Stock <terinjokes@gmail.com> | 2018-12-15 16:06:40 -0800 |
---|---|---|
committer | Terin Stock <terinjokes@gmail.com> | 2018-12-21 14:11:30 -0800 |
commit | 3395b909c21325cb9f0b8fffa026405e09b2c233 (patch) | |
tree | 4f67e6bb7ea507ac3a73c3d3e314f5e0d07e2a6c | |
parent | 8e0f32eb5421d71846700ffe4f11d2958a33f1b1 (diff) |
fix: pass environment to workers v0.2.0
Passes the environment through to workers, allowing more control by the user of Bakelite. In particular, this allows the GOCACHE and GO111MODULE environment variables to be configured. The CGO_ENABLED, GOOS, and GOARCH environment variables are still controlled by Bakelite, as before.
-rw-r--r-- | main.go | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/main.go b/main.go index 8096ae5..8ce0254 100644 --- a/main.go +++ b/main.go @@ -124,6 +124,8 @@ See also: go build, go install, go clean. platforms := plBuilder.Build() + environ := parseEnvironment(os.Environ()) + var ( parallelJobs = runtime.NumCPU() sem = semaphore.NewWeighted(int64(parallelJobs)) @@ -143,7 +145,7 @@ See also: go build, go install, go clean. go func(platform Platform, pkg string) { defer sem.Release(1) - err := build(ctx, platform, pkg) + err := build(ctx, environ, platform, pkg) if err != nil { errored = true @@ -162,20 +164,21 @@ See also: go build, go install, go clean. } } -func build(ctx context.Context, platform Platform, pkg string) error { +func build(ctx context.Context, environ kvs, platform Platform, pkg string) error { name := fmt.Sprintf("%s-%s-%s", filepath.Base(pkg), platform.OS, platform.Arch) if platform.OS == OS_WINDOWS { name += ".exe" } - env := kvs{ - "GOOS": string(platform.OS), - "GOARCH": string(platform.Arch), - "GOROOT": os.Getenv("GOROOT"), - "GOPATH": os.Getenv("GOPATH"), + env := kvs{} + for key, val := range environ { + env[key] = val } + env["GOOS"] = string(platform.OS) + env["GOARCH"] = string(platform.Arch) + if cgo { env["CGO_ENABLED"] = "1" } else { @@ -244,3 +247,13 @@ func parsePlatforms(plBuilder *PlatformBuilder, fields []string) *PlatformBuilde return plBuilder } + +func parseEnvironment(environ []string) kvs { + env := kvs{} + for _, s := range environ { + split := strings.SplitN(s, "=", 2) + env[split[0]] = split[1] + } + + return env +} |