Search in sources :

Example 16 with TreeFileArtifact

use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.

the class ActionMetadataHandler method constructTreeArtifactValue.

private TreeArtifactValue constructTreeArtifactValue(Collection<TreeFileArtifact> contents) throws IOException {
    Map<TreeFileArtifact, FileArtifactValue> values = Maps.newHashMapWithExpectedSize(contents.size());
    for (TreeFileArtifact treeFileArtifact : contents) {
        FileArtifactValue cachedValue = additionalOutputData.get(treeFileArtifact);
        if (cachedValue == null) {
            FileValue fileValue = outputArtifactData.get(treeFileArtifact);
            // file will be requested from this cache too many times.
            if (fileValue == null) {
                try {
                    fileValue = constructFileValue(treeFileArtifact, /*statNoFollow=*/
                    null);
                } catch (FileNotFoundException e) {
                    String errorMessage = String.format("Failed to resolve relative path %s inside TreeArtifact %s. " + "The associated file is either missing or is an invalid symlink.", treeFileArtifact.getParentRelativePath(), treeFileArtifact.getParent().getExecPathString());
                    throw new IOException(errorMessage, e);
                }
            }
            // A minor hack: maybeStoreAdditionalData will force the data to be stored
            // in additionalOutputData.
            maybeStoreAdditionalData(treeFileArtifact, fileValue, null);
            cachedValue = Preconditions.checkNotNull(additionalOutputData.get(treeFileArtifact), treeFileArtifact);
        }
        values.put(treeFileArtifact, cachedValue);
    }
    return TreeArtifactValue.create(values);
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 17 with TreeFileArtifact

use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.

the class ActionTemplateExpansionFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws ActionTemplateExpansionFunctionException, InterruptedException {
    ActionTemplateExpansionKey key = (ActionTemplateExpansionKey) skyKey.argument();
    ActionTemplate actionTemplate = key.getActionTemplate();
    // Requests the TreeArtifactValue object for the input TreeArtifact.
    SkyKey artifactValueKey = ArtifactSkyKey.key(actionTemplate.getInputTreeArtifact(), true);
    TreeArtifactValue treeArtifactValue = (TreeArtifactValue) env.getValue(artifactValueKey);
    // Input TreeArtifact is not ready yet.
    if (env.valuesMissing()) {
        return null;
    }
    Iterable<TreeFileArtifact> inputTreeFileArtifacts = treeArtifactValue.getChildren();
    Iterable<Action> expandedActions;
    try {
        // Expand the action template using the list of expanded input TreeFileArtifacts.
        expandedActions = ImmutableList.<Action>copyOf(actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, key));
        // TODO(rduan): Add a check to verify the inputs of expanded actions are subsets of inputs
        // of the ActionTemplate.
        checkActionAndArtifactConflicts(expandedActions);
    } catch (ActionConflictException e) {
        e.reportTo(env.getListener());
        throw new ActionTemplateExpansionFunctionException(e);
    } catch (ArtifactPrefixConflictException e) {
        env.getListener().handle(Event.error(e.getMessage()));
        throw new ActionTemplateExpansionFunctionException(e);
    }
    return new ActionTemplateExpansionValue(expandedActions);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) Action(com.google.devtools.build.lib.actions.Action) ActionTemplateExpansionKey(com.google.devtools.build.lib.skyframe.ActionTemplateExpansionValue.ActionTemplateExpansionKey) ActionTemplate(com.google.devtools.build.lib.analysis.actions.ActionTemplate) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)

Example 18 with TreeFileArtifact

use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.

the class ArtifactFunction method createTreeArtifactValueFromActionTemplate.

private static TreeArtifactValue createTreeArtifactValueFromActionTemplate(ActionTemplate actionTemplate, Artifact treeArtifact, Environment env) throws ArtifactFunctionException, InterruptedException {
    // Request the list of expanded actions from the ActionTemplate.
    ActionTemplateExpansionValue expansionValue = (ActionTemplateExpansionValue) env.getValue(ActionTemplateExpansionValue.key(actionTemplate));
    // The expanded actions are not yet available.
    if (env.valuesMissing()) {
        return null;
    }
    // Execute the expanded actions in parallel.
    Iterable<SkyKey> expandedActionExecutionKeys = ActionExecutionValue.keys(expansionValue.getExpandedActions());
    Map<SkyKey, SkyValue> expandedActionValueMap = env.getValues(expandedActionExecutionKeys);
    // The execution values of the expanded actions are not yet all available.
    if (env.valuesMissing()) {
        return null;
    }
    // Aggregate the ArtifactValues for individual TreeFileArtifacts into a TreeArtifactValue for
    // the parent TreeArtifact.
    ImmutableMap.Builder<TreeFileArtifact, FileArtifactValue> map = ImmutableMap.builder();
    for (Map.Entry<SkyKey, SkyValue> entry : expandedActionValueMap.entrySet()) {
        SkyKey expandedActionExecutionKey = entry.getKey();
        ActionExecutionValue actionExecutionValue = (ActionExecutionValue) entry.getValue();
        Action expandedAction = (Action) expandedActionExecutionKey.argument();
        Iterable<TreeFileArtifact> treeFileArtifacts = findActionOutputsWithMatchingParent(expandedAction, treeArtifact);
        Preconditions.checkState(!Iterables.isEmpty(treeFileArtifacts), "Action %s does not output TreeFileArtifact under %s", expandedAction, treeArtifact);
        for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
            FileArtifactValue value = createSimpleFileArtifactValue(treeFileArtifact, expandedAction, actionExecutionValue, env);
            map.put(treeFileArtifact, value);
        }
    }
    // Return the aggregated TreeArtifactValue.
    return TreeArtifactValue.create(map.build());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Action(com.google.devtools.build.lib.actions.Action) ImmutableMap(com.google.common.collect.ImmutableMap) SkyValue(com.google.devtools.build.skyframe.SkyValue) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 19 with TreeFileArtifact

use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.

the class CustomCommandLineTest method testTreeFileArtifactExecPathArgs.

@Test
public void testTreeFileArtifactExecPathArgs() {
    Artifact treeArtifactOne = createTreeArtifact("myArtifact/treeArtifact1");
    Artifact treeArtifactTwo = createTreeArtifact("myArtifact/treeArtifact2");
    CustomCommandLine commandLineTemplate = CustomCommandLine.builder().addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne).addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo).build();
    TreeFileArtifact treeFileArtifactOne = createTreeFileArtifact(treeArtifactOne, "children/child1");
    TreeFileArtifact treeFileArtifactTwo = createTreeFileArtifact(treeArtifactTwo, "children/child2");
    CustomCommandLine commandLine = commandLineTemplate.evaluateTreeFileArtifacts(ImmutableList.of(treeFileArtifactOne, treeFileArtifactTwo));
    assertThat(commandLine.arguments()).containsExactly("--argOne", "myArtifact/treeArtifact1/children/child1", "--argTwo", "myArtifact/treeArtifact2/children/child2").inOrder();
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 20 with TreeFileArtifact

use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.

the class SpawnActionTemplateTest method testExpandedAction_commonToolsAndInputs.

@Test
public void testExpandedAction_commonToolsAndInputs() throws Exception {
    Artifact inputTreeArtifact = createInputTreeArtifact();
    Artifact outputTreeArtifact = createOutputTreeArtifact();
    Artifact commonInput = createDerivedArtifact("common/input");
    Artifact commonTool = createDerivedArtifact("common/tool");
    Artifact executable = createDerivedArtifact("bin/cp");
    SpawnActionTemplate actionTemplate = builder(inputTreeArtifact, outputTreeArtifact).setExecutionInfo(ImmutableMap.<String, String>of("local", "")).setExecutable(executable).setCommandLineTemplate(createSimpleCommandLineTemplate(inputTreeArtifact, outputTreeArtifact)).setOutputPathMapper(IDENTITY_MAPPER).setMnemonics("ActionTemplate", "ExpandedAction").addCommonTools(ImmutableList.of(commonTool)).addCommonInputs(ImmutableList.of(commonInput)).build(ActionsTestUtil.NULL_ACTION_OWNER);
    Iterable<TreeFileArtifact> inputTreeFileArtifacts = createInputTreeFileArtifacts(inputTreeArtifact);
    List<SpawnAction> expandedActions = ImmutableList.copyOf(actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, ArtifactOwner.NULL_OWNER));
    for (int i = 0; i < expandedActions.size(); ++i) {
        assertThat(expandedActions.get(i).getInputs()).containsAllOf(commonInput, commonTool, executable);
        assertThat(expandedActions.get(i).getTools()).containsAllOf(commonTool, executable);
    }
}
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)

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