use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class GlobFunctionTest method testResilienceToFilesystemInconsistencies_SubdirectoryExistence.
@Test
public void testResilienceToFilesystemInconsistencies_SubdirectoryExistence() throws Exception {
// Our custom filesystem says directory "pkgPath/foo/bar" contains a subdirectory "wiz" but a
// direct stat on "pkgPath/foo/bar/wiz" says it does not exist.
Path fooBarDir = pkgPath.getRelative("foo/bar");
fs.stubStat(fooBarDir.getRelative("wiz"), null);
RootedPath fooBarDirRootedPath = RootedPath.toRootedPath(root, fooBarDir);
SkyValue fooBarDirListingValue = DirectoryListingStateValue.create(ImmutableList.of(new Dirent("wiz", Dirent.Type.DIRECTORY)));
differencer.inject(ImmutableMap.of(DirectoryListingStateValue.key(fooBarDirRootedPath), fooBarDirListingValue));
String expectedMessage = "/root/workspace/pkg/foo/bar/wiz is no longer an existing directory.";
SkyKey skyKey = GlobValue.key(PKG_ID, root, "**/wiz", false, PathFragment.EMPTY_FRAGMENT);
EvaluationResult<GlobValue> result = driver.evaluate(ImmutableList.of(skyKey), false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class);
assertThat(errorInfo.getException().getMessage()).contains(expectedMessage);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class GlobFunctionTest method testResilienceToFilesystemInconsistencies_DirectoryExistence.
/** Regression test for b/13319874: Directory listing crash. */
@Test
public void testResilienceToFilesystemInconsistencies_DirectoryExistence() throws Exception {
// Our custom filesystem says "pkgPath/BUILD" exists but "pkgPath" does not exist.
fs.stubStat(pkgPath, null);
RootedPath pkgRootedPath = RootedPath.toRootedPath(root, pkgPath);
FileStateValue pkgDirFileStateValue = FileStateValue.create(pkgRootedPath, null);
FileValue pkgDirValue = FileValue.value(pkgRootedPath, pkgDirFileStateValue, pkgRootedPath, pkgDirFileStateValue);
differencer.inject(ImmutableMap.of(FileValue.key(pkgRootedPath), pkgDirValue));
String expectedMessage = "/root/workspace/pkg is no longer an existing directory";
SkyKey skyKey = GlobValue.key(PKG_ID, root, "*/foo", false, PathFragment.EMPTY_FRAGMENT);
EvaluationResult<GlobValue> result = driver.evaluate(ImmutableList.of(skyKey), false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class);
assertThat(errorInfo.getException().getMessage()).contains(expectedMessage);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class GlobFunctionTest method testResilienceToFilesystemInconsistencies_SymlinkType.
@Test
public void testResilienceToFilesystemInconsistencies_SymlinkType() throws Exception {
RootedPath wizRootedPath = RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz"));
RootedPath fileRootedPath = RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz/file"));
final FileStatus realStat = fileRootedPath.asPath().stat();
fs.stubStat(fileRootedPath.asPath(), new FileStatus() {
@Override
public boolean isFile() {
// The stat says foo/bar/wiz/file is a real file, not a symlink.
return true;
}
@Override
public boolean isSpecialFile() {
return false;
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isSymbolicLink() {
return false;
}
@Override
public long getSize() throws IOException {
return realStat.getSize();
}
@Override
public long getLastModifiedTime() throws IOException {
return realStat.getLastModifiedTime();
}
@Override
public long getLastChangeTime() throws IOException {
return realStat.getLastChangeTime();
}
@Override
public long getNodeId() throws IOException {
return realStat.getNodeId();
}
});
// But the dir listing say foo/bar/wiz/file is a symlink.
SkyValue wizDirListingValue = DirectoryListingStateValue.create(ImmutableList.of(new Dirent("file", Dirent.Type.SYMLINK)));
differencer.inject(ImmutableMap.of(DirectoryListingStateValue.key(wizRootedPath), wizDirListingValue));
String expectedMessage = "readdir and stat disagree about whether " + fileRootedPath.asPath() + " is a symlink";
SkyKey skyKey = GlobValue.key(PKG_ID, root, "foo/bar/wiz/*", false, PathFragment.EMPTY_FRAGMENT);
EvaluationResult<GlobValue> result = driver.evaluate(ImmutableList.of(skyKey), false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class);
assertThat(errorInfo.getException().getMessage()).contains(expectedMessage);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class PrepareDepsOfTargetsUnderDirectoryFunctionTest method testExcludedSubdirectoryGettingPassedDown.
@Test
public void testExcludedSubdirectoryGettingPassedDown() throws Exception {
// Given a package "a", and a package below it in "a/b/c", and a non-BUILD file below it in
// "a/b/d",
scratch.file("a/BUILD");
scratch.file("a/b/c/BUILD");
scratch.file("a/b/d/helloworld");
// When the top package is evaluated for recursive package values, and "a/b/c" is excluded,
ImmutableSet<PathFragment> excludedPaths = ImmutableSet.of(new PathFragment("a/b/c"));
SkyKey key = createPrepDepsKey(rootDirectory, new PathFragment("a"), excludedPaths);
SkyKey collectKey = createCollectPackagesKey(rootDirectory, new PathFragment("a"), excludedPaths);
EvaluationResult<?> evaluationResult = getEvaluationResult(key, collectKey);
CollectPackagesUnderDirectoryValue value = (CollectPackagesUnderDirectoryValue) evaluationResult.getWalkableGraph().getValue(createCollectPackagesKey(rootDirectory, new PathFragment("a"), excludedPaths));
// Then the value reports that "a" is a package,
assertThat(value.isDirectoryPackage()).isTrue();
// And the subdirectory corresponding to "a/b" is present in the result,
RootedPath onlySubdir = Iterables.getOnlyElement(value.getSubdirectoryTransitivelyContainsPackagesOrErrors().keySet());
assertThat(onlySubdir.getRelativePath()).isEqualTo(new PathFragment("a/b"));
// And the "a/b" subdirectory does not report a package under it (because it got excluded).
assertThat(value.getSubdirectoryTransitivelyContainsPackagesOrErrors().get(onlySubdir)).isFalse();
// Also, the computation graph contains a cached value for "a/b" with "a/b/c" excluded, because
// "a/b/c" does live underneath "a/b".
WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
SkyKey abKey = createCollectPackagesKey(rootDirectory, new PathFragment("a/b"), excludedPaths);
assertThat(exists(abKey, graph)).isTrue();
CollectPackagesUnderDirectoryValue abValue = (CollectPackagesUnderDirectoryValue) Preconditions.checkNotNull(graph.getValue(abKey));
// And that value says that "a/b" is not a package,
assertThat(abValue.isDirectoryPackage()).isFalse();
// And only the subdirectory "a/b/d" is present in that value,
RootedPath abd = Iterables.getOnlyElement(abValue.getSubdirectoryTransitivelyContainsPackagesOrErrors().keySet());
assertThat(abd.getRelativePath()).isEqualTo(new PathFragment("a/b/d"));
// And no package is under "a/b/d".
assertThat(abValue.getSubdirectoryTransitivelyContainsPackagesOrErrors().get(abd)).isFalse();
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testRegexp.
@Test
public void testRegexp() throws Exception {
Artifact wantedArtifact = sourceArtifact("foo/bar/baz.txt");
Artifact unwantedArtifact = sourceArtifact("foo/boo/baztxt.bak");
RootedPath wantedPath = rootedPath(wantedArtifact);
createFile(wantedPath, "hello");
createFile(unwantedArtifact, "nope");
Artifact pkgDirArtifact = sourceArtifact("foo");
RootedPath dir = rootedPath(pkgDirArtifact);
scratch.dir(dir.asPath().getPathString());
TraversalRequest traversalRoot = new TraversalRequest(dir, false, PackageBoundaryMode.REPORT_ERROR, true, null, Pattern.compile(".*\\.txt"));
ResolvedFile expected = regularFileForTesting(wantedPath);
traverseAndAssertFiles(traversalRoot, expected);
}
Aggregations