Search in sources :

Example 1 with BuildFailedException

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

the class TreeArtifactBuildTest method testOneExpandedActionThrowsInActionTemplate.

@Test
public void testOneExpandedActionThrowsInActionTemplate() throws Throwable {
    // expect errors
    reporter.removeHandler(failFastHandler);
    // artifact1 is a tree artifact generated by a TouchingTestAction.
    Artifact artifact1 = createTreeArtifact("treeArtifact1");
    TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child1"));
    TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child2"));
    registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
    // artifact2 is a tree artifact generated by an action template.
    Artifact artifact2 = createTreeArtifact("treeArtifact2");
    SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
    registerAction(actionTemplate);
    // We mock out the action template function to expand into two actions:
    // One Action that touches the output file.
    // The other action that just throws when executed.
    TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child1"));
    TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child2"));
    Action generateOutputAction = new DummyAction(ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1);
    Action throwingAction = new ThrowingDummyAction(ImmutableList.<Artifact>of(treeFileArtifactB), ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2));
    actionTemplateExpansionFunction = new DummyActionTemplateExpansionFunction(ImmutableMultimap.<ActionTemplate<?>, Action>of(actionTemplate, generateOutputAction, actionTemplate, throwingAction));
    try {
        buildArtifact(artifact2);
        fail("Expected BuildFailedException");
    } catch (BuildFailedException e) {
        assertThat(e.getMessage()).contains("Throwing dummy action");
    }
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) DummyAction(com.google.devtools.build.lib.actions.util.TestAction.DummyAction) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) DummyAction(com.google.devtools.build.lib.actions.util.TestAction.DummyAction) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) ActionTemplate(com.google.devtools.build.lib.analysis.actions.ActionTemplate) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) 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) Test(org.junit.Test)

Example 2 with BuildFailedException

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

the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.

@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
    // Failure expected
    StoredEventHandler storingEventHandler = new StoredEventHandler();
    reporter.removeHandler(failFastHandler);
    reporter.addHandler(storingEventHandler);
    final Artifact out = createTreeArtifact("output");
    TreeArtifactTestAction action = new TreeArtifactTestAction(out) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) {
            try {
                writeFile(out.getPath().getChild("one"), "one");
                writeFile(out.getPath().getChild("two"), "two");
                FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    try {
        buildArtifact(action.getSoleOutput());
        // Should have thrown
        fail();
    } catch (BuildFailedException e) {
        List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
        assertThat(errors).hasSize(2);
        assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
        assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
    }
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) 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) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with BuildFailedException

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

the class TreeArtifactBuildTest method testInputTreeArtifactCreationFailedInActionTemplate.

@Test
public void testInputTreeArtifactCreationFailedInActionTemplate() throws Throwable {
    // expect errors
    reporter.removeHandler(failFastHandler);
    // artifact1 is created by a action that throws.
    Artifact artifact1 = createTreeArtifact("treeArtifact1");
    registerAction(new ThrowingDummyAction(ImmutableList.<Artifact>of(), ImmutableList.of(artifact1)));
    // artifact2 is a tree artifact generated by an action template.
    Artifact artifact2 = createTreeArtifact("treeArtifact2");
    SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
    registerAction(actionTemplate);
    try {
        buildArtifact(artifact2);
        fail("Expected BuildFailedException");
    } catch (BuildFailedException e) {
        assertThat(e.getMessage()).contains("Throwing dummy action");
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) 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) Test(org.junit.Test)

Example 4 with BuildFailedException

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

the class ParallelBuilderTest method testWaitsForSubprocesses.

// Regression test for bug fixed in CL 3548332: builder was not waiting for
// all its subprocesses to terminate.
@Test
public void testWaitsForSubprocesses() throws Exception {
    final Semaphore semaphore = new Semaphore(1);
    final boolean[] finished = { false };
    // t=0: semaphore acquired
    semaphore.acquireUninterruptibly();
    // This arrangement ensures that the "bar" action tries to run for about
    // 100ms after the "foo" action has completed (failed).
    // [action] -> foo
    Artifact foo = createDerivedArtifact("foo");
    Callable<Void> makeFoo = new Callable<Void>() {

        @Override
        public Void call() throws IOException {
            // t=2: semaphore re-acquired
            semaphore.acquireUninterruptibly();
            throw new IOException("foo action failed");
        }
    };
    registerAction(new TestAction(makeFoo, Artifact.NO_ARTIFACTS, ImmutableList.of(foo)));
    // [action] -> bar
    Artifact bar = createDerivedArtifact("bar");
    Runnable makeBar = new Runnable() {

        @Override
        public void run() {
            // t=1: semaphore released
            semaphore.release();
            try {
                // 100ms
                Thread.sleep(100);
            } catch (InterruptedException e) {
            // This might happen (though not necessarily).  The
            // ParallelBuilder interrupts all its workers at the first sign
            // of trouble.
            }
            finished[0] = true;
        }
    };
    registerAction(new TestAction(makeBar, emptySet, asSet(bar)));
    // Don't fail fast when we encounter the error
    reporter.removeHandler(failFastHandler);
    try {
        buildArtifacts(foo, bar);
        fail();
    } catch (BuildFailedException e) {
        assertThat(e.getMessage()).contains("TestAction failed due to exception: foo action failed");
        assertContainsEvent("TestAction failed due to exception: foo action failed");
    }
    assertTrue("bar action not finished, yet buildArtifacts has completed.", finished[0]);
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Semaphore(java.util.concurrent.Semaphore) 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 5 with BuildFailedException

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

the class ParallelBuilderTest method testUpdateCacheError.

@Test
public void testUpdateCacheError() throws Exception {
    FileSystem fs = new InMemoryFileSystem() {

        @Override
        public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
            final FileStatus stat = super.stat(path, followSymlinks);
            if (path.toString().endsWith("/out/foo")) {
                return new FileStatus() {

                    private final FileStatus original = stat;

                    @Override
                    public boolean isSymbolicLink() {
                        return original.isSymbolicLink();
                    }

                    @Override
                    public boolean isFile() {
                        return original.isFile();
                    }

                    @Override
                    public boolean isDirectory() {
                        return original.isDirectory();
                    }

                    @Override
                    public boolean isSpecialFile() {
                        return original.isSpecialFile();
                    }

                    @Override
                    public long getSize() throws IOException {
                        return original.getSize();
                    }

                    @Override
                    public long getNodeId() throws IOException {
                        return original.getNodeId();
                    }

                    @Override
                    public long getLastModifiedTime() throws IOException {
                        throw new IOException();
                    }

                    @Override
                    public long getLastChangeTime() throws IOException {
                        return original.getLastChangeTime();
                    }
                };
            }
            return stat;
        }
    };
    Artifact foo = createDerivedArtifact(fs, "foo");
    registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(foo)));
    reporter.removeHandler(failFastHandler);
    try {
        buildArtifacts(foo);
        fail("Expected to fail");
    } catch (BuildFailedException e) {
        assertContainsEvent("not all outputs were created or valid");
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Aggregations

BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)25 Artifact (com.google.devtools.build.lib.actions.Artifact)20 Test (org.junit.Test)17 TestAction (com.google.devtools.build.lib.actions.util.TestAction)12 IOException (java.io.IOException)8 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)7 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)7 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)7 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)6 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)5 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)5 ImmutableList (com.google.common.collect.ImmutableList)4 TestExecException (com.google.devtools.build.lib.actions.TestExecException)4 SpawnActionTemplate (com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate)4 List (java.util.List)4 Action (com.google.devtools.build.lib.actions.Action)3 DummyAction (com.google.devtools.build.lib.actions.util.TestAction.DummyAction)3 ActionTemplate (com.google.devtools.build.lib.analysis.actions.ActionTemplate)3 ExitCode (com.google.devtools.build.lib.util.ExitCode)3 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)3