Search in sources :

Example 26 with TreeFileArtifact

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

the class ActionTemplateExpansionFunctionTest method testThrowsOnActionConflict.

@Test
public void testThrowsOnActionConflict() throws Exception {
    Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
    Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
    OutputPathMapper mapper = new OutputPathMapper() {

        @Override
        public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
            return new PathFragment("conflict_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 ActionConflictException");
    } catch (ActionConflictException e) {
    // Expected ActionConflictException
    }
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) 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) 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 27 with TreeFileArtifact

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

the class ArtifactFunctionTest method testConsecutiveSpawnActionTemplates.

@Test
public void testConsecutiveSpawnActionTemplates() throws Throwable {
    // artifact1 is a tree artifact generated by normal action.
    Artifact artifact1 = createDerivedTreeArtifactWithAction("treeArtifact1");
    createFakeTreeFileArtifact(artifact1, "child1", "hello1");
    createFakeTreeFileArtifact(artifact1, "child2", "hello2");
    // artifact2 is a tree artifact generated by action template.
    Artifact artifact2 = createDerivedTreeArtifactOnly("treeArtifact2");
    createFakeTreeFileArtifact(artifact2, "child1", "hello1");
    createFakeTreeFileArtifact(artifact2, "child2", "hello2");
    actions.add(ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2));
    // artifact3 is a tree artifact generated by action template.
    Artifact artifact3 = createDerivedTreeArtifactOnly("treeArtifact3");
    TreeFileArtifact treeFileArtifact1 = createFakeTreeFileArtifact(artifact3, "child1", "hello1");
    TreeFileArtifact treeFileArtifact2 = createFakeTreeFileArtifact(artifact3, "child2", "hello2");
    actions.add(ActionsTestUtil.createDummySpawnActionTemplate(artifact2, artifact3));
    TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact3);
    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 28 with TreeFileArtifact

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

the class ArtifactFunctionTest method createFakeTreeFileArtifact.

private TreeFileArtifact createFakeTreeFileArtifact(Artifact treeArtifact, String parentRelativePath, String content) throws Exception {
    TreeFileArtifact treeFileArtifact = ActionInputHelper.treeFileArtifact(treeArtifact, new PathFragment(parentRelativePath));
    Path path = treeFileArtifact.getPath();
    FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
    writeFile(path, content);
    return treeFileArtifact;
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 29 with TreeFileArtifact

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

the class ArtifactFunctionTest method testSpawnActionTemplate.

@Test
public void testSpawnActionTemplate() throws Throwable {
    // artifact1 is a tree artifact generated by normal action.
    Artifact artifact1 = createDerivedTreeArtifactWithAction("treeArtifact1");
    createFakeTreeFileArtifact(artifact1, "child1", "hello1");
    createFakeTreeFileArtifact(artifact1, "child2", "hello2");
    // artifact2 is a tree artifact generated by action template.
    Artifact artifact2 = createDerivedTreeArtifactOnly("treeArtifact2");
    TreeFileArtifact treeFileArtifact1 = createFakeTreeFileArtifact(artifact2, "child1", "hello1");
    TreeFileArtifact treeFileArtifact2 = createFakeTreeFileArtifact(artifact2, "child2", "hello2");
    actions.add(ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2));
    TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact2);
    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 30 with TreeFileArtifact

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

the class FilesystemValueCheckerTest method checkDirtyTreeArtifactActions.

public void checkDirtyTreeArtifactActions(BatchStat batchStatter) throws Exception {
    // Normally, an Action specifies the contents of a TreeArtifact when it executes.
    // To decouple FileSystemValueTester checking from Action execution, we inject TreeArtifact
    // contents into ActionExecutionValues.
    Artifact out1 = createTreeArtifact("one");
    TreeFileArtifact file11 = treeFileArtifact(out1, "fizz");
    FileSystemUtils.createDirectoryAndParents(out1.getPath());
    FileSystemUtils.writeContentAsLatin1(file11.getPath(), "buzz");
    Artifact out2 = createTreeArtifact("two");
    FileSystemUtils.createDirectoryAndParents(out2.getPath().getChild("subdir"));
    TreeFileArtifact file21 = treeFileArtifact(out2, "moony");
    TreeFileArtifact file22 = treeFileArtifact(out2, "subdir/wormtail");
    FileSystemUtils.writeContentAsLatin1(file21.getPath(), "padfoot");
    FileSystemUtils.writeContentAsLatin1(file22.getPath(), "prongs");
    Artifact outEmpty = createTreeArtifact("empty");
    FileSystemUtils.createDirectoryAndParents(outEmpty.getPath());
    Artifact outUnchanging = createTreeArtifact("untouched");
    FileSystemUtils.createDirectoryAndParents(outUnchanging.getPath());
    Artifact last = createTreeArtifact("zzzzzzzzzz");
    FileSystemUtils.createDirectoryAndParents(last.getPath());
    Action action1 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out1));
    Action action2 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out2));
    Action actionEmpty = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(outEmpty));
    Action actionUnchanging = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(outUnchanging));
    Action lastAction = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(last));
    differencer.inject(ImmutableMap.<SkyKey, SkyValue>of(ActionExecutionValue.key(action1), actionValueWithTreeArtifacts(ImmutableList.of(file11)), ActionExecutionValue.key(action2), actionValueWithTreeArtifacts(ImmutableList.of(file21, file22)), ActionExecutionValue.key(actionEmpty), actionValueWithEmptyDirectory(outEmpty), ActionExecutionValue.key(actionUnchanging), actionValueWithEmptyDirectory(outUnchanging), ActionExecutionValue.key(lastAction), actionValueWithEmptyDirectory(last)));
    assertFalse(driver.evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE).hasError());
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    // Touching the TreeArtifact directory should have no effect
    FileSystemUtils.touchFile(out1.getPath());
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    // Neither should touching a subdirectory.
    FileSystemUtils.touchFile(out2.getPath().getChild("subdir"));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    /* **** Tests for directories **** */
    // Removing a directory (even if empty) should have an effect
    outEmpty.getPath().delete();
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(outEmpty.getExecPath()).build())).containsExactly(ActionExecutionValue.key(actionEmpty));
    // Symbolic links should count as dirty
    Path dummyEmptyDir = fs.getPath("/bin").getRelative("symlink");
    FileSystemUtils.createDirectoryAndParents(dummyEmptyDir);
    FileSystemUtils.ensureSymbolicLink(outEmpty.getPath(), dummyEmptyDir);
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(outEmpty.getExecPath()).build())).containsExactly(ActionExecutionValue.key(actionEmpty));
    // We're done fiddling with this... restore the original state
    outEmpty.getPath().delete();
    FileSystemUtils.deleteTree(dummyEmptyDir);
    FileSystemUtils.createDirectoryAndParents(outEmpty.getPath());
    /* **** Tests for files and directory contents ****/
    // Test that file contents matter. This is covered by existing tests already,
    // so it's just a sanity check.
    FileSystemUtils.writeContentAsLatin1(file11.getPath(), "goodbye");
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file11.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1));
    // Test that directory contents (and nested contents) matter
    Artifact out1new = treeFileArtifact(out1, "julius/caesar");
    FileSystemUtils.createDirectoryAndParents(out1.getPath().getChild("julius"));
    FileSystemUtils.writeContentAsLatin1(out1new.getPath(), "octavian");
    // even for empty directories
    Artifact outEmptyNew = treeFileArtifact(outEmpty, "marcus");
    FileSystemUtils.writeContentAsLatin1(outEmptyNew.getPath(), "aurelius");
    // so does removing
    file21.getPath().delete();
    // now, let's test our changes are actually visible
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).modify(outEmptyNew.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
    // We also check that if the modified file set does not contain our modified files on disk,
    // we are not going to check and return them.
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(outEmptyNew.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2));
    // Check modifying the last (lexicographically) tree artifact.
    last.getPath().delete();
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).modify(last.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2), ActionExecutionValue.key(lastAction));
    // Check ModifiedFileSet without the last (lexicographically) tree artifact.
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2));
    // Restore
    last.getPath().delete();
    FileSystemUtils.createDirectoryAndParents(last.getPath());
    // We add a test for NOTHING_MODIFIED, because FileSystemValueChecker doesn't
    // pay attention to file sets for TreeArtifact directory listings.
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.NOTHING_MODIFIED)).isEmpty();
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) ExternalFileAction(com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) 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) TestAction(com.google.devtools.build.lib.actions.util.TestAction)

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