aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java7
-rwxr-xr-xsrc/test/shell/bazel/bazel_test_test.sh10
-rwxr-xr-xtools/test/test-setup.sh13
4 files changed, 28 insertions, 21 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java
index 7df123a52b..a6562d5065 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java
@@ -42,7 +42,6 @@ import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
import com.google.devtools.build.lib.view.test.TestStatus.TestCase;
import com.google.devtools.build.lib.view.test.TestStatus.TestResultData;
import com.google.devtools.common.options.OptionsClassProvider;
-
import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
@@ -90,7 +89,8 @@ public class StandaloneTestStrategy extends TestStrategy {
Path execRoot = actionExecutionContext.getExecutor().getExecRoot();
TestRunnerAction.ResolvedPaths resolvedPaths = action.resolve(execRoot);
- Map<String, String> env = getEnv(action, runfilesDir, testTmpDir, resolvedPaths);
+ Map<String, String> env =
+ getEnv(action, execRoot, runfilesDir, testTmpDir, resolvedPaths.getXmlOutputPath());
Map<String, String> info = new HashMap<>();
@@ -149,24 +149,17 @@ public class StandaloneTestStrategy extends TestStrategy {
}
private Map<String, String> getEnv(
- TestRunnerAction action,
- Path runfilesDir,
- Path tmpDir,
- TestRunnerAction.ResolvedPaths resolvedPaths) {
+ TestRunnerAction action, Path execRoot, Path runfilesDir, Path tmpDir, Path xmlOutputPath) {
Map<String, String> vars = getDefaultTestEnvironment(action);
BuildConfiguration config = action.getConfiguration();
vars.putAll(config.getLocalShellEnvironment());
vars.putAll(action.getTestEnv());
- /*
- * TODO(bazel-team): the paths below are absolute,
- * making test actions impossible to cache remotely.
- */
- vars.put("TEST_SRCDIR", runfilesDir.getPathString());
- vars.put("TEST_TMPDIR", tmpDir.getPathString());
+ vars.put("TEST_SRCDIR", runfilesDir.relativeTo(execRoot).getPathString());
+ vars.put("TEST_TMPDIR", tmpDir.relativeTo(execRoot).getPathString());
vars.put("TEST_WORKSPACE", action.getRunfilesPrefix());
- vars.put("XML_OUTPUT_FILE", resolvedPaths.getXmlOutputPath().getPathString());
+ vars.put("XML_OUTPUT_FILE", xmlOutputPath.relativeTo(execRoot).getPathString());
if (!action.isEnableRunfiles()) {
vars.put("RUNFILES_MANIFEST_ONLY", "1");
}
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
index cc9acf66d9..dadd5691dc 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
@@ -224,7 +224,12 @@ public class LinuxSandboxedStrategy implements SpawnActionContext {
ImmutableSet.Builder<Path> dirs = ImmutableSet.builder();
FileSystem fs = blazeDirs.getFileSystem();
if (env.containsKey("TEST_TMPDIR")) {
- dirs.add(fs.getPath(env.get("TEST_TMPDIR")));
+ PathFragment testTmpDir = new PathFragment(env.get("TEST_TMPDIR"));
+ if (testTmpDir.isAbsolute()) {
+ dirs.add(fs.getPath(testTmpDir));
+ } else {
+ dirs.add(execRoot.getRelative(testTmpDir));
+ }
}
dirs.add(fs.getPath("/tmp"));
return dirs.build();
diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh
index 8ea800161d..98a80cbbdc 100755
--- a/src/test/shell/bazel/bazel_test_test.sh
+++ b/src/test/shell/bazel/bazel_test_test.sh
@@ -93,7 +93,7 @@ function test_tmpdir() {
mkdir -p foo
cat > foo/bar_test.sh <<EOF
#!/bin/bash
-echo "I'm a test"
+echo TEST_TMPDIR=$TEST_TMPDIR
EOF
chmod +x foo/bar_test.sh
cat > foo/BUILD <<EOF
@@ -102,15 +102,11 @@ sh_test(
srcs = ["bar_test.sh"],
)
EOF
- bazel test --test_output=all -s //foo:bar_test >& $TEST_log || \
+ bazel test --test_output=all //foo:bar_test >& $TEST_log || \
fail "Running sh_test failed"
expect_log "TEST_TMPDIR=/.*"
- cat > foo/bar_test.sh <<EOF
-#!/bin/bash
-echo "I'm a different test"
-EOF
- bazel test --test_output=all --test_tmpdir=$TEST_TMPDIR -s //foo:bar_test \
+ bazel test --test_output=all --test_tmpdir=$TEST_TMPDIR //foo:bar_test \
>& $TEST_log || fail "Running sh_test failed"
expect_log "TEST_TMPDIR=$TEST_TMPDIR"
}
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh
index 8ea4fc57b6..6714c792d5 100755
--- a/tools/test/test-setup.sh
+++ b/tools/test/test-setup.sh
@@ -20,6 +20,19 @@ exec 2>&1
# Executing the test log will page it.
echo 'exec ${PAGER:-/usr/bin/less} "$0" || exit 1'
+# Bazel sets some environment vars to relative paths, but it's easier to deal
+# with absolute paths once we're actually running the test, so let's convert
+# them.
+if [[ "$TEST_SRCDIR" != /* ]]; then
+ export TEST_SRCDIR="$PWD/$TEST_SRCDIR"
+fi
+if [[ "$TEST_TMPDIR" != /* ]]; then
+ export TEST_TMPDIR="$PWD/$TEST_TMPDIR"
+fi
+if [[ "$XML_OUTPUT_FILE" != /* ]]; then
+ export XML_OUTPUT_FILE="$PWD/$XML_OUTPUT_FILE"
+fi
+
# Tell googletest about Bazel sharding.
if [[ -n "${TEST_TOTAL_SHARDS+x}" ]] && ((TEST_TOTAL_SHARDS != 0)); then
export GTEST_SHARD_INDEX="${TEST_SHARD_INDEX}"