use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper 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
}
}
use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper 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.OutputPathMapper 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
}
}
Aggregations