Search in sources :

Example 1 with ExtendedEventHandler

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SingleCycleReporter(com.google.devtools.build.skyframe.CyclesReporter.SingleCycleReporter) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) Test(org.junit.Test)

Example 2 with ExtendedEventHandler

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();
}
Also used : LoadingPhaseCompleteEvent(com.google.devtools.build.lib.pkgcache.LoadingPhaseCompleteEvent) Stopwatch(com.google.common.base.Stopwatch) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) TargetParsingCompleteEvent(com.google.devtools.build.lib.pkgcache.TargetParsingCompleteEvent) Target(com.google.devtools.build.lib.packages.Target) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) LoadingFailedException(com.google.devtools.build.lib.pkgcache.LoadingFailedException) HashSet(java.util.HashSet)

Example 3 with ExtendedEventHandler

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());
}
Also used : TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) TargetProvider(com.google.devtools.build.lib.pkgcache.TargetProvider) Label(com.google.devtools.build.lib.cmdline.Label) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) Test(org.junit.Test)

Example 4 with ExtendedEventHandler

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")));
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) EventHandler(com.google.devtools.build.lib.events.EventHandler) EventBus(com.google.common.eventbus.EventBus) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) MoreAsserts.assertContainsEvent(com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent) Event(com.google.devtools.build.lib.events.Event) Supplier(com.google.common.base.Supplier) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Example 5 with ExtendedEventHandler

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.
    }
}
Also used : SingleCycleReporter(com.google.devtools.build.skyframe.CyclesReporter.SingleCycleReporter) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) Test(org.junit.Test)

Aggregations

ExtendedEventHandler (com.google.devtools.build.lib.events.ExtendedEventHandler)5 Test (org.junit.Test)4 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)2 SingleCycleReporter (com.google.devtools.build.skyframe.CyclesReporter.SingleCycleReporter)2 Stopwatch (com.google.common.base.Stopwatch)1 Supplier (com.google.common.base.Supplier)1 EventBus (com.google.common.eventbus.EventBus)1 Label (com.google.devtools.build.lib.cmdline.Label)1 Event (com.google.devtools.build.lib.events.Event)1 EventHandler (com.google.devtools.build.lib.events.EventHandler)1 Reporter (com.google.devtools.build.lib.events.Reporter)1 Target (com.google.devtools.build.lib.packages.Target)1 LoadingFailedException (com.google.devtools.build.lib.pkgcache.LoadingFailedException)1 LoadingPhaseCompleteEvent (com.google.devtools.build.lib.pkgcache.LoadingPhaseCompleteEvent)1 TargetParsingCompleteEvent (com.google.devtools.build.lib.pkgcache.TargetParsingCompleteEvent)1 TargetProvider (com.google.devtools.build.lib.pkgcache.TargetProvider)1 MoreAsserts.assertContainsEvent (com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent)1 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1