From 3395b909c21325cb9f0b8fffa026405e09b2c233 Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sat, 15 Dec 2018 16:06:40 -0800 Subject: fix: pass environment to workers 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. --- main.go | 27 ++++++++++++++++++++------- 1 file 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 +} -- cgit 1.4.1