use of com.google.devtools.build.lib.actions.Artifact 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.actions.Artifact in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testOutputsAreReadOnlyAndExecutable.
@Test
public void testOutputsAreReadOnlyAndExecutable() throws Exception {
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
writeFile(out.getPath().getChild("three").getChild("four"), "three/four");
registerOutput(actionExecutionContext, "one");
registerOutput(actionExecutionContext, "two");
registerOutput(actionExecutionContext, "three/four");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
buildArtifact(action.getSoleOutput());
checkDirectoryPermissions(out.getPath());
checkFilePermissions(out.getPath().getChild("one"));
checkFilePermissions(out.getPath().getChild("two"));
checkDirectoryPermissions(out.getPath().getChild("three"));
checkFilePermissions(out.getPath().getChild("three").getChild("four"));
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testCacheCheckingForTreeArtifactsDoesNotCauseReexecution.
/** Unchanged TreeArtifact outputs should not cause reexecution. */
@Test
public void testCacheCheckingForTreeArtifactsDoesNotCauseReexecution() throws Exception {
Artifact outOne = createTreeArtifact("outputOne");
Button buttonOne = new Button();
Artifact outTwo = createTreeArtifact("outputTwo");
Button buttonTwo = new Button();
TouchingTestAction actionOne = new TouchingTestAction(buttonOne, outOne, "file_one", "file_two");
registerAction(actionOne);
CopyTreeAction actionTwo = new CopyTreeAction(buttonTwo, outOne, outTwo, "file_one", "file_two");
registerAction(actionTwo);
buttonOne.pressed = buttonTwo.pressed = false;
buildArtifact(outTwo);
// built
assertTrue(buttonOne.pressed);
// built
assertTrue(buttonTwo.pressed);
buttonOne.pressed = buttonTwo.pressed = false;
buildArtifact(outTwo);
// not built
assertFalse(buttonOne.pressed);
// not built
assertFalse(buttonTwo.pressed);
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.
@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
// Failure expected
StoredEventHandler storingEventHandler = new StoredEventHandler();
reporter.removeHandler(failFastHandler);
reporter.addHandler(storingEventHandler);
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
try {
buildArtifact(action.getSoleOutput());
// Should have thrown
fail();
} catch (BuildFailedException e) {
List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
}
use of com.google.devtools.build.lib.actions.Artifact 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");
}
}
Aggregations