Search in sources :

Example 21 with StoredEventHandler

use of com.google.devtools.build.lib.events.StoredEventHandler 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

StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)21 IOException (java.io.IOException)6 Test (org.junit.Test)6 ImmutableList (com.google.common.collect.ImmutableList)5 Artifact (com.google.devtools.build.lib.actions.Artifact)5 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)5 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)4 List (java.util.List)4 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)3 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)3 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 BuildFileAST (com.google.devtools.build.lib.syntax.BuildFileAST)3 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)3 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)3 Nullable (javax.annotation.Nullable)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CachingAnalysisEnvironment (com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment)2 Event (com.google.devtools.build.lib.events.Event)2