diff options
author | Philipp Wollermann <philwo@google.com> | 2016-07-14 15:10:10 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2016-07-14 17:46:04 +0000 |
commit | a03599225c010739e9d2e852400f1fdc94f8ee91 (patch) | |
tree | 6d2bf024e104b58c04ef7412ee42f7eca94959ce /src/main | |
parent | 0e7a4171b13c9332bd278a3a9b70699af551853a (diff) |
StandaloneTestStrategy: Use relative paths for environmental variables related to tests.
This allows for better caching and also makes it easy to run tests in a different directory than the global execroot.
The paths are rewritten to absolute paths in test-setup.sh, because Test Encyclopedia says that we pass absolute paths to tests in these variables.
--
MOS_MIGRATED_REVID=127432675
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java | 19 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java | 7 |
2 files changed, 12 insertions, 14 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(); |