use of com.google.devtools.build.lib.actions.SpawnActionContext in project bazel by bazelbuild.
the class BlazeExecutorTest method testDebugPrintActionContexts.
@Test
public void testDebugPrintActionContexts() throws Exception {
TestExecutorBuilder builder = new TestExecutorBuilder(directories, binTools);
OptionsParser parser = OptionsParser.newOptionsParser(TestExecutorBuilder.DEFAULT_OPTIONS);
parser.parse("--debug_print_action_contexts");
Reporter reporter = new Reporter(new EventBus());
StoredEventHandler storedEventHandler = new StoredEventHandler();
reporter.addHandler(storedEventHandler);
SpawnActionContext mockStrategy = Mockito.mock(SpawnActionContext.class);
builder.setReporter(reporter).setOptionsParser(parser).setExecution("mock", mockStrategy);
builder.build();
Event event = Iterables.find(storedEventHandler.getEvents(), new Predicate<Event>() {
@Override
public boolean apply(@Nullable Event event) {
return event.getMessage().contains("SpawnActionContextMap: \"mock\" = ");
}
});
assertThat(event).isNotNull();
assertThat(event.getMessage()).contains("\"mock\" = " + mockStrategy.getClass().getSimpleName());
}
use of com.google.devtools.build.lib.actions.SpawnActionContext in project bazel by bazelbuild.
the class StandaloneTestStrategy method executeTest.
protected TestResultData executeTest(TestRunnerAction action, Spawn spawn, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException, IOException {
Executor executor = actionExecutionContext.getExecutor();
Closeable streamed = null;
Path testLogPath = action.getTestLog().getPath();
TestResultData.Builder builder = TestResultData.newBuilder();
long startTime = executor.getClock().currentTimeMillis();
SpawnActionContext spawnActionContext = executor.getSpawnActionContext(action.getMnemonic());
try {
try {
if (executionOptions.testOutput.equals(TestOutputFormat.STREAMED)) {
streamed = new StreamedTestOutput(Reporter.outErrForReporter(actionExecutionContext.getExecutor().getEventHandler()), testLogPath);
}
spawnActionContext.exec(spawn, actionExecutionContext);
builder.setTestPassed(true).setStatus(BlazeTestStatus.PASSED).setCachable(true).setPassedLog(testLogPath.getPathString());
} catch (ExecException e) {
// Execution failed, which we consider a test failure.
// TODO(bazel-team): set cachable==true for relevant statuses (failure, but not for
// timeout, etc.)
builder.setTestPassed(false).setStatus(e.hasTimedOut() ? BlazeTestStatus.TIMEOUT : BlazeTestStatus.FAILED).addFailedLogs(testLogPath.getPathString());
if (spawnActionContext.shouldPropagateExecException()) {
throw e;
}
} finally {
long duration = executor.getClock().currentTimeMillis() - startTime;
builder.addTestTimes(duration);
builder.addTestProcessTimes(duration);
builder.setRunDurationMillis(duration);
if (streamed != null) {
streamed.close();
}
}
TestCase details = parseTestResult(action.resolve(actionExecutionContext.getExecutor().getExecRoot()).getXmlOutputPath());
if (details != null) {
builder.setTestCase(details);
}
if (action.isCoverageMode()) {
builder.setHasCoverage(true);
}
return builder.build();
} catch (IOException e) {
throw new TestExecException(e.getMessage());
}
}
use of com.google.devtools.build.lib.actions.SpawnActionContext in project bazel by bazelbuild.
the class JavaHeaderCompileAction method execute.
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
if (!useDirectClasspath()) {
super.execute(actionExecutionContext);
return;
}
Executor executor = actionExecutionContext.getExecutor();
SpawnActionContext context = getContext(executor);
try {
context.exec(getDirectSpawn(), actionExecutionContext);
} catch (ExecException e) {
// if the direct input spawn failed, try again with transitive inputs to produce better
// better messages
super.execute(actionExecutionContext);
// the compilation should never fail with direct deps but succeed with transitive inputs
if (fallbackError) {
throw e.toActionExecutionException("header compilation failed unexpectedly", executor.getVerboseFailures(), this);
}
Event event = Event.warn(getOwner().getLocation(), "header compilation failed unexpectedly");
executor.getEventHandler().handle(event);
}
}
use of com.google.devtools.build.lib.actions.SpawnActionContext in project bazel by bazelbuild.
the class StandaloneSpawnStrategyTest method setUp.
@Before
public final void setUp() throws Exception {
Path testRoot = createTestRoot();
Path workspaceDir = testRoot.getRelative("workspace-name");
workspaceDir.createDirectory();
// setup output base & directories
Path outputBase = testRoot.getRelative("outputBase");
outputBase.createDirectory();
BlazeDirectories directories = new BlazeDirectories(outputBase, outputBase, workspaceDir, "mock-product-name");
// This call implicitly symlinks the integration bin tools into the exec root.
IntegrationMock.get().getIntegrationBinTools(directories);
OptionsParser optionsParser = OptionsParser.newOptionsParser(ExecutionOptions.class);
optionsParser.parse("--verbose_failures");
EventBus bus = new EventBus();
ResourceManager resourceManager = ResourceManager.instanceForTestingOnly();
resourceManager.setAvailableResources(ResourceSet.create(/*memoryMb=*/
1, /*cpuUsage=*/
1, /*ioUsage=*/
1, /*localTestCount=*/
1));
this.executor = new BlazeExecutor(directories.getExecRoot(), reporter, bus, BlazeClock.instance(), optionsParser, ImmutableList.<ActionContext>of(), ImmutableMap.<String, SpawnActionContext>of("", new StandaloneSpawnStrategy(directories.getExecRoot(), false, "mock-product-name", resourceManager)), ImmutableList.<ActionContextProvider>of());
executor.getExecRoot().createDirectory();
}
Aggregations