Skip to content

Commit 7ef8fb1

Browse files
authored
Allow environment variables to override go_env in @rules_go//go (#4464)
**What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** This PR fixes an inconsistency in how environment variables interact with `go_env`. Prior to this PR, environment variables could override settings in `go_env` within `go_repository`, but could not override `go_env` when invoking `@rules_go//go`. **Which issues(s) does this PR fix?** Fixes #4462 **Other notes for review**
1 parent 74e87e6 commit 7ef8fb1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

go/tools/go_bin_runner/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ func parseConfig() (Config, error) {
128128
}
129129

130130
func getGoEnv(goBin string, cfg Config) ([]string, error) {
131-
env := os.Environ()
131+
var env []string
132132
for k, v := range cfg.GoEnv {
133133
env = append(env, k+"="+v)
134134
}
135+
env = append(env, os.Environ()...)
135136

136137
// The go binary lies at $GOROOT/bin/go.
137138
goRoot, err := filepath.Abs(filepath.Dir(filepath.Dir(goBin)))

tests/bcr/go_tool_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ runfiles_export_envvars
1818
export BUILD_WORKING_DIRECTORY=$(pwd)
1919
[[ "$("$GO_TOOL" version)" =~ ^go ]]
2020
[[ "$("$GO_TOOL" env GOPRIVATE)" == example.com ]]
21+
# Test that explicit env vars override `go_env` settings.
22+
[[ "$(GOPRIVATE=foo.com "$GO_TOOL" env GOPRIVATE)" == foo.com ]]

0 commit comments

Comments
 (0)