Skip to content

Commit

Permalink
fix: pass environment to workers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
terinjokes committed Dec 21, 2018
1 parent 8e0f32e commit 3395b90
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 3395b90

Please sign in to comment.