Search in sources :

Example 11 with TreeFileArtifact

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
    }
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) OutputPathMapper(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) OwnedArtifact(com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 12 with TreeFileArtifact

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());
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 13 with TreeFileArtifact

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);
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ExecException(com.google.devtools.build.lib.actions.ExecException) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

Example 14 with TreeFileArtifact

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();
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ImmutableList(com.google.common.collect.ImmutableList) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 15 with TreeFileArtifact

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();
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ImmutableList(com.google.common.collect.ImmutableList) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Aggregations

TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)30 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)22 Artifact (com.google.devtools.build.lib.actions.Artifact)20 Test (org.junit.Test)18 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)13 Action (com.google.devtools.build.lib.actions.Action)8 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)6 SpawnActionTemplate (com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate)6 TestAction (com.google.devtools.build.lib.actions.util.TestAction)5 ActionTemplate (com.google.devtools.build.lib.analysis.actions.ActionTemplate)5 DummyAction (com.google.devtools.build.lib.actions.util.TestAction.DummyAction)4 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)3 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)3 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)3 OutputPathMapper (com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper)3 OwnedArtifact (com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact)3 IOException (java.io.IOException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)2