use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class CustomCommandLineTest method testJoinExpandedTreeArtifactExecPath.
@Test
public void testJoinExpandedTreeArtifactExecPath() {
Artifact treeArtifact = createTreeArtifact("myTreeArtifact");
CommandLine commandLine = CustomCommandLine.builder().add("hello").addJoinExpandedTreeArtifactExecPath(":", treeArtifact).build();
assertThat(commandLine.arguments()).containsExactly("hello", "JoinExpandedTreeArtifactExecPathsArg{ delimiter: :, treeArtifact: myTreeArtifact}");
final Iterable<TreeFileArtifact> treeFileArtifacts = ImmutableList.of(createTreeFileArtifact(treeArtifact, "children/child1"), createTreeFileArtifact(treeArtifact, "children/child2"));
ArtifactExpander artifactExpander = new ArtifactExpander() {
@Override
public void expand(Artifact artifact, Collection<? super Artifact> output) {
for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
if (treeFileArtifact.getParent().equals(artifact)) {
output.add(treeFileArtifact);
}
}
}
};
assertThat(commandLine.arguments(artifactExpander)).containsExactly("hello", "myTreeArtifact/children/child1:myTreeArtifact/children/child2");
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class CustomCommandLineTest method testTreeFileArtifactExecPathWithTemplateArgs.
@Test
public void testTreeFileArtifactExecPathWithTemplateArgs() {
Artifact treeArtifact = createTreeArtifact("myArtifact/treeArtifact1");
CustomCommandLine commandLineTemplate = CustomCommandLine.builder().addPlaceholderTreeArtifactFormattedExecPath("path:%s", treeArtifact).build();
TreeFileArtifact treeFileArtifact = createTreeFileArtifact(treeArtifact, "children/child1");
CustomCommandLine commandLine = commandLineTemplate.evaluateTreeFileArtifacts(ImmutableList.of(treeFileArtifact));
assertThat(commandLine.arguments()).containsExactly("path:myArtifact/treeArtifact1/children/child1");
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact 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.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class ActionInputHelper method asTreeFileArtifacts.
/** Returns a Set of TreeFileArtifacts with the given parent and parent-relative paths. */
public static Set<TreeFileArtifact> asTreeFileArtifacts(final Artifact parent, Set<? extends PathFragment> parentRelativePaths) {
Preconditions.checkState(parent.isTreeArtifact(), "Given parent %s must be a TreeArtifact", parent);
ImmutableSet.Builder<TreeFileArtifact> builder = ImmutableSet.builder();
for (PathFragment path : parentRelativePaths) {
builder.add(treeFileArtifact(parent, path));
}
return builder.build();
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class SpawnActionTemplateTest method testExpandedAction_illegalOutputPath.
@Test
public void testExpandedAction_illegalOutputPath() throws Exception {
Artifact inputTreeArtifact = createInputTreeArtifact();
Artifact outputTreeArtifact = createOutputTreeArtifact();
Iterable<TreeFileArtifact> inputTreeFileArtifacts = createInputTreeFileArtifacts(inputTreeArtifact);
SpawnActionTemplate.Builder builder = builder(inputTreeArtifact, outputTreeArtifact).setExecutable(new PathFragment("/bin/cp")).setCommandLineTemplate(createSimpleCommandLineTemplate(inputTreeArtifact, outputTreeArtifact));
OutputPathMapper mapper = new OutputPathMapper() {
@Override
public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
return new PathFragment("//absolute/" + inputTreeFileArtifact.getParentRelativePath());
}
};
SpawnActionTemplate actionTemplate = builder.setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
try {
actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, ArtifactOwner.NULL_OWNER);
fail("Absolute output paths not allowed, expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
mapper = new OutputPathMapper() {
@Override
public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
return new PathFragment("../" + inputTreeFileArtifact.getParentRelativePath());
}
};
actionTemplate = builder.setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
try {
actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, ArtifactOwner.NULL_OWNER);
fail("Output paths containing '..' not allowed, expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
}
Aggregations