Search in sources :

Example 6 with TreeFileArtifact

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

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);
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) ArtifactExpander(com.google.devtools.build.lib.actions.Artifact.ArtifactExpander) Executor(com.google.devtools.build.lib.actions.Executor) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Collection(java.util.Collection) 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)

Example 8 with TreeFileArtifact

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();
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ArrayList(java.util.ArrayList) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) 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 9 with TreeFileArtifact

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());
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 10 with TreeFileArtifact

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;
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) 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) LinkedHashMap(java.util.LinkedHashMap)

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