Search in sources :

Example 51 with Artifact

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

the class ParallelBuilderTest method testDuplicatedInput.

@Test
public void testDuplicatedInput() throws Exception {
    // <null> -> [action] -> foo
    // (foo, foo) -> [action] -> bar
    Artifact foo = createDerivedArtifact("foo");
    Artifact bar = createDerivedArtifact("bar");
    registerAction(new TestAction(TestAction.NO_EFFECT, ParallelBuilderTest.<Artifact>asSet(), asSet(foo)));
    registerAction(new TestAction(TestAction.NO_EFFECT, Lists.<Artifact>newArrayList(foo, foo), asSet(bar)));
    buildArtifacts(bar);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 52 with Artifact

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

the class ParallelBuilderTest method testReportsActionExecutedEvent.

@Test
public void testReportsActionExecutedEvent() throws Exception {
    Artifact pear = createDerivedArtifact("pear");
    ActionEventRecorder recorder = new ActionEventRecorder();
    EventBus eventBus = new EventBus();
    eventBusRef.set(eventBus);
    eventBus.register(recorder);
    Action action = registerAction(new TestAction(Runnables.doNothing(), emptySet, asSet(pear)));
    buildArtifacts(createBuilder(DEFAULT_NUM_JOBS, true), pear);
    assertThat(recorder.actionExecutedEvents).hasSize(1);
    assertEquals(action, recorder.actionExecutedEvents.get(0).getAction());
}
Also used : Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) EventBus(com.google.common.eventbus.EventBus) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 53 with Artifact

use of com.google.devtools.build.lib.actions.Artifact 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)

Example 54 with Artifact

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

the class ParallelBuilderTest method testCyclicActionGraph.

@Test
public void testCyclicActionGraph() throws Exception {
    // foo -> [action] -> bar
    // bar -> [action] -> baz
    // baz -> [action] -> foo
    Artifact foo = createDerivedArtifact("foo");
    Artifact bar = createDerivedArtifact("bar");
    Artifact baz = createDerivedArtifact("baz");
    try {
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(foo)));
        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)

Example 55 with Artifact

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

the class ParallelBuilderTest method testSelfCyclicActionGraph.

@Test
public void testSelfCyclicActionGraph() throws Exception {
    // foo -> [action] -> foo
    Artifact foo = createDerivedArtifact("foo");
    try {
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(foo)));
        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

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28