Search in sources :

Example 6 with ModifiedFileSet

use of com.google.devtools.build.lib.vfs.ModifiedFileSet in project bazel by bazelbuild.

the class SequencedSkyframeExecutor method handleDiffsWithCompleteDiffInformation.

/**
   * Invalidates files under path entries whose corresponding {@link DiffAwareness} gave an exact
   * diff. Removes entries from the given map as they are processed. All of the files need to be
   * invalidated, so the map should be empty upon completion of this function.
   */
private void handleDiffsWithCompleteDiffInformation(TimestampGranularityMonitor tsgm, Map<Path, DiffAwarenessManager.ProcessableModifiedFileSet> modifiedFilesByPathEntry) throws InterruptedException {
    for (Path pathEntry : ImmutableSet.copyOf(modifiedFilesByPathEntry.keySet())) {
        DiffAwarenessManager.ProcessableModifiedFileSet processableModifiedFileSet = modifiedFilesByPathEntry.get(pathEntry);
        ModifiedFileSet modifiedFileSet = processableModifiedFileSet.getModifiedFileSet();
        Preconditions.checkState(!modifiedFileSet.treatEverythingAsModified(), pathEntry);
        handleChangedFiles(ImmutableList.of(pathEntry), getDiff(tsgm, modifiedFileSet.modifiedSourceFiles(), pathEntry));
        processableModifiedFileSet.markProcessed();
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet)

Example 7 with ModifiedFileSet

use of com.google.devtools.build.lib.vfs.ModifiedFileSet in project bazel by bazelbuild.

the class FilesystemValueCheckerTest method checkDirtyTreeArtifactActions.

public void checkDirtyTreeArtifactActions(BatchStat batchStatter) throws Exception {
    // Normally, an Action specifies the contents of a TreeArtifact when it executes.
    // To decouple FileSystemValueTester checking from Action execution, we inject TreeArtifact
    // contents into ActionExecutionValues.
    Artifact out1 = createTreeArtifact("one");
    TreeFileArtifact file11 = treeFileArtifact(out1, "fizz");
    FileSystemUtils.createDirectoryAndParents(out1.getPath());
    FileSystemUtils.writeContentAsLatin1(file11.getPath(), "buzz");
    Artifact out2 = createTreeArtifact("two");
    FileSystemUtils.createDirectoryAndParents(out2.getPath().getChild("subdir"));
    TreeFileArtifact file21 = treeFileArtifact(out2, "moony");
    TreeFileArtifact file22 = treeFileArtifact(out2, "subdir/wormtail");
    FileSystemUtils.writeContentAsLatin1(file21.getPath(), "padfoot");
    FileSystemUtils.writeContentAsLatin1(file22.getPath(), "prongs");
    Artifact outEmpty = createTreeArtifact("empty");
    FileSystemUtils.createDirectoryAndParents(outEmpty.getPath());
    Artifact outUnchanging = createTreeArtifact("untouched");
    FileSystemUtils.createDirectoryAndParents(outUnchanging.getPath());
    Artifact last = createTreeArtifact("zzzzzzzzzz");
    FileSystemUtils.createDirectoryAndParents(last.getPath());
    Action action1 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out1));
    Action action2 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out2));
    Action actionEmpty = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(outEmpty));
    Action actionUnchanging = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(outUnchanging));
    Action lastAction = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(last));
    differencer.inject(ImmutableMap.<SkyKey, SkyValue>of(ActionExecutionValue.key(action1), actionValueWithTreeArtifacts(ImmutableList.of(file11)), ActionExecutionValue.key(action2), actionValueWithTreeArtifacts(ImmutableList.of(file21, file22)), ActionExecutionValue.key(actionEmpty), actionValueWithEmptyDirectory(outEmpty), ActionExecutionValue.key(actionUnchanging), actionValueWithEmptyDirectory(outUnchanging), ActionExecutionValue.key(lastAction), actionValueWithEmptyDirectory(last)));
    assertFalse(driver.evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE).hasError());
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    // Touching the TreeArtifact directory should have no effect
    FileSystemUtils.touchFile(out1.getPath());
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    // Neither should touching a subdirectory.
    FileSystemUtils.touchFile(out2.getPath().getChild("subdir"));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    /* **** Tests for directories **** */
    // Removing a directory (even if empty) should have an effect
    outEmpty.getPath().delete();
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(outEmpty.getExecPath()).build())).containsExactly(ActionExecutionValue.key(actionEmpty));
    // Symbolic links should count as dirty
    Path dummyEmptyDir = fs.getPath("/bin").getRelative("symlink");
    FileSystemUtils.createDirectoryAndParents(dummyEmptyDir);
    FileSystemUtils.ensureSymbolicLink(outEmpty.getPath(), dummyEmptyDir);
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(outEmpty.getExecPath()).build())).containsExactly(ActionExecutionValue.key(actionEmpty));
    // We're done fiddling with this... restore the original state
    outEmpty.getPath().delete();
    FileSystemUtils.deleteTree(dummyEmptyDir);
    FileSystemUtils.createDirectoryAndParents(outEmpty.getPath());
    /* **** Tests for files and directory contents ****/
    // Test that file contents matter. This is covered by existing tests already,
    // so it's just a sanity check.
    FileSystemUtils.writeContentAsLatin1(file11.getPath(), "goodbye");
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file11.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1));
    // Test that directory contents (and nested contents) matter
    Artifact out1new = treeFileArtifact(out1, "julius/caesar");
    FileSystemUtils.createDirectoryAndParents(out1.getPath().getChild("julius"));
    FileSystemUtils.writeContentAsLatin1(out1new.getPath(), "octavian");
    // even for empty directories
    Artifact outEmptyNew = treeFileArtifact(outEmpty, "marcus");
    FileSystemUtils.writeContentAsLatin1(outEmptyNew.getPath(), "aurelius");
    // so does removing
    file21.getPath().delete();
    // now, let's test our changes are actually visible
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).modify(outEmptyNew.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
    // We also check that if the modified file set does not contain our modified files on disk,
    // we are not going to check and return them.
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(outEmptyNew.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2));
    // Check modifying the last (lexicographically) tree artifact.
    last.getPath().delete();
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).modify(last.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2), ActionExecutionValue.key(lastAction));
    // Check ModifiedFileSet without the last (lexicographically) tree artifact.
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(file21.getExecPath()).modify(out1new.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2));
    // Restore
    last.getPath().delete();
    FileSystemUtils.createDirectoryAndParents(last.getPath());
    // We add a test for NOTHING_MODIFIED, because FileSystemValueChecker doesn't
    // pay attention to file sets for TreeArtifact directory listings.
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.NOTHING_MODIFIED)).isEmpty();
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) ExternalFileAction(com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction)

Example 8 with ModifiedFileSet

use of com.google.devtools.build.lib.vfs.ModifiedFileSet in project bazel by bazelbuild.

the class DiffAwarenessManagerTest method testResetAndSetPathEntriesCallClose.

@Test
public void testResetAndSetPathEntriesCallClose() throws Exception {
    Path pathEntry = root.getRelative("pathEntry");
    ModifiedFileSet diff = ModifiedFileSet.NOTHING_MODIFIED;
    DiffAwarenessStub diffAwareness1 = new DiffAwarenessStub(ImmutableList.of(diff));
    DiffAwarenessStub diffAwareness2 = new DiffAwarenessStub(ImmutableList.of(diff));
    DiffAwarenessFactoryStub factory = new DiffAwarenessFactoryStub();
    factory.inject(pathEntry, diffAwareness1);
    DiffAwarenessManager manager = new DiffAwarenessManager(ImmutableList.of(factory));
    manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertFalse("diffAwareness1 shouldn't have been closed yet", diffAwareness1.closed());
    manager.reset();
    assertTrue("diffAwareness1 should have been closed by reset", diffAwareness1.closed());
    factory.inject(pathEntry, diffAwareness2);
    manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertFalse("diffAwareness2 shouldn't have been closed yet", diffAwareness2.closed());
    events.assertNoWarningsOrErrors();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ProcessableModifiedFileSet(com.google.devtools.build.lib.skyframe.DiffAwarenessManager.ProcessableModifiedFileSet) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) Test(org.junit.Test)

Example 9 with ModifiedFileSet

use of com.google.devtools.build.lib.vfs.ModifiedFileSet in project bazel by bazelbuild.

the class DiffAwarenessManagerTest method testHandlesUnprocessedDiffs.

@Test
public void testHandlesUnprocessedDiffs() throws Exception {
    Path pathEntry = root.getRelative("pathEntry");
    ModifiedFileSet diff1 = ModifiedFileSet.builder().modify(new PathFragment("file1")).build();
    ModifiedFileSet diff2 = ModifiedFileSet.builder().modify(new PathFragment("file2")).build();
    ModifiedFileSet diff3 = ModifiedFileSet.builder().modify(new PathFragment("file3")).build();
    DiffAwarenessStub diffAwareness = new DiffAwarenessStub(ImmutableList.of(diff1, diff2, diff3, DiffAwarenessStub.BROKEN_DIFF));
    DiffAwarenessFactoryStub factory = new DiffAwarenessFactoryStub();
    factory.inject(pathEntry, diffAwareness);
    DiffAwarenessManager manager = new DiffAwarenessManager(ImmutableList.of(factory));
    ProcessableModifiedFileSet firstProcessableDiff = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertEquals("Expected EVERYTHING_MODIFIED on first call to getDiff", ModifiedFileSet.EVERYTHING_MODIFIED, firstProcessableDiff.getModifiedFileSet());
    firstProcessableDiff.markProcessed();
    ProcessableModifiedFileSet processableDiff1 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertEquals(diff1, processableDiff1.getModifiedFileSet());
    ProcessableModifiedFileSet processableDiff2 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertEquals(ModifiedFileSet.union(diff1, diff2), processableDiff2.getModifiedFileSet());
    processableDiff2.markProcessed();
    ProcessableModifiedFileSet processableDiff3 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertEquals(diff3, processableDiff3.getModifiedFileSet());
    events.assertNoWarningsOrErrors();
    ProcessableModifiedFileSet processableDiff4 = manager.getDiff(events.reporter(), pathEntry, OptionsClassProvider.EMPTY);
    assertEquals(ModifiedFileSet.EVERYTHING_MODIFIED, processableDiff4.getModifiedFileSet());
    events.assertContainsWarning("error");
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ProcessableModifiedFileSet(com.google.devtools.build.lib.skyframe.DiffAwarenessManager.ProcessableModifiedFileSet) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ProcessableModifiedFileSet(com.google.devtools.build.lib.skyframe.DiffAwarenessManager.ProcessableModifiedFileSet) Test(org.junit.Test)

Example 10 with ModifiedFileSet

use of com.google.devtools.build.lib.vfs.ModifiedFileSet in project bazel by bazelbuild.

the class TargetPatternEvaluatorTest method testAddedFilesAndDotDotDot.

@Test
public void testAddedFilesAndDotDotDot() throws Exception {
    invalidate(ModifiedFileSet.EVERYTHING_MODIFIED);
    reporter.removeHandler(failFastHandler);
    scratch.dir("h");
    try {
        parseList("//h/...");
        fail("TargetParsingException expected");
    } catch (TargetParsingException e) {
    // expected
    }
    scratch.file("h/i/j/k/BUILD", "sh_library(name='l')");
    ModifiedFileSet modifiedFileSet = ModifiedFileSet.builder().modify(new PathFragment("h")).modify(new PathFragment("h/i")).modify(new PathFragment("h/i/j")).modify(new PathFragment("h/i/j/k")).modify(new PathFragment("h/i/j/k/BUILD")).build();
    invalidate(modifiedFileSet);
    reporter.addHandler(failFastHandler);
    Set<Label> nonEmptyResult = parseList("//h/...");
    assertThat(nonEmptyResult).containsExactly(Label.parseAbsolute("//h/i/j/k:l"));
}
Also used : TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Label(com.google.devtools.build.lib.cmdline.Label) Test(org.junit.Test)

Aggregations

ModifiedFileSet (com.google.devtools.build.lib.vfs.ModifiedFileSet)11 Test (org.junit.Test)7 Path (com.google.devtools.build.lib.vfs.Path)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 ProcessableModifiedFileSet (com.google.devtools.build.lib.skyframe.DiffAwarenessManager.ProcessableModifiedFileSet)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 Label (com.google.devtools.build.lib.cmdline.Label)2 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)2 Stopwatch (com.google.common.base.Stopwatch)1 Action (com.google.devtools.build.lib.actions.Action)1 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)1 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)1 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 TestExecException (com.google.devtools.build.lib.actions.TestExecException)1 ActionCache (com.google.devtools.build.lib.actions.cache.ActionCache)1 TestAction (com.google.devtools.build.lib.actions.util.TestAction)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1