use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversalOfDanglingSymlinkInADirectory.
@Test
public void testTraversalOfDanglingSymlinkInADirectory() throws Exception {
Artifact dirArtifact = sourceArtifact("a");
RootedPath file = createFile(childOf(dirArtifact, "file.txt"));
RootedPath link = rootedPath(sourceArtifact("a/dangling.sym"));
PathFragment linkTarget = new PathFragment("non_existent");
parentOf(link).asPath().createDirectory();
link.asPath().createSymbolicLink(linkTarget);
traverseAndAssertFiles(fileLikeRoot(dirArtifact, DONT_CROSS), regularFileForTesting(file), danglingSymlinkForTesting(link, linkTarget));
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method assertTraversalOfDirectory.
private void assertTraversalOfDirectory(Artifact directoryArtifact) throws Exception {
// Create files under the directory.
// Use the root + root-relative path of the rootArtifact to create these files, rather than
// using the rootDirectory + execpath of the rootArtifact. The resulting paths are the same
// but the RootedPaths are different:
// in the 1st case, it is: RootedPath(/root/execroot, relative), in the second it is
// in the 2nd case, it is: RootedPath(/root, execroot/relative).
// Creating the files will also create the parent directories.
RootedPath file1 = createFile(childOf(directoryArtifact, "bar.txt"));
RootedPath file2 = createFile(childOf(directoryArtifact, "baz/qux.txt"));
TraversalRequest traversalRoot = fileLikeRoot(directoryArtifact, DONT_CROSS);
// Assert that the SkyValue is built and looks right.
ResolvedFile expected1 = regularFileForTesting(file1);
ResolvedFile expected2 = regularFileForTesting(file2);
RecursiveFilesystemTraversalValue v1 = traverseAndAssertFiles(traversalRoot, expected1, expected2);
assertThat(progressReceiver.invalidations).isEmpty();
assertThat(progressReceiver.evaluations).contains(v1);
progressReceiver.clear();
// Add a new file to the directory and see that the value is rebuilt.
RootedPath file3 = createFile(childOf(directoryArtifact, "foo.txt"));
invalidateDirectory(directoryArtifact);
ResolvedFile expected3 = regularFileForTesting(file3);
RecursiveFilesystemTraversalValue v2 = traverseAndAssertFiles(traversalRoot, expected1, expected2, expected3);
assertThat(progressReceiver.invalidations).contains(rftvSkyKey(traversalRoot));
assertThat(progressReceiver.evaluations).contains(v2);
// Directories always have the same hash code, but that is fine because their contents are also
// part of the RecursiveFilesystemTraversalValue, so v1 and v2 are unequal.
assertThat(v2).isNotEqualTo(v1);
assertTraversalRootHashesAreEqual(v1, v2);
progressReceiver.clear();
// Edit a file in the directory and see that the value is rebuilt.
appendToFile(file1, "bar");
RecursiveFilesystemTraversalValue v3 = traverseAndAssertFiles(traversalRoot, expected1, expected2, expected3);
assertThat(progressReceiver.invalidations).contains(rftvSkyKey(traversalRoot));
assertThat(progressReceiver.evaluations).contains(v3);
assertThat(v3).isNotEqualTo(v2);
// Directories always have the same hash code, but that is fine because their contents are also
// part of the RecursiveFilesystemTraversalValue, so v2 and v3 are unequal.
assertTraversalRootHashesAreEqual(v2, v3);
progressReceiver.clear();
// Add a new file *outside* of the directory and see that the value is *not* rebuilt.
Artifact someFile = sourceArtifact("somewhere/else/a.file");
createFile(someFile, "new file");
appendToFile(someFile, "not all changes are treated equal");
RecursiveFilesystemTraversalValue v4 = traverseAndAssertFiles(traversalRoot, expected1, expected2, expected3);
assertThat(v4).isEqualTo(v3);
assertTraversalRootHashesAreEqual(v3, v4);
assertThat(progressReceiver.invalidations).doesNotContain(rftvSkyKey(traversalRoot));
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class TimestampBuilderMediumTest method testOldCacheKeysAreCleanedUp.
@Test
public void testOldCacheKeysAreCleanedUp() throws Exception {
// [action1] -> (/goodbye), cache key will be /goodbye
Artifact goodbye = createDerivedArtifact("goodbye");
FileSystemUtils.createDirectoryAndParents(goodbye.getPath().getParentDirectory());
FileSystemUtils.writeContentAsLatin1(goodbye.getPath(), "test");
Button button = createActionButton(emptySet, Sets.newLinkedHashSet(ImmutableList.of(goodbye)));
button.pressed = false;
buildArtifacts(persistentBuilder(cache), goodbye);
// built
assertTrue(button.pressed);
// action1 is cached using the cache key /goodbye.
assertThat(cache.get(goodbye.getExecPathString())).isNotNull();
// [action2] -> (/hello,/goodbye), cache key will be /hello
clearActions();
Artifact hello = createDerivedArtifact("hello");
Artifact goodbye2 = createDerivedArtifact("goodbye");
Button button2 = createActionButton(emptySet, Sets.newLinkedHashSet(ImmutableList.of(hello, goodbye2)));
button2.pressed = false;
buildArtifacts(persistentBuilder(cache), hello, goodbye2);
// rebuilt
assertTrue(button2.pressed);
// action2 is cached using the cache key /hello.
assertThat(cache.get(hello.getExecPathString())).isNotNull();
// Now, action1 should no longer be in the cache.
assertThat(cache.get(goodbye.getExecPathString())).isNull();
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class TimestampBuilderMediumTest method testPersistentCache_ModifyingOutputCausesActionReexecution.
@Test
public void testPersistentCache_ModifyingOutputCausesActionReexecution() 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);
// Creating a new persistent cache does not cause a rebuild
cache.save();
buildArtifacts(persistentBuilder(createCache()), hello);
// not rebuilt
assertFalse(button.pressed);
}
use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.
the class TimestampBuilderMediumTest method testArtifactNamesMatter.
@Test
public void testArtifactNamesMatter() throws Exception {
// /hello -> [action] -> /goodbye
Artifact hello = createSourceArtifact("hello");
FileSystemUtils.createDirectoryAndParents(hello.getPath().getParentDirectory());
FileSystemUtils.writeContentAsLatin1(hello.getPath(), "hello");
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);
// Now create duplicate graph, replacing "hello" with "hi".
clearActions();
Artifact hi = createSourceArtifact("hi");
FileSystemUtils.createDirectoryAndParents(hi.getPath().getParentDirectory());
FileSystemUtils.writeContentAsLatin1(hi.getPath(), "hello");
Artifact goodbye2 = createDerivedArtifact("goodbye");
Button button2 = createActionButton(Sets.newHashSet(hi), Sets.newHashSet(goodbye2));
button2.pressed = false;
buildArtifacts(persistentBuilder(cache), goodbye2);
// name changed. must rebuild.
assertTrue(button2.pressed);
}
Aggregations