Search in sources :

Example 66 with RootedPath

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);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) SkyValue(com.google.devtools.build.skyframe.SkyValue) SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Dirent(com.google.devtools.build.lib.vfs.Dirent) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Example 67 with RootedPath

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);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Example 68 with RootedPath

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);
}
Also used : SkyValue(com.google.devtools.build.skyframe.SkyValue) SkyKey(com.google.devtools.build.skyframe.SkyKey) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Dirent(com.google.devtools.build.lib.vfs.Dirent) IOException(java.io.IOException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Example 69 with RootedPath

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();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Example 70 with RootedPath

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);
}
Also used : TraversalRequest(com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest) ResolvedFile(com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile) Artifact(com.google.devtools.build.lib.actions.Artifact) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Aggregations

RootedPath (com.google.devtools.build.lib.vfs.RootedPath)84 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)43 SkyKey (com.google.devtools.build.skyframe.SkyKey)41 Test (org.junit.Test)33 Path (com.google.devtools.build.lib.vfs.Path)28 Artifact (com.google.devtools.build.lib.actions.Artifact)21 IOException (java.io.IOException)15 Package (com.google.devtools.build.lib.packages.Package)13 SkyValue (com.google.devtools.build.skyframe.SkyValue)11 TraversalRequest (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest)9 ResolvedFile (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile)8 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)7 EvalException (com.google.devtools.build.lib.syntax.EvalException)7 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)7 Dirent (com.google.devtools.build.lib.vfs.Dirent)6 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)5 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)5 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 FileValue (com.google.devtools.build.lib.skyframe.FileValue)5 Map (java.util.Map)5