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);
}
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);
}
}
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;
}
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());
}
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);
}
Aggregations