diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java index c87d85d969f836..a2e1d150c839e7 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java @@ -248,7 +248,14 @@ public void exit(AbruptExitException exception) { CoreOptions configOpts = options.getOptions(CoreOptions.class); if (configOpts != null) { for (Map.Entry entry : configOpts.repositoryEnvironment) { - repoEnv.put(entry.getKey(), entry.getValue()); + String name = entry.getKey(); + String value = entry.getValue(); + if (value == null) { + value = System.getenv(name); + } + if (value != null) { + repoEnv.put(name, value); + } } } } diff --git a/src/test/shell/bazel/starlark_repository_test.sh b/src/test/shell/bazel/starlark_repository_test.sh index 0fbbeae8f99abb..e5ef96782993e4 100755 --- a/src/test/shell/bazel/starlark_repository_test.sh +++ b/src/test/shell/bazel/starlark_repository_test.sh @@ -889,6 +889,7 @@ EOF cat > .bazelrc </dev/null`/repoenv.txt repoenv4.txt + cp `bazel info bazel-genfiles 3> /dev/null`/unrelated.txt unrelated4.txt + echo; cat repoenv4.txt; echo; cat unrelated4.txt; echo + + grep -q 'FOO=qux' repoenv4.txt \ + || fail "Expected FOO to be visible to repo rules" + diff unrelated1.txt unrelated4.txt \ + || fail "Expected unrelated action to not be rerun" } function test_repo_env_inverse() {