Search in sources :

Example 66 with Artifact

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

the class TimestampBuilderMediumTest method testModifyingInputCausesActionReexecution.

@Test
public void testModifyingInputCausesActionReexecution() throws Exception {
    // /hello -> [action] -> /goodbye
    Artifact hello = createSourceArtifact("hello");
    FileSystemUtils.createDirectoryAndParents(hello.getPath().getParentDirectory());
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content1");
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button = createActionButton(Sets.newHashSet(hello), Sets.newHashSet(goodbye));
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // still not rebuilt
    assertFalse(button.pressed);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content2");
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // rebuilt
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    // Creating a new persistent cache does not cause a rebuild
    cache.save();
    buildArtifacts(persistentBuilder(createCache()), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 67 with Artifact

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

the class TimestampBuilderMediumTest method testModifyingTimestampOnlyDoesNotCauseActionReexecution.

/**
   * Tests that changing timestamp of the input file without changing it content
   * does not cause action reexecution when metadata cache uses file digests in
   * addition to the timestamp.
   */
@Test
public void testModifyingTimestampOnlyDoesNotCauseActionReexecution() throws Exception {
    // /hello -> [action] -> /goodbye
    Artifact hello = createSourceArtifact("hello");
    FileSystemUtils.createDirectoryAndParents(hello.getPath().getParentDirectory());
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content1");
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button = createActionButton(Sets.newHashSet(hello), Sets.newHashSet(goodbye));
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    // Creating a new persistent caches, including metadata cache does not cause
    // a rebuild
    cache.save();
    Builder builder = persistentBuilder(createCache());
    buildArtifacts(builder, goodbye);
    // not rebuilt
    assertFalse(button.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 68 with Artifact

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

the class TimestampBuilderMediumTest method testPersistentCache_failedIntegrityCheckCausesActionReexecution.

@Test
public void testPersistentCache_failedIntegrityCheckCausesActionReexecution() throws Exception {
    // [action] -> /hello
    Artifact hello = createDerivedArtifact("hello");
    Button button = createActionButton(emptySet, Sets.newHashSet(hello));
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), hello);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), hello);
    // not rebuilt
    assertFalse(button.pressed);
    hello.getPath().setWritable(true);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content");
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), hello);
    // rebuilt
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), hello);
    // not rebuilt
    assertFalse(button.pressed);
    cache.save();
    // Get filename index path and store a copy of it.
    Path indexPath = Iterables.getOnlyElement(UnixGlob.forPath(cacheRoot).addPattern("filename_index*").globInterruptible());
    Path indexCopy = scratch.resolve("index_copy");
    FileSystemUtils.copyFile(indexPath, indexCopy);
    // Add extra records to the action cache and indexer.
    Artifact helloExtra = createDerivedArtifact("hello_extra");
    Button buttonExtra = createActionButton(emptySet, Sets.newHashSet(helloExtra));
    buildArtifacts(persistentBuilder(cache), helloExtra);
    // built
    assertTrue(buttonExtra.pressed);
    cache.save();
    assertTrue(indexPath.getFileSize() > indexCopy.getFileSize());
    // Validate current cache.
    buildArtifacts(persistentBuilder(createCache()), hello);
    // not rebuilt
    assertFalse(button.pressed);
    // Restore outdated file index.
    FileSystemUtils.copyFile(indexCopy, indexPath);
    // Second attempt will initialize empty cache, causing rebuild.
    try {
        createCache();
        fail("Expected IOException");
    } catch (IOException e) {
        assertThat(e.getMessage()).contains("Failed action cache referential integrity check");
    }
    // Validate cache with incorrect (out-of-date) filename index.
    buildArtifacts(persistentBuilder(createCache()), hello);
    // rebuilt due to the out-of-date index
    assertTrue(button.pressed);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 69 with Artifact

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

the class TimestampBuilderMediumTest method testDuplicateInputs.

@Test
public void testDuplicateInputs() throws Exception {
    // (/hello,/hello) -> [action] -> /goodbye
    Artifact hello = createSourceArtifact("hello");
    FileSystemUtils.createDirectoryAndParents(hello.getPath().getParentDirectory());
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "hello");
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button = createActionButton(Lists.<Artifact>newArrayList(hello, hello), Sets.newHashSet(goodbye));
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "hello2");
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // rebuilt
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    // Creating a new persistent cache does not cause a rebuild
    cache.save();
    buildArtifacts(persistentBuilder(createCache()), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 70 with Artifact

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

the class TimestampBuilderMediumTest method testArtifactOrderingDoesNotMatter.

@Test
public void testArtifactOrderingDoesNotMatter() throws Exception {
    // (/hello,/there) -> [action] -> /goodbye
    Artifact hello = createSourceArtifact("hello");
    Artifact there = createSourceArtifact("there");
    FileSystemUtils.createDirectoryAndParents(hello.getPath().getParentDirectory());
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "hello");
    FileSystemUtils.writeContentAsLatin1(there.getPath(), "there");
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button = createActionButton(Sets.newLinkedHashSet(ImmutableList.of(hello, there)), Sets.newHashSet(goodbye));
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    // Now create duplicate graph, with swapped order.
    clearActions();
    Artifact goodbye2 = createDerivedArtifact("goodbye");
    Button button2 = createActionButton(Sets.newLinkedHashSet(ImmutableList.of(there, hello)), Sets.newHashSet(goodbye2));
    button2.pressed = false;
    buildArtifacts(persistentBuilder(cache), goodbye);
    // still not rebuilt
    assertFalse(button2.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28