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