Search in sources :

Example 66 with SkyValue

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

SkyValue (com.google.devtools.build.skyframe.SkyValue)66 SkyKey (com.google.devtools.build.skyframe.SkyKey)63 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)18 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)17 Test (org.junit.Test)16 Artifact (com.google.devtools.build.lib.actions.Artifact)15 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)15 HashMap (java.util.HashMap)14 ImmutableList (com.google.common.collect.ImmutableList)10 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)10 Path (com.google.devtools.build.lib.vfs.Path)9 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)8 LinkedHashMap (java.util.LinkedHashMap)8 Label (com.google.devtools.build.lib.cmdline.Label)7 HashSet (java.util.HashSet)7 Target (com.google.devtools.build.lib.packages.Target)6 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 IOException (java.io.IOException)5 ImmutableSet (com.google.common.collect.ImmutableSet)4