Skip to content

Commit

Permalink
Add repo env test (bazelbuild#15768)
Browse files Browse the repository at this point in the history
Fix and test for null value bug when using --repo_env
[Issue Link](bazelbuild#15430)

Closes bazelbuild#15618.

PiperOrigin-RevId: 457728307
Change-Id: I3d57ae4ac95de09215281bec51329b7baafd53af

Co-authored-by: Googler <noreply@google.com>
  • Loading branch information
ckolli5 and Googler committed Jul 5, 2022
1 parent 62be9ea commit d4663a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ public void exit(AbruptExitException exception) {
value = System.getenv(name);
}
if (value != null) {
repoEnv.put(entry.getKey(), entry.getValue());
repoEnvFromOptions.put(entry.getKey(), entry.getValue());
repoEnv.put(name, value);
repoEnvFromOptions.put(name, value);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/py/bazel/bazel_external_repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,27 @@ def testExternalBazelignoreContainingRepoName(self):
args=['build', '@other_repo//:file'], cwd=work_dir)
self.AssertExitCode(exit_code, 0, stderr)

def testRepoEnv(self):
# Testing fix for issue: https://github.com/bazelbuild/bazel/issues/15430

self.ScratchFile('WORKSPACE', [
'load("//:main.bzl", "dump_env")', 'dump_env(', ' name = "debug"',
')'
])
self.ScratchFile('BUILD')
self.ScratchFile('main.bzl', [
'def _dump_env(ctx):', ' val = ctx.os.environ.get("FOO", "nothing")',
' print("FOO", val)', ' ctx.file("BUILD")',
'dump_env = repository_rule(', ' implementation = _dump_env,',
' local = True,', ')'
])

exit_code, _, stderr = self.RunBazel(
args=['build', '@debug//:all', '--repo_env=FOO'],
env_add={'FOO': 'bar'})
self.AssertExitCode(exit_code, 0, stderr)
self.assertIn('FOO bar', os.linesep.join(stderr))
self.assertNotIn('null value in entry: FOO=null', os.linesep.join(stderr))

if __name__ == '__main__':
unittest.main()

0 comments on commit d4663a1

Please sign in to comment.