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);
}
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);
}
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());
}
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();
}
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);
}
}
Aggregations