Search in sources :

Example 11 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class TimestampBuilderTest method testMissingSourceFileIsAnError.

@Test
public void testMissingSourceFileIsAnError() throws Exception {
    // A missing input to an action must be treated as an error because there's
    // a risk that the action that consumes it will succeed, but with a
    // different behavior (imagine that it globs over the directory, for
    // example).  It's not ok to simply try the action and let the action
    // report "input file not found".
    //
    // (However, there are exceptions to this principle: C++ compilation
    // actions may depend on non-existent headers from stale .d files.  We need
    // to allow the action to proceed to execution in this case.)
    reporter.removeHandler(failFastHandler);
    // doesn't exist
    Artifact in = createSourceArtifact("in");
    Artifact out = createDerivedArtifact("out");
    registerAction(new TestAction(TestAction.NO_EFFECT, Collections.singleton(in), Collections.singleton(out)));
    try {
        // fails with ActionExecutionException
        buildArtifacts(amnesiacBuilder(), out);
        fail();
    } catch (BuildFailedException e) {
        assertThat(e.getMessage()).contains("1 input file(s) do not exist");
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 12 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class TimestampBuilderTestCase method createActionButton.

/**
   * Creates a TestAction from 'inputs' to 'outputs', and a new button, such
   * that executing the action causes the button to be pressed.  The button is
   * returned.
   */
protected Button createActionButton(Collection<Artifact> inputs, Collection<Artifact> outputs) {
    Button button = new Button();
    registerAction(new TestAction(button, inputs, outputs));
    return button;
}
Also used : TestAction(com.google.devtools.build.lib.actions.util.TestAction)

Example 13 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class FilesystemValueCheckerTest method checkDirtyActions.

public void checkDirtyActions(BatchStat batchStatter, boolean forceDigests) throws Exception {
    Artifact out1 = createDerivedArtifact("fiz");
    Artifact out2 = createDerivedArtifact("pop");
    FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hello");
    FileSystemUtils.writeContentAsLatin1(out2.getPath(), "fizzlepop");
    Action action1 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out1));
    Action action2 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out2));
    differencer.inject(ImmutableMap.<SkyKey, SkyValue>of(ActionExecutionValue.key(action1), actionValue(action1, forceDigests), ActionExecutionValue.key(action2), actionValue(action2, forceDigests)));
    assertFalse(driver.evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE).hasError());
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
    FileSystemUtils.writeContentAsLatin1(out1.getPath(), "goodbye");
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).containsExactly(ActionExecutionValue.key(action1));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(out1.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1));
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(out1.getExecPath().getParentDirectory()).build())).isEmpty();
    assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.NOTHING_MODIFIED)).isEmpty();
}
Also used : 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 14 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class ParallelBuilderTest method testFailureRecovery.

/**
   * Test that we can recover properly after a failed build.
   */
@Test
public void testFailureRecovery() throws Exception {
    // [action] -> foo
    Artifact foo = createDerivedArtifact("foo");
    Callable<Void> makeFoo = new Callable<Void>() {

        @Override
        public Void call() throws IOException {
            throw new IOException("building 'foo' is supposed to fail");
        }
    };
    registerAction(new TestAction(makeFoo, Artifact.NO_ARTIFACTS, ImmutableList.of(foo)));
    // [action] -> bar
    Artifact bar = createDerivedArtifact("bar");
    registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(bar)));
    // Don't fail fast when we encounter the error
    reporter.removeHandler(failFastHandler);
    // test that building 'foo' fails
    try {
        buildArtifacts(foo);
        fail("building 'foo' was supposed to fail!");
    } catch (BuildFailedException e) {
        if (!e.getMessage().contains("building 'foo' is supposed to fail")) {
            throw e;
        }
        // Make sure the reporter reported the error message.
        assertContainsEvent("building 'foo' is supposed to fail");
    }
    // test that a subsequent build of 'bar' succeeds
    buildArtifacts(bar);
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) Callable(java.util.concurrent.Callable) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 15 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class ParallelBuilderTest method testCyclicActionGraphWithTail.

@Test
public void testCyclicActionGraphWithTail() throws Exception {
    // bar -> [action] -> foo
    // baz -> [action] -> bar
    // bat, foo -> [action] -> baz
    Artifact foo = createDerivedArtifact("foo");
    Artifact bar = createDerivedArtifact("bar");
    Artifact baz = createDerivedArtifact("baz");
    Artifact bat = createDerivedArtifact("bat");
    try {
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo)));
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(bar)));
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bat, foo), asSet(baz)));
        registerAction(new TestAction(TestAction.NO_EFFECT, ImmutableSet.<Artifact>of(), asSet(bat)));
        buildArtifacts(foo);
        fail("Builder failed to detect cyclic action graph");
    } catch (BuildFailedException e) {
        assertEquals(e.getMessage(), CYCLE_MSG);
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Aggregations

TestAction (com.google.devtools.build.lib.actions.util.TestAction)20 Artifact (com.google.devtools.build.lib.actions.Artifact)16 Test (org.junit.Test)14 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)10 IOException (java.io.IOException)5 Action (com.google.devtools.build.lib.actions.Action)4 Path (com.google.devtools.build.lib.vfs.Path)4 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 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)3 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)3 Callable (java.util.concurrent.Callable)3 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)2 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)2 ExternalFileAction (com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction)2 ModifiedFileSet (com.google.devtools.build.lib.vfs.ModifiedFileSet)2 EventBus (com.google.common.eventbus.EventBus)1 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1