Search in sources :

Example 1 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class ParallelBuilderTest method testProgressReporting.

@Test
public void testProgressReporting() throws Exception {
    // Build three artifacts in 3 separate actions (baz depends on bar and bar
    // depends on foo.  Make sure progress is reported at the beginning of all
    // three actions.
    List<Artifact> sourceFiles = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        sourceFiles.add(createInputFile("file" + i));
    }
    Artifact foo = createDerivedArtifact("foo");
    Artifact bar = createDerivedArtifact("bar");
    Artifact baz = createDerivedArtifact("baz");
    bar.getPath().delete();
    baz.getPath().delete();
    final List<String> messages = new ArrayList<>();
    EventHandler handler = new EventHandler() {

        @Override
        public void handle(Event event) {
            EventKind k = event.getKind();
            if (k == EventKind.START || k == EventKind.FINISH) {
                // Remove the tmpDir as this is user specific and the assert would
                // fail below.
                messages.add(event.getMessage().replaceFirst(TestUtils.tmpDir(), "") + " " + event.getKind());
            }
        }
    };
    reporter.addHandler(handler);
    reporter.addHandler(new PrintingEventHandler(EventKind.ALL_EVENTS));
    registerAction(new TestAction(TestAction.NO_EFFECT, sourceFiles, asSet(foo)));
    registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
    registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
    buildArtifacts(baz);
    // Check that the percentages increase non-linearly, because foo has 10 input files
    List<String> expectedMessages = Lists.newArrayList("Test foo START", "Test foo FINISH", "Test bar START", "Test bar FINISH", "Test baz START", "Test baz FINISH");
    assertThat(messages).containsAllIn(expectedMessages);
    // Now do an incremental rebuild of bar and baz,
    // and check the incremental progress percentages.
    messages.clear();
    bar.getPath().delete();
    baz.getPath().delete();
    // This uses a new builder instance so that we refetch timestamps from
    // (in-memory) file system, rather than using cached entries.
    buildArtifacts(baz);
    expectedMessages = Lists.newArrayList("Test bar START", "Test bar FINISH", "Test baz START", "Test baz FINISH");
    assertThat(messages).containsAllIn(expectedMessages);
}
Also used : EventKind(com.google.devtools.build.lib.events.EventKind) ArrayList(java.util.ArrayList) EventHandler(com.google.devtools.build.lib.events.EventHandler) PrintingEventHandler(com.google.devtools.build.lib.events.PrintingEventHandler) ActionExecutedEvent(com.google.devtools.build.lib.actions.ActionExecutedEvent) Event(com.google.devtools.build.lib.events.Event) Artifact(com.google.devtools.build.lib.actions.Artifact) PrintingEventHandler(com.google.devtools.build.lib.events.PrintingEventHandler) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 2 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class SkyframeLabelVisitorTest method testCrashInLoadPackageIsReportedEffectively.

// Regression test for "Bazel hangs on input of illegal rule".
@Test
public void testCrashInLoadPackageIsReportedEffectively() throws Exception {
    reporter.removeHandler(failFastHandler);
    // Inject a NullPointerException into loadPackage().  This is triggered by
    // any ERROR event.
    reporter.addHandler(new EventHandler() {

        @Override
        public void handle(Event event) {
            if (EventKind.ERRORS.contains(event.getKind())) {
                throw new NullPointerException("oops");
            }
        }
    });
    // Visitation of //x reaches package "bad" by many paths.  The first time,
    // loadPackage() crashes (because of the injected NPE).  Previously,
    // on a subsequent visitation, the visitor would get livelocked due the
    // stale PendingEntry stuck in the PackageCache.  With the fix, the NPE is
    // thrown.
    scratch.file("bad/BUILD", "this is a bad build file");
    scratch.file("x/BUILD", "sh_library(name='x', ", "           deps=['//bad:a', '//bad:b', '//bad:c',", "                 '//bad:d', '//bad:e', '//bad:f'])");
    try {
        // Used to get stuck.
        assertLabelsVisitedWithErrors(ImmutableSet.of("//x:x"), ImmutableSet.of("//x"));
        // unreachable
        fail();
    } catch (NullPointerException npe) {
    // This is expected for legacy blaze.
    } catch (RuntimeException re) {
        // This is expected for Skyframe blaze.
        assertThat(re.getCause()).isInstanceOf(NullPointerException.class);
    }
}
Also used : EventHandler(com.google.devtools.build.lib.events.EventHandler) Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 3 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class SkyframeLabelVisitorTestCase method assertNewBuildFileConflict.

protected Collection<Event> assertNewBuildFileConflict() throws Exception {
    // expect errors
    reporter.removeHandler(failFastHandler);
    scratch.file("pkg/BUILD", "sh_library(name = 'x', deps = ['//pkg2:q/sub'])");
    scratch.file("pkg2/BUILD", "sh_library(name = 'q/sub')");
    assertLabelsVisited(ImmutableSet.of("//pkg:x", "//pkg2:q/sub"), ImmutableSet.of("//pkg:x"), !EXPECT_ERROR, !KEEP_GOING);
    scratch.file("pkg2/q/BUILD");
    syncPackages();
    EventCollector warningCollector = new EventCollector(EventKind.WARNING);
    reporter.addHandler(warningCollector);
    assertLabelsVisitedWithErrors(ImmutableSet.of("//pkg:x"), ImmutableSet.of("//pkg:x"));
    assertContainsEvent("Label '//pkg2:q/sub' crosses boundary of subpackage 'pkg2/q'");
    assertContainsEvent("no such target '//pkg2:q/sub'");
    Collection<Event> warnings = Lists.newArrayList(warningCollector);
    // Check stability (not redundant).
    assertLabelsVisitedWithErrors(ImmutableSet.of("//pkg:x"), ImmutableSet.of("//pkg:x"));
    assertContainsEvent("Label '//pkg2:q/sub' crosses boundary of subpackage 'pkg2/q'");
    return warnings;
}
Also used : EventCollector(com.google.devtools.build.lib.events.EventCollector) Event(com.google.devtools.build.lib.events.Event)

Example 4 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class CircularDependencyTest method testThreeLongPackageGroupCycle.

@Test
public void testThreeLongPackageGroupCycle() throws Exception {
    String expectedEvent = "cycle in dependency graph:\n" + "    //cycle:superman\n" + ".-> //cycle:rock\n" + "|   //cycle:paper\n" + "|   //cycle:scissors\n" + "`-- //cycle:rock";
    checkError("cycle", "superman", expectedEvent, "# dummy line", "package_group(name='paper', includes=['//cycle:scissors'])", "package_group(name='rock', includes=['//cycle:paper'])", "package_group(name='scissors', includes=['//cycle:rock'])", "sh_library(name='superman', visibility=[':rock'])");
    Event foundEvent = null;
    for (Event event : eventCollector) {
        if (event.getMessage().contains(expectedEvent)) {
            foundEvent = event;
            break;
        }
    }
    assertNotNull(foundEvent);
    Location location = foundEvent.getLocation();
    assertEquals(3, location.getStartLineAndColumn().getLine());
    assertEquals("/workspace/cycle/BUILD", location.getPath().toString());
}
Also used : Event(com.google.devtools.build.lib.events.Event) Location(com.google.devtools.build.lib.events.Location) Test(org.junit.Test)

Example 5 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class BuildViewTestCase method getRuleContextForSkylark.

/**
   * Creates and returns a rule context to use for Skylark tests that is equivalent to the one
   * that was used to create the given configured target.
   */
protected RuleContext getRuleContextForSkylark(ConfiguredTarget target) throws Exception {
    // TODO(bazel-team): we need this horrible workaround because CachingAnalysisEnvironment
    // only works with StoredErrorEventListener despite the fact it accepts the interface
    // ErrorEventListener, so it's not possible to create it with reporter.
    // See BuildView.getRuleContextForTesting().
    StoredEventHandler eventHandler = new StoredEventHandler() {

        @Override
        public synchronized void handle(Event e) {
            super.handle(e);
            reporter.handle(e);
        }
    };
    return view.getRuleContextForTesting(target, eventHandler, masterConfig);
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Event(com.google.devtools.build.lib.events.Event)

Aggregations

Event (com.google.devtools.build.lib.events.Event)28 Test (org.junit.Test)15 EventHandler (com.google.devtools.build.lib.events.EventHandler)4 EventBus (com.google.common.eventbus.EventBus)3 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)3 Reporter (com.google.devtools.build.lib.events.Reporter)3 MoreAsserts.assertContainsEvent (com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent)3 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)3 ArrayList (java.util.ArrayList)3 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)2 ActionMiddlemanEvent (com.google.devtools.build.lib.actions.ActionMiddlemanEvent)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 CachedActionEvent (com.google.devtools.build.lib.actions.CachedActionEvent)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2 EventCollector (com.google.devtools.build.lib.events.EventCollector)2 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1