Search in sources :

Example 26 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class RecursiveFilesystemTraversalFunctionTest method testGeneratedDirectoryConflictsWithPackage.

@Test
public void testGeneratedDirectoryConflictsWithPackage() throws Exception {
    Artifact genDir = derivedArtifact("a/b");
    createFile(rootedPath(sourceArtifact("a/b/c/file.real")));
    createFile(rootedPath(derivedArtifact("a/b/c/file.fake")));
    createFile(sourceArtifact("a/b/c/BUILD"));
    SkyKey key = rftvSkyKey(fileLikeRoot(genDir, CROSS));
    EvaluationResult<SkyValue> result = eval(key);
    assertThat(result.hasError()).isTrue();
    ErrorInfo error = result.getError(key);
    assertThat(error.isTransient()).isFalse();
    assertThat(error.getException().getMessage()).contains("Generated directory a/b/c conflicts with package under the same path.");
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 27 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class FileFunctionTest method testFilesystemInconsistencies_GetFastDigest.

@Test
public void testFilesystemInconsistencies_GetFastDigest() throws Exception {
    file("a");
    // Our custom filesystem says "a/b" exists but "a" does not exist.
    fs.stubFastDigestError(path("a"), new IOException("nope"));
    SequentialBuildDriver driver = makeDriver();
    SkyKey skyKey = skyKey("a");
    EvaluationResult<FileValue> result = driver.evaluate(ImmutableList.of(skyKey), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
    assertTrue(result.hasError());
    ErrorInfo errorInfo = result.getError(skyKey);
    assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class);
    assertThat(errorInfo.getException().getMessage()).contains("encountered error 'nope'");
    assertThat(errorInfo.getException().getMessage()).contains("/root/a is no longer a file");
}
Also used : SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class ASTFileLookupFunctionTest method testIOExceptionOccursDuringReading.

@Test
public void testIOExceptionOccursDuringReading() throws Exception {
    reporter.removeHandler(failFastHandler);
    scratch.file("/workspace/tools/build_rules/BUILD");
    scratch.file("foo/BUILD", "genrule(name = 'foo',", "  outs = ['out.txt'],", "  cmd = 'echo hello >@')");
    mockFS.statThrowsIoException = true;
    // We don't want to fail early on config creation.
    invalidatePackages(/*alsoConfigs=*/
    false);
    SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
    EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
    false, reporter);
    assertTrue(result.hasError());
    ErrorInfo errorInfo = result.getError(skyKey);
    Throwable e = errorInfo.getException();
    assertEquals(skyKey, errorInfo.getRootCauseOfException());
    assertThat(e).isInstanceOf(NoSuchPackageException.class);
    assertThat(e.getMessage()).contains("bork");
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Test(org.junit.Test)

Example 29 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class FileFunctionTest method runTestInfiniteSymlinkExpansion.

private void runTestInfiniteSymlinkExpansion(boolean symlinkToAncestor, boolean absoluteSymlink) throws Exception {
    Path otherPath = path("other");
    RootedPath otherRootedPath = RootedPath.toRootedPath(pkgRoot, otherPath.relativeTo(pkgRoot));
    Path ancestorPath = path("a");
    RootedPath ancestorRootedPath = RootedPath.toRootedPath(pkgRoot, ancestorPath.relativeTo(pkgRoot));
    FileSystemUtils.ensureSymbolicLink(otherPath, ancestorPath);
    Path intermediatePath = path("inter");
    RootedPath intermediateRootedPath = RootedPath.toRootedPath(pkgRoot, intermediatePath.relativeTo(pkgRoot));
    Path descendantPath = path("a/b/c/d/e");
    RootedPath descendantRootedPath = RootedPath.toRootedPath(pkgRoot, descendantPath.relativeTo(pkgRoot));
    if (symlinkToAncestor) {
        FileSystemUtils.ensureSymbolicLink(descendantPath, intermediatePath);
        if (absoluteSymlink) {
            FileSystemUtils.ensureSymbolicLink(intermediatePath, ancestorPath);
        } else {
            FileSystemUtils.ensureSymbolicLink(intermediatePath, ancestorRootedPath.getRelativePath());
        }
    } else {
        FileSystemUtils.ensureSymbolicLink(ancestorPath, intermediatePath);
        if (absoluteSymlink) {
            FileSystemUtils.ensureSymbolicLink(intermediatePath, descendantPath);
        } else {
            FileSystemUtils.ensureSymbolicLink(intermediatePath, descendantRootedPath.getRelativePath());
        }
    }
    StoredEventHandler eventHandler = new StoredEventHandler();
    SequentialBuildDriver driver = makeDriver();
    SkyKey ancestorPathKey = FileValue.key(ancestorRootedPath);
    SkyKey descendantPathKey = FileValue.key(descendantRootedPath);
    SkyKey otherPathKey = FileValue.key(otherRootedPath);
    ImmutableList<SkyKey> keys;
    ImmutableList<SkyKey> errorKeys;
    ImmutableList<RootedPath> expectedChain;
    if (symlinkToAncestor) {
        keys = ImmutableList.of(descendantPathKey, otherPathKey);
        errorKeys = ImmutableList.of(descendantPathKey);
        expectedChain = ImmutableList.of(descendantRootedPath, intermediateRootedPath, ancestorRootedPath);
    } else {
        keys = ImmutableList.of(ancestorPathKey, otherPathKey);
        errorKeys = keys;
        expectedChain = ImmutableList.of(ancestorRootedPath, intermediateRootedPath, descendantRootedPath);
    }
    EvaluationResult<FileValue> result = driver.evaluate(keys, /*keepGoing=*/
    true, DEFAULT_THREAD_COUNT, eventHandler);
    assertTrue(result.hasError());
    for (SkyKey key : errorKeys) {
        ErrorInfo errorInfo = result.getError(key);
        // FileFunction detects infinite symlink expansion explicitly.
        assertThat(errorInfo.getCycleInfo()).isEmpty();
        FileSymlinkInfiniteExpansionException fsiee = (FileSymlinkInfiniteExpansionException) errorInfo.getException();
        assertThat(fsiee.getMessage()).contains("Infinite symlink expansion");
        assertThat(fsiee.getChain()).containsExactlyElementsIn(expectedChain).inOrder();
    }
    // Check that the unique symlink expansion error was reported exactly once.
    assertThat(eventHandler.getEvents()).hasSize(1);
    assertThat(Iterables.getOnlyElement(eventHandler.getEvents()).getMessage()).contains("infinite symlink expansion detected");
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) SkyKey(com.google.devtools.build.skyframe.SkyKey) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 30 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class FileFunctionTest method runTestSymlinkCycle.

private void runTestSymlinkCycle(boolean ancestorCycle, boolean startInCycle) throws Exception {
    symlink("a", "b");
    symlink("b", "c");
    symlink("c", "d");
    symlink("d", "e");
    symlink("e", "c");
    // We build multiple keys at once to make sure the cycle is reported exactly once.
    Map<RootedPath, ImmutableList<RootedPath>> startToCycleMap = ImmutableMap.<RootedPath, ImmutableList<RootedPath>>builder().put(rootedPath("a"), ImmutableList.of(rootedPath("c"), rootedPath("d"), rootedPath("e"))).put(rootedPath("b"), ImmutableList.of(rootedPath("c"), rootedPath("d"), rootedPath("e"))).put(rootedPath("d"), ImmutableList.<RootedPath>of(rootedPath("d"), rootedPath("e"), rootedPath("c"))).put(rootedPath("e"), ImmutableList.<RootedPath>of(rootedPath("e"), rootedPath("c"), rootedPath("d"))).put(rootedPath("a/some/descendant"), ImmutableList.of(rootedPath("c"), rootedPath("d"), rootedPath("e"))).put(rootedPath("b/some/descendant"), ImmutableList.of(rootedPath("c"), rootedPath("d"), rootedPath("e"))).put(rootedPath("d/some/descendant"), ImmutableList.<RootedPath>of(rootedPath("d"), rootedPath("e"), rootedPath("c"))).put(rootedPath("e/some/descendant"), ImmutableList.<RootedPath>of(rootedPath("e"), rootedPath("c"), rootedPath("d"))).build();
    Map<RootedPath, ImmutableList<RootedPath>> startToPathToCycleMap = ImmutableMap.<RootedPath, ImmutableList<RootedPath>>builder().put(rootedPath("a"), ImmutableList.of(rootedPath("a"), rootedPath("b"))).put(rootedPath("b"), ImmutableList.of(rootedPath("b"))).put(rootedPath("d"), ImmutableList.<RootedPath>of()).put(rootedPath("e"), ImmutableList.<RootedPath>of()).put(rootedPath("a/some/descendant"), ImmutableList.of(rootedPath("a"), rootedPath("b"))).put(rootedPath("b/some/descendant"), ImmutableList.of(rootedPath("b"))).put(rootedPath("d/some/descendant"), ImmutableList.<RootedPath>of()).put(rootedPath("e/some/descendant"), ImmutableList.<RootedPath>of()).build();
    ImmutableList<SkyKey> keys;
    if (ancestorCycle && startInCycle) {
        keys = ImmutableList.of(skyKey("d/some/descendant"), skyKey("e/some/descendant"));
    } else if (ancestorCycle && !startInCycle) {
        keys = ImmutableList.of(skyKey("a/some/descendant"), skyKey("b/some/descendant"));
    } else if (!ancestorCycle && startInCycle) {
        keys = ImmutableList.of(skyKey("d"), skyKey("e"));
    } else {
        keys = ImmutableList.of(skyKey("a"), skyKey("b"));
    }
    StoredEventHandler eventHandler = new StoredEventHandler();
    SequentialBuildDriver driver = makeDriver();
    EvaluationResult<FileValue> result = driver.evaluate(keys, /*keepGoing=*/
    true, DEFAULT_THREAD_COUNT, eventHandler);
    assertTrue(result.hasError());
    for (SkyKey key : keys) {
        ErrorInfo errorInfo = result.getError(key);
        // FileFunction detects symlink cycles explicitly.
        assertThat(errorInfo.getCycleInfo()).isEmpty();
        FileSymlinkCycleException fsce = (FileSymlinkCycleException) errorInfo.getException();
        RootedPath start = (RootedPath) key.argument();
        assertThat(fsce.getPathToCycle()).containsExactlyElementsIn(startToPathToCycleMap.get(start)).inOrder();
        assertThat(fsce.getCycle()).containsExactlyElementsIn(startToCycleMap.get(start)).inOrder();
    }
    // Check that the unique cycle was reported exactly once.
    assertThat(eventHandler.getEvents()).hasSize(1);
    assertThat(Iterables.getOnlyElement(eventHandler.getEvents()).getMessage()).contains("circular symlinks detected");
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) ImmutableList(com.google.common.collect.ImmutableList) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Aggregations

ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)30 SkyKey (com.google.devtools.build.skyframe.SkyKey)29 Test (org.junit.Test)19 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)10 Path (com.google.devtools.build.lib.vfs.Path)9 SkyValue (com.google.devtools.build.skyframe.SkyValue)8 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)6 Map (java.util.Map)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Label (com.google.devtools.build.lib.cmdline.Label)4 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)3 Dirent (com.google.devtools.build.lib.vfs.Dirent)3 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)3 RecordingDifferencer (com.google.devtools.build.skyframe.RecordingDifferencer)3 IOException (java.io.IOException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Artifact (com.google.devtools.build.lib.actions.Artifact)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2