diff options
author | 2016-07-12 14:17:05 +0000 | |
---|---|---|
committer | 2016-07-13 11:15:29 +0000 | |
commit | 5b12f6e759c1f3137a7149d3026ff96686d07696 (patch) | |
tree | 80b238e185fc6dc6e4ed2de478f18676cc4d8f8c | |
parent | 68ac6be904ea57dd50fd1d1df946660d55bbf8a2 (diff) |
Fix TMPDIR in test_genrule_default_env
TMPDIR is not just an arbitrary environment variable that we expect to be passed
to tests; it is the place where we temporary files may be stored. This semantic
rule also applies to bazel itself. So TMPDIR has to point to a directory where
we can write to. Unfortunately, the only way we have to find out a directory to
write to is TMPDIR itself. So, create a fresh directory there and pass that
directory on as new value for TMPDIR to see if it is passed through to the
action.
Also, fix up the resetting of TMPDIR: do not assume unset is the same
as set to the empty string.
--
Change-Id: I378ae9196c33d988686e8a2a6d3c142238fe8aab
Reviewed-on: https://bazel-review.googlesource.com/#/c/4030
MOS_MIGRATED_REVID=127196634
-rwxr-xr-x | src/test/shell/bazel/bazel_rules_test.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/test/shell/bazel/bazel_rules_test.sh b/src/test/shell/bazel/bazel_rules_test.sh index 6b7c04ed1d..cd510872fe 100755 --- a/src/test/shell/bazel/bazel_rules_test.sh +++ b/src/test/shell/bazel/bazel_rules_test.sh @@ -229,18 +229,27 @@ genrule( cmd = "(echo \"PATH=$$PATH\"; echo \"TMPDIR=$$TMPDIR\") > $@", ) EOF - local old_path="${PATH-}" + local old_path="${PATH}" local old_tmpdir="${TMPDIR-}" + local effective_tmpdir="${TMPDIR:-/tmp}" + local new_tmpdir=$(mktemp -d "${effective_tmpdir}/newfancytmpdirXXXXXX") + [ -d "${new_tmpdir}" ] || \ + fail "Could not create new temporary directory ${new_tmpdir}" export PATH="/bin:/usr/bin:/random/path" - export TMPDIR="/some/path" + export TMPDIR="${new_tmpdir}" # batch mode to force reload of the environment bazel --batch build //pkg:test || fail "Failed to build //pkg:test" - export PATH="$old_path" - export TMPDIR="$old_tmpdir" assert_contains "PATH=/bin:/usr/bin:/random/path" \ bazel-genfiles/pkg/test.out - assert_contains "TMPDIR=/some/path" \ + assert_contains "TMPDIR=.*newfancytmpdir" \ bazel-genfiles/pkg/test.out + if [ -n "${old_tmpdir}" ] + then + export TMPDIR="${old_tmpdir}" + else + unset TMPDIR + fi + export PATH="${old_path}" } function test_genrule_remote() { |