use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testExpandedActionsBuildInActionTemplate.
@Test
public void testExpandedActionsBuildInActionTemplate() throws Throwable {
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
Artifact artifact2 = createTreeArtifact("treeArtifact2");
SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
registerAction(actionTemplate);
// We mock out the action template function to expand into two actions that just touch the
// output files.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child2"));
Action generateOutputAction = new DummyAction(ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1);
Action noGenerateOutputAction = new DummyAction(ImmutableList.<Artifact>of(treeFileArtifactB), expectedOutputTreeFileArtifact2);
actionTemplateExpansionFunction = new DummyActionTemplateExpansionFunction(ImmutableMultimap.<ActionTemplate<?>, Action>of(actionTemplate, generateOutputAction, actionTemplate, noGenerateOutputAction));
buildArtifact(artifact2);
}
use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testAllExpandedActionsThrowInActionTemplate.
@Test
public void testAllExpandedActionsThrowInActionTemplate() throws Throwable {
// expect errors
reporter.removeHandler(failFastHandler);
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
Artifact artifact2 = createTreeArtifact("treeArtifact2");
SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
registerAction(actionTemplate);
// We mock out the action template function to expand into two actions that throw when executed.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child2"));
Action throwingAction = new ThrowingDummyAction(ImmutableList.<Artifact>of(treeFileArtifactA), ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact1));
Action anotherThrowingAction = new ThrowingDummyAction(ImmutableList.<Artifact>of(treeFileArtifactB), ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2));
actionTemplateExpansionFunction = new DummyActionTemplateExpansionFunction(ImmutableMultimap.<ActionTemplate<?>, Action>of(actionTemplate, throwingAction, actionTemplate, anotherThrowingAction));
try {
buildArtifact(artifact2);
fail("Expected BuildFailedException");
} catch (BuildFailedException e) {
assertThat(e.getMessage()).contains("Throwing dummy action");
}
}
use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class ActionTemplateExpansionFunctionTest method testThrowsOnActionConflict.
@Test
public void testThrowsOnActionConflict() throws Exception {
Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
OutputPathMapper mapper = new OutputPathMapper() {
@Override
public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
return new PathFragment("conflict_path");
}
};
SpawnActionTemplate spawnActionTemplate = new SpawnActionTemplate.Builder(inputTreeArtifact, outputTreeArtifact).setExecutable(new PathFragment("/bin/cp")).setCommandLineTemplate(CustomCommandLine.builder().build()).setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
try {
evaluate(spawnActionTemplate);
fail("Expected ActionConflictException");
} catch (ActionConflictException e) {
// Expected ActionConflictException
}
}
use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class ActionTemplateExpansionFunctionTest method testActionTemplateExpansionFunction.
@Test
public void testActionTemplateExpansionFunction() throws Exception {
Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
SpawnActionTemplate spawnActionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(inputTreeArtifact, outputTreeArtifact);
List<Action> actions = evaluate(spawnActionTemplate);
assertThat(actions).hasSize(3);
ArtifactOwner owner = ActionTemplateExpansionValue.createActionTemplateExpansionKey(spawnActionTemplate);
int i = 0;
for (Action action : actions) {
String childName = "child" + i;
assertThat(Artifact.toExecPaths(action.getInputs())).contains("out/inputTreeArtifact/" + childName);
assertThat(Artifact.toExecPaths(action.getOutputs())).containsExactly("out/outputTreeArtifact/" + childName);
assertThat(Iterables.getOnlyElement(action.getOutputs()).getArtifactOwner()).isEqualTo(owner);
++i;
}
}
Aggregations