use of com.google.devtools.build.lib.events.ExtendedEventHandler in project bazel by bazelbuild.
the class CyclesReporterTest method smoke.
@Test
public void smoke() {
final AtomicBoolean reported = new AtomicBoolean();
SingleCycleReporter singleReporter = new SingleCycleReporter() {
@Override
public boolean maybeReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo, boolean alreadyReported, ExtendedEventHandler eventHandler) {
reported.set(true);
return true;
}
};
CycleInfo cycleInfo = new CycleInfo(ImmutableList.of(DUMMY_KEY));
CyclesReporter cyclesReporter = new CyclesReporter(singleReporter);
cyclesReporter.reportCycles(ImmutableList.of(cycleInfo), DUMMY_KEY, NullEventHandler.INSTANCE);
assertThat(reported.get()).isTrue();
}
use of com.google.devtools.build.lib.events.ExtendedEventHandler in project bazel by bazelbuild.
the class LegacyLoadingPhaseRunner method execute.
/**
* Performs target pattern evaluation, test suite expansion (if requested), and loads the
* transitive closure of the resulting targets as well as of the targets needed to use the given
* build configuration provider.
*/
@Override
public LoadingResult execute(ExtendedEventHandler eventHandler, List<String> targetPatterns, PathFragment relativeWorkingDirectory, LoadingOptions options, boolean keepGoing, boolean determineTests, @Nullable LoadingCallback callback) throws TargetParsingException, LoadingFailedException, InterruptedException {
LOG.info("Starting pattern evaluation");
Stopwatch timer = Stopwatch.createStarted();
if (options.buildTestsOnly && options.compileOneDependency) {
throw new LoadingFailedException("--compile_one_dependency cannot be used together with " + "the --build_tests_only option or the 'bazel test' command ");
}
targetPatternEvaluator.updateOffset(relativeWorkingDirectory);
ExtendedEventHandler parseFailureListener = new ParseFailureListenerImpl(eventHandler);
// Determine targets to build:
ResolvedTargets<Target> targets = getTargetsToBuild(parseFailureListener, targetPatterns, options.compileOneDependency, options.buildTagFilterList, keepGoing);
ImmutableSet<Target> filteredTargets = targets.getFilteredTargets();
boolean buildTestsOnly = options.buildTestsOnly;
ImmutableSet<Target> testsToRun = null;
ImmutableSet<Target> testFilteredTargets = ImmutableSet.of();
// then the list of filtered targets will be set as build list as well.
if (determineTests || buildTestsOnly) {
// Parse the targets to get the tests.
ResolvedTargets<Target> testTargets = determineTests(parseFailureListener, targetPatterns, options, keepGoing);
if (testTargets.getTargets().isEmpty() && !testTargets.getFilteredTargets().isEmpty()) {
eventHandler.handle(Event.warn("All specified test targets were excluded by filters"));
}
if (buildTestsOnly) {
// Replace original targets to build with test targets, so that only targets that are
// actually going to be built are loaded in the loading phase. Note that this has a side
// effect that any test_suite target requested to be built is replaced by the set of *_test
// targets it represents; for example, this affects the status and the summary reports.
Set<Target> allFilteredTargets = new HashSet<>();
allFilteredTargets.addAll(targets.getTargets());
allFilteredTargets.addAll(targets.getFilteredTargets());
allFilteredTargets.removeAll(testTargets.getTargets());
allFilteredTargets.addAll(testTargets.getFilteredTargets());
testFilteredTargets = ImmutableSet.copyOf(allFilteredTargets);
filteredTargets = ImmutableSet.of();
targets = ResolvedTargets.<Target>builder().merge(testTargets).mergeError(targets.hasError()).build();
if (determineTests) {
testsToRun = testTargets.getTargets();
}
} else /*if (determineTests)*/
{
testsToRun = testTargets.getTargets();
targets = ResolvedTargets.<Target>builder().merge(targets).addAll(testsToRun).mergeError(testTargets.hasError()).build();
// filteredTargets is correct in this case - it cannot contain tests that got back in
// through test_suite expansion, because the test determination would also filter those out.
// However, that's not obvious, and it might be better to explicitly recompute it.
}
if (testsToRun != null) {
// Note that testsToRun can still be null here, if buildTestsOnly && !shouldRunTests.
Preconditions.checkState(targets.getTargets().containsAll(testsToRun));
}
}
if (targets.hasError()) {
eventHandler.handle(Event.warn("Target pattern parsing failed. Continuing anyway"));
}
LoadingPhaseRunner.maybeReportDeprecation(eventHandler, targets.getTargets());
long targetPatternEvalTime = timer.stop().elapsed(TimeUnit.MILLISECONDS);
LOG.info("Starting test suite expansion");
timer = Stopwatch.createStarted();
ImmutableSet<Target> targetsToLoad = targets.getTargets();
ResolvedTargets<Target> expandedResult;
try {
expandedResult = expandTestSuites(eventHandler, targetsToLoad, keepGoing);
} catch (TargetParsingException e) {
throw new LoadingFailedException("Loading failed; build aborted", e);
}
ImmutableSet<Target> expandedTargetsToLoad = expandedResult.getTargets();
ImmutableSet<Target> testSuiteTargets = ImmutableSet.copyOf(Sets.difference(targetsToLoad, expandedTargetsToLoad));
long testSuiteTime = timer.stop().elapsed(TimeUnit.MILLISECONDS);
TargetPatternPhaseValue patternParsingValue = new TargetPatternPhaseValue(expandedTargetsToLoad, testsToRun, targets.hasError(), expandedResult.hasError(), filteredTargets, testFilteredTargets, /*originalTargets=*/
targets.getTargets(), testSuiteTargets, getWorkspaceName(eventHandler));
// This is the same code as SkyframeLoadingPhaseRunner.
eventHandler.post(new TargetParsingCompleteEvent(patternParsingValue.getOriginalTargets(), patternParsingValue.getFilteredTargets(), patternParsingValue.getTestFilteredTargets(), targetPatternEvalTime, targetPatterns, patternParsingValue.getTargets()));
if (callback != null) {
callback.notifyTargets(patternParsingValue.getTargets());
}
eventHandler.post(new LoadingPhaseCompleteEvent(patternParsingValue.getTargets(), patternParsingValue.getTestSuiteTargets(), packageManager.getStatistics(), testSuiteTime));
LOG.info("Target pattern evaluation finished");
return patternParsingValue.toLoadingResult();
}
use of com.google.devtools.build.lib.events.ExtendedEventHandler in project bazel by bazelbuild.
the class TestTargetUtilsTest method testExpandTestSuitesInterrupted.
@Test
public void testExpandTestSuitesInterrupted() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("broken/BUILD", "test_suite(name = 'broken', tests = ['//missing:missing_test'])");
try {
TestTargetUtils.expandTestSuites(new TargetProvider() {
@Override
public Target getTarget(ExtendedEventHandler eventHandler, Label label) throws InterruptedException {
throw new InterruptedException();
}
}, reporter, Sets.newHashSet(getTarget("//broken")), /*strict=*/
false, /*keep_going=*/
true);
} catch (TargetParsingException e) {
assertNotNull(e.getMessage());
}
assertTrue(Thread.currentThread().isInterrupted());
}
use of com.google.devtools.build.lib.events.ExtendedEventHandler in project bazel by bazelbuild.
the class ParallelEvaluatorTest method signalValueEnqueuedAndEvaluated.
@Test
public void signalValueEnqueuedAndEvaluated() throws Exception {
final Set<SkyKey> enqueuedValues = Sets.newConcurrentHashSet();
final Set<SkyKey> evaluatedValues = Sets.newConcurrentHashSet();
EvaluationProgressReceiver progressReceiver = new EvaluationProgressReceiver() {
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
throw new IllegalStateException();
}
@Override
public void enqueueing(SkyKey skyKey) {
enqueuedValues.add(skyKey);
}
@Override
public void computed(SkyKey skyKey, long elapsedTimeNanos) {
}
@Override
public void evaluated(SkyKey skyKey, Supplier<SkyValue> skyValueSupplier, EvaluationState state) {
evaluatedValues.add(skyKey);
}
};
ExtendedEventHandler reporter = new Reporter(new EventBus(), new EventHandler() {
@Override
public void handle(Event e) {
throw new IllegalStateException();
}
});
MemoizingEvaluator aug = new InMemoryMemoizingEvaluator(ImmutableMap.of(GraphTester.NODE_TYPE, tester.getFunction()), new RecordingDifferencer(), progressReceiver);
SequentialBuildDriver driver = new SequentialBuildDriver(aug);
tester.getOrCreate("top1").setComputedValue(CONCATENATE).addDependency("d1").addDependency("d2");
tester.getOrCreate("top2").setComputedValue(CONCATENATE).addDependency("d3");
tester.getOrCreate("top3");
assertThat(enqueuedValues).isEmpty();
assertThat(evaluatedValues).isEmpty();
tester.set("d1", new StringValue("1"));
tester.set("d2", new StringValue("2"));
tester.set("d3", new StringValue("3"));
driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top1")), false, 200, reporter);
assertThat(enqueuedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1", "d1", "d2")));
assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1", "d1", "d2")));
enqueuedValues.clear();
evaluatedValues.clear();
driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top2")), false, 200, reporter);
assertThat(enqueuedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top2", "d3")));
assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top2", "d3")));
enqueuedValues.clear();
evaluatedValues.clear();
driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top1")), false, 200, reporter);
assertThat(enqueuedValues).isEmpty();
assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1")));
}
use of com.google.devtools.build.lib.events.ExtendedEventHandler in project bazel by bazelbuild.
the class CyclesReporterTest method notReportedAssertion.
@Test
public void notReportedAssertion() {
SingleCycleReporter singleReporter = new SingleCycleReporter() {
@Override
public boolean maybeReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo, boolean alreadyReported, ExtendedEventHandler eventHandler) {
return false;
}
};
CycleInfo cycleInfo = new CycleInfo(ImmutableList.of(DUMMY_KEY));
CyclesReporter cyclesReporter = new CyclesReporter(singleReporter);
try {
cyclesReporter.reportCycles(ImmutableList.of(cycleInfo), DUMMY_KEY, NullEventHandler.INSTANCE);
assertThat(false).isTrue();
} catch (IllegalStateException e) {
// Expected.
}
}
Aggregations