use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testOneExpandedActionThrowsInActionTemplate.
@Test
public void testOneExpandedActionThrowsInActionTemplate() 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:
// One Action that touches the output file.
// The other action that just throws when executed.
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 throwingAction = new ThrowingDummyAction(ImmutableList.<Artifact>of(treeFileArtifactB), ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2));
actionTemplateExpansionFunction = new DummyActionTemplateExpansionFunction(ImmutableMultimap.<ActionTemplate<?>, Action>of(actionTemplate, generateOutputAction, actionTemplate, throwingAction));
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 TreeArtifactBuildTest method testEmptyInputAndOutputTreeArtifactInActionTemplate.
@Test
public void testEmptyInputAndOutputTreeArtifactInActionTemplate() throws Throwable {
// artifact1 is an empty tree artifact which is generated by a single no-op dummy action.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
registerAction(new NoOpDummyAction(ImmutableList.<Artifact>of(), ImmutableList.of(artifact1)));
// artifact2 is a tree artifact generated by an action template that takes artifact1 as input.
Artifact artifact2 = createTreeArtifact("treeArtifact2");
SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
registerAction(actionTemplate);
buildArtifact(artifact2);
assertThat(artifact1.getPath().exists()).isTrue();
assertThat(artifact1.getPath().getDirectoryEntries()).isEmpty();
assertThat(artifact2.getPath().exists()).isTrue();
assertThat(artifact2.getPath().getDirectoryEntries()).isEmpty();
}
use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testInputTreeArtifactCreationFailedInActionTemplate.
@Test
public void testInputTreeArtifactCreationFailedInActionTemplate() throws Throwable {
// expect errors
reporter.removeHandler(failFastHandler);
// artifact1 is created by a action that throws.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
registerAction(new ThrowingDummyAction(ImmutableList.<Artifact>of(), ImmutableList.of(artifact1)));
// artifact2 is a tree artifact generated by an action template.
Artifact artifact2 = createTreeArtifact("treeArtifact2");
SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
registerAction(actionTemplate);
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 testThrowsOnArtifactPrefixConflict.
@Test
public void testThrowsOnArtifactPrefixConflict() throws Exception {
Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
OutputPathMapper mapper = new OutputPathMapper() {
private int i = 0;
@Override
public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
PathFragment path;
switch(i) {
case 0:
path = new PathFragment("path_prefix");
break;
case 1:
path = new PathFragment("path_prefix/conflict");
break;
default:
path = inputTreeFileArtifact.getParentRelativePath();
}
++i;
return 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 ArtifactPrefixConflictException");
} catch (ArtifactPrefixConflictException e) {
// Expected ArtifactPrefixConflictException
}
}
use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testExpandedActionDoesNotGenerateOutputInActionTemplate.
@Test
public void testExpandedActionDoesNotGenerateOutputInActionTemplate() 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:
// One Action that touches the output file.
// The other action that does not generate the output file.
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 NoOpDummyAction(ImmutableList.<Artifact>of(treeFileArtifactB), ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2));
actionTemplateExpansionFunction = new DummyActionTemplateExpansionFunction(ImmutableMultimap.<ActionTemplate<?>, Action>of(actionTemplate, generateOutputAction, actionTemplate, noGenerateOutputAction));
try {
buildArtifact(artifact2);
fail("Expected BuildFailedException");
} catch (BuildFailedException e) {
assertThat(e.getMessage()).contains("not all outputs were created or valid");
}
}
Aggregations