Search in sources :

Example 26 with SequentialBuildDriver

use of com.google.devtools.build.skyframe.SequentialBuildDriver 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)

Example 27 with SequentialBuildDriver

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

the class FileFunctionTest method testAbsoluteSymlinksToFilesOutsideRootWhenExternalAssumedNonExistentAndImmutable.

@Test
public void testAbsoluteSymlinksToFilesOutsideRootWhenExternalAssumedNonExistentAndImmutable() throws Exception {
    file("/outsideroot");
    symlink("a", "/outsideroot");
    SequentialBuildDriver driver = makeDriver(ExternalFileAction.ASSUME_NON_EXISTENT_AND_IMMUTABLE_FOR_EXTERNAL_PATHS);
    SkyKey key = skyKey("a");
    EvaluationResult<SkyValue> result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
    assertThatEvaluationResult(result).hasNoError();
    FileValue value = (FileValue) result.get(key);
    assertThat(value).isNotNull();
    assertFalse(value.exists());
}
Also used : SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Test(org.junit.Test)

Example 28 with SequentialBuildDriver

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

the class FileFunctionTest method assertChangesIfChanges.

/**
   * Asserts that if the contents of {@code changedPathString} changes, then the FileValue
   * corresponding to {@code pathString} will change. Returns the paths of all files seen. Not meant
   * to be called directly by tests.
   */
private Set<RootedPath> assertChangesIfChanges(String changedPathString, boolean isFile, boolean changes, String pathString) throws Exception {
    SequentialBuildDriver driver = makeDriver();
    SkyKey key = skyKey(pathString);
    EvaluationResult<SkyValue> result;
    result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
    if (result.hasError()) {
        fail(String.format("Evaluation error for %s: %s", key, result.getError()));
    }
    SkyValue oldValue = result.get(key);
    Pair<ImmutableList<String>, Runnable> changeResult = change(changedPathString, isFile);
    ImmutableList<String> changedPathStrings = changeResult.first;
    Runnable undoCallback = changeResult.second;
    differencer.invalidate(Iterables.transform(changedPathStrings, new Function<String, SkyKey>() {

        @Override
        public SkyKey apply(String input) {
            return fileStateSkyKey(input);
        }
    }));
    result = driver.evaluate(ImmutableList.of(key), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
    if (result.hasError()) {
        fail(String.format("Evaluation error for %s: %s", key, result.getError()));
    }
    SkyValue newValue = result.get(key);
    assertTrue(String.format("Changing the contents of %s %s should%s change the value for file %s.", isFile ? "file" : "directory", changedPathString, changes ? "" : " not", pathString), changes != newValue.equals(oldValue));
    // Restore the original file.
    undoCallback.run();
    return filesSeen(driver.getGraphForTesting());
}
Also used : SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Function(com.google.common.base.Function) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) HashFunction(com.google.devtools.build.lib.vfs.FileSystem.HashFunction) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)28 SkyKey (com.google.devtools.build.skyframe.SkyKey)18 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)11 InMemoryMemoizingEvaluator (com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator)11 RecordingDifferencer (com.google.devtools.build.skyframe.RecordingDifferencer)11 SkyFunction (com.google.devtools.build.skyframe.SkyFunction)10 SkyValue (com.google.devtools.build.skyframe.SkyValue)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Test (org.junit.Test)10 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)9 SkyFunctionName (com.google.devtools.build.skyframe.SkyFunctionName)9 Before (org.junit.Before)9 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)6 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)6 HashMap (java.util.HashMap)6 Path (com.google.devtools.build.lib.vfs.Path)5 ImmutableSet (com.google.common.collect.ImmutableSet)3 AnalysisMock (com.google.devtools.build.lib.analysis.util.AnalysisMock)3 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)3 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)3