use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class SpawnActionTemplateTest method testExpandedAction_arguments.
@Test
public void testExpandedAction_arguments() throws Exception {
SpawnActionTemplate actionTemplate = createSimpleSpawnActionTemplate();
Artifact inputTreeArtifact = createInputTreeArtifact();
Artifact outputTreeArtifact = createOutputTreeArtifact();
Iterable<TreeFileArtifact> inputTreeFileArtifacts = createInputTreeFileArtifacts(inputTreeArtifact);
List<SpawnAction> expandedActions = ImmutableList.copyOf(actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, ArtifactOwner.NULL_OWNER));
assertThat(expandedActions).hasSize(3);
for (int i = 0; i < expandedActions.size(); ++i) {
String baseName = String.format("child%d", i);
assertThat(expandedActions.get(i).getArguments()).containsExactly("/bin/cp", inputTreeArtifact.getExecPathString() + "/children/" + baseName, outputTreeArtifact.getExecPathString() + "/children/" + baseName).inOrder();
}
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class ParamFileWriteActionTest method actionExecutionContext.
private ActionExecutionContext actionExecutionContext() throws Exception {
final Iterable<TreeFileArtifact> treeFileArtifacts = ImmutableList.of(createTreeFileArtifact(treeArtifact, "artifacts/treeFileArtifact1"), createTreeFileArtifact(treeArtifact, "artifacts/treeFileArtifact2"));
ArtifactExpander artifactExpander = new ArtifactExpander() {
@Override
public void expand(Artifact artifact, Collection<? super Artifact> output) {
for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
if (treeFileArtifact.getParent().equals(artifact)) {
output.add(treeFileArtifact);
}
}
}
};
Executor executor = new TestExecutorBuilder(directories, binTools).build();
return new ActionExecutionContext(executor, null, null, new FileOutErr(), ImmutableMap.<String, String>of(), artifactExpander);
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class PopulateTreeArtifactActionTest method testOutputTreeFileArtifactDirsCreated.
@Test
public void testOutputTreeFileArtifactDirsCreated() throws Exception {
Action action = createPopulateTreeArtifactAction();
scratch.overwriteFile("archiveManifest.txt", "archive_members/dirA/memberA", "archive_members/dirB/memberB");
ArrayList<Artifact> treeFileArtifacts = new ArrayList<Artifact>();
ActionExecutionContext executionContext = actionExecutionContext(treeFileArtifacts);
action.execute(executionContext);
// We check whether the parent directory structures of output TreeFileArtifacts exist even
// though the spawn is not executed (the SpawnActionContext is mocked out).
assertThat(treeFileArtifacts).hasSize(2);
for (Artifact treeFileArtifact : treeFileArtifacts) {
assertThat(treeFileArtifact.getPath().getParentDirectory().exists()).isTrue();
assertThat(treeFileArtifact.getPath().exists()).isFalse();
}
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class FilesystemValueCheckerTest method actionValueWithTreeArtifacts.
private ActionExecutionValue actionValueWithTreeArtifacts(List<TreeFileArtifact> contents) {
Map<Artifact, FileValue> fileData = new HashMap<>();
Map<Artifact, Map<TreeFileArtifact, FileArtifactValue>> directoryData = new HashMap<>();
for (TreeFileArtifact output : contents) {
try {
Map<TreeFileArtifact, FileArtifactValue> dirDatum = directoryData.get(output.getParent());
if (dirDatum == null) {
dirDatum = new HashMap<>();
directoryData.put(output.getParent(), dirDatum);
}
FileValue fileValue = ActionMetadataHandler.fileValueFromArtifact(output, null, null);
dirDatum.put(output, FileArtifactValue.create(output, fileValue));
fileData.put(output, fileValue);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
Map<Artifact, TreeArtifactValue> treeArtifactData = new HashMap<>();
for (Map.Entry<Artifact, Map<TreeFileArtifact, FileArtifactValue>> dirDatum : directoryData.entrySet()) {
treeArtifactData.put(dirDatum.getKey(), TreeArtifactValue.create(dirDatum.getValue()));
}
return new ActionExecutionValue(fileData, treeArtifactData, ImmutableMap.<Artifact, FileArtifactValue>of());
}
use of com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact in project bazel by bazelbuild.
the class ActionTemplateExpansionFunctionTest method createAndPopulateTreeArtifact.
private Artifact createAndPopulateTreeArtifact(String path, String... childRelativePaths) throws Exception {
Artifact treeArtifact = createTreeArtifact(path);
Map<TreeFileArtifact, FileArtifactValue> treeFileArtifactMap = new LinkedHashMap<>();
for (String childRelativePath : childRelativePaths) {
TreeFileArtifact treeFileArtifact = ActionInputHelper.treeFileArtifact(treeArtifact, new PathFragment(childRelativePath));
scratch.file(treeFileArtifact.getPath().toString(), childRelativePath);
// We do not care about the FileArtifactValues in this test.
treeFileArtifactMap.put(treeFileArtifact, FileArtifactValue.create(treeFileArtifact));
}
artifactValueMap.put(treeArtifact, TreeArtifactValue.create(ImmutableMap.copyOf(treeFileArtifactMap)));
return treeArtifact;
}
Aggregations