use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact 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.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class ArtifactFunctionTest method testActionTreeArtifactOutput.
@Test
public void testActionTreeArtifactOutput() throws Throwable {
Artifact artifact = createDerivedTreeArtifactWithAction("treeArtifact");
TreeFileArtifact treeFileArtifact1 = createFakeTreeFileArtifact(artifact, "child1", "hello1");
TreeFileArtifact treeFileArtifact2 = createFakeTreeFileArtifact(artifact, "child2", "hello2");
TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact);
assertNotNull(value.getChildValues().get(treeFileArtifact1));
assertNotNull(value.getChildValues().get(treeFileArtifact2));
assertNotNull(value.getChildValues().get(treeFileArtifact1).getDigest());
assertNotNull(value.getChildValues().get(treeFileArtifact2).getDigest());
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class PopulateTreeArtifactAction method execute.
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
Spawn spawn;
// Create a spawn to unzip the archive file into the output TreeArtifact.
try {
spawn = createSpawn();
} catch (IOException e) {
throw new ActionExecutionException(e, this, false);
} catch (IllegalManifestFileException e) {
throw new ActionExecutionException(e, this, true);
}
// case we just return without generating anything under the output TreeArtifact.
if (spawn.getOutputFiles().isEmpty()) {
return;
}
// Check spawn output TreeFileArtifact conflicts.
try {
checkOutputConflicts(spawn.getOutputFiles());
} catch (ArtifactPrefixConflictException e) {
throw new ActionExecutionException(e, this, true);
}
// Create parent directories for the output TreeFileArtifacts.
try {
for (ActionInput fileEntry : spawn.getOutputFiles()) {
FileSystemUtils.createDirectoryAndParents(((Artifact) fileEntry).getPath().getParentDirectory());
}
} catch (IOException e) {
throw new ActionExecutionException(e, this, false);
}
// Execute the spawn.
try {
getContext(executor).exec(spawn, actionExecutionContext);
} catch (ExecException e) {
throw e.toActionExecutionException(getMnemonic() + " action failed for target: " + getOwner().getLabel(), executor.getVerboseFailures(), this);
}
// Populate the output TreeArtifact with the Spawn output TreeFileArtifacts.
for (ActionInput fileEntry : spawn.getOutputFiles()) {
actionExecutionContext.getMetadataHandler().addExpandedTreeOutput((TreeFileArtifact) fileEntry);
}
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class SpawnActionTemplate method generateActionForInputArtifacts.
@Override
public Iterable<SpawnAction> generateActionForInputArtifacts(Iterable<TreeFileArtifact> inputTreeFileArtifacts, ArtifactOwner artifactOwner) {
ImmutableList.Builder<SpawnAction> expandedActions = new ImmutableList.Builder<>();
for (TreeFileArtifact inputTreeFileArtifact : inputTreeFileArtifacts) {
PathFragment parentRelativeOutputPath = outputPathMapper.parentRelativeOutputPath(inputTreeFileArtifact);
TreeFileArtifact outputTreeFileArtifact = ActionInputHelper.treeFileArtifact(outputTreeArtifact, parentRelativeOutputPath, artifactOwner);
expandedActions.add(createAction(inputTreeFileArtifact, outputTreeFileArtifact));
}
return expandedActions.build();
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class CppCompileActionTemplate method generateActionForInputArtifacts.
@Override
public Iterable<CppCompileAction> generateActionForInputArtifacts(Iterable<TreeFileArtifact> inputTreeFileArtifacts, ArtifactOwner artifactOwner) {
ImmutableList.Builder<CppCompileAction> expandedActions = new ImmutableList.Builder<>();
for (TreeFileArtifact inputTreeFileArtifact : inputTreeFileArtifacts) {
String outputName = outputTreeFileArtifactName(inputTreeFileArtifact);
TreeFileArtifact outputTreeFileArtifact = ActionInputHelper.treeFileArtifact(outputTreeArtifact, new PathFragment(outputName), artifactOwner);
expandedActions.add(createAction(inputTreeFileArtifact, outputTreeFileArtifact));
}
return expandedActions.build();
}
Aggregations