use of com.google.devtools.build.lib.rules.test.TestTargetExecutionSettings in project bazel by bazelbuild.
the class TestStrategy method getArgs.
/**
* Generates a command line to run for the test action, taking into account coverage and {@code
* --run_under} settings.
*
* @param coverageScript a script interjected between setup script and rest of command line to
* collect coverage data. If this is an empty string, it is ignored.
* @param testAction The test action.
* @return the command line as string list.
* @throws ExecException
*/
protected ImmutableList<String> getArgs(String coverageScript, TestRunnerAction testAction) throws ExecException {
List<String> args = Lists.newArrayList();
// testAction.getConfiguration().getTargetOS() == OS.WINDOWS
if (OS.getCurrent() == OS.WINDOWS) {
args.add(testAction.getShExecutable().getPathString());
args.add("-c");
args.add("$0 $*");
}
Artifact testSetup = testAction.getRuntimeArtifact(TEST_SETUP_BASENAME);
args.add(testSetup.getExecPath().getCallablePathString());
if (testAction.isCoverageMode()) {
args.add(coverageScript);
}
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
// Insert the command prefix specified by the "--run_under=<command-prefix>" option, if any.
if (execSettings.getRunUnder() != null) {
addRunUnderArgs(testAction, args);
}
// Execute the test using the alias in the runfiles tree, as mandated by the Test Encyclopedia.
args.add(execSettings.getExecutable().getRootRelativePath().getCallablePathString());
args.addAll(execSettings.getArgs());
return ImmutableList.copyOf(args);
}
use of com.google.devtools.build.lib.rules.test.TestTargetExecutionSettings in project bazel by bazelbuild.
the class TestStrategy method getLocalRunfilesDirectory.
/**
* Returns the runfiles directory associated with the test executable, creating/updating it if
* necessary and --build_runfile_links is specified.
*/
protected static Path getLocalRunfilesDirectory(TestRunnerAction testAction, ActionExecutionContext actionExecutionContext, BinTools binTools, ImmutableMap<String, String> shellEnvironment, boolean enableRunfiles) throws ExecException, InterruptedException {
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
Path runfilesDir = execSettings.getRunfilesDir();
// as a flag to the build.
if (execSettings.getRunfilesSymlinksCreated()) {
return runfilesDir;
}
// Synchronize runfiles tree generation on the runfiles manifest artifact.
// This is necessary, because we might end up with multiple test runner actions
// trying to generate same runfiles tree in case of --runs_per_test > 1 or
// local test sharding.
long startTime = Profiler.nanoTimeMaybe();
synchronized (execSettings.getInputManifest()) {
Profiler.instance().logSimpleTask(startTime, ProfilerTask.WAIT, testAction);
updateLocalRunfilesDirectory(testAction, runfilesDir, actionExecutionContext, binTools, shellEnvironment, enableRunfiles);
}
return runfilesDir;
}
use of com.google.devtools.build.lib.rules.test.TestTargetExecutionSettings in project bazel by bazelbuild.
the class TestStrategy method updateLocalRunfilesDirectory.
/**
* Ensure the runfiles tree exists and is consistent with the TestAction's manifest
* ($0.runfiles_manifest), bringing it into consistency if not. The contents of the output file
* $0.runfiles/MANIFEST, if it exists, are used a proxy for the set of existing symlinks, to avoid
* the need for recursion.
*/
private static void updateLocalRunfilesDirectory(TestRunnerAction testAction, Path runfilesDir, ActionExecutionContext actionExecutionContext, BinTools binTools, ImmutableMap<String, String> shellEnvironment, boolean enableRunfiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
Path outputManifest = runfilesDir.getRelative("MANIFEST");
try {
// an up-to-date check.
if (!outputManifest.isSymbolicLink() && Arrays.equals(outputManifest.getDigest(), execSettings.getInputManifest().getPath().getDigest())) {
return;
}
} catch (IOException e1) {
// Ignore it - we will just try to create runfiles directory.
}
executor.getEventHandler().handle(Event.progress("Building runfiles directory for '" + execSettings.getExecutable().prettyPrint() + "'."));
new SymlinkTreeHelper(execSettings.getInputManifest().getPath(), runfilesDir, false).createSymlinks(testAction, actionExecutionContext, binTools, shellEnvironment, enableRunfiles);
executor.getEventHandler().handle(Event.progress(testAction.getProgressMessage()));
}
use of com.google.devtools.build.lib.rules.test.TestTargetExecutionSettings in project bazel by bazelbuild.
the class TestStrategy method addRunUnderArgs.
private static void addRunUnderArgs(TestRunnerAction testAction, List<String> args) {
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
if (execSettings.getRunUnderExecutable() != null) {
args.add(execSettings.getRunUnderExecutable().getRootRelativePath().getCallablePathString());
} else {
String command = execSettings.getRunUnder().getCommand();
// --run_under commands that do not contain '/' are either shell built-ins or need to be
// located on the PATH env, so we wrap them in a shell invocation. Note that we shell tokenize
// the --run_under parameter and getCommand only returns the first such token.
boolean needsShell = !command.contains("/");
if (needsShell) {
args.add(testAction.getConfiguration().getShellExecutable().getPathString());
args.add("-c");
args.add("\"$@\"");
// Sets $0.
args.add("/bin/sh");
}
args.add(command);
}
args.addAll(testAction.getExecutionSettings().getRunUnder().getOptions());
}
Aggregations