Search in sources :

Example 1 with ExecutionProgressReceiverAvailableEvent

use of com.google.devtools.build.lib.buildtool.buildevent.ExecutionProgressReceiverAvailableEvent in project bazel by bazelbuild.

the class SkyframeBuilder method buildArtifacts.

@Override
public void buildArtifacts(Reporter reporter, Set<Artifact> artifacts, Set<ConfiguredTarget> parallelTests, Set<ConfiguredTarget> exclusiveTests, Collection<ConfiguredTarget> targetsToBuild, Collection<AspectValue> aspects, Executor executor, Set<ConfiguredTarget> builtTargets, boolean explain, @Nullable Range<Long> lastExecutionTimeRange, TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, AbruptExitException, TestExecException, InterruptedException {
    skyframeExecutor.prepareExecution(modifiedOutputFiles, lastExecutionTimeRange);
    skyframeExecutor.setFileCache(fileCache);
    // Note that executionProgressReceiver accesses builtTargets concurrently (after wrapping in a
    // synchronized collection), so unsynchronized access to this variable is unsafe while it runs.
    ExecutionProgressReceiver executionProgressReceiver = new ExecutionProgressReceiver(Preconditions.checkNotNull(builtTargets), countTestActions(exclusiveTests), ImmutableSet.<ConfiguredTarget>builder().addAll(parallelTests).addAll(exclusiveTests).build(), topLevelArtifactContext, skyframeExecutor.getEventBus());
    skyframeExecutor.getEventBus().post(new ExecutionProgressReceiverAvailableEvent(executionProgressReceiver));
    List<ExitCode> exitCodes = new LinkedList<>();
    EvaluationResult<?> result;
    ActionExecutionStatusReporter statusReporter = ActionExecutionStatusReporter.create(reporter, executor, skyframeExecutor.getEventBus());
    AtomicBoolean isBuildingExclusiveArtifacts = new AtomicBoolean(false);
    ActionExecutionInactivityWatchdog watchdog = new ActionExecutionInactivityWatchdog(executionProgressReceiver.createInactivityMonitor(statusReporter), executionProgressReceiver.createInactivityReporter(statusReporter, isBuildingExclusiveArtifacts), progressReportInterval);
    skyframeExecutor.setActionExecutionProgressReportingObjects(executionProgressReceiver, executionProgressReceiver, statusReporter);
    watchdog.start();
    try {
        result = skyframeExecutor.buildArtifacts(reporter, executor, artifacts, targetsToBuild, aspects, parallelTests, /*exclusiveTesting=*/
        false, keepGoing, explain, finalizeActionsToOutputService, numJobs, actionCacheChecker, executionProgressReceiver, topLevelArtifactContext);
        // progressReceiver is finished, so unsynchronized access to builtTargets is now safe.
        Optional<ExitCode> exitCode = processResult(reporter, result, keepGoing, skyframeExecutor);
        Preconditions.checkState(exitCode != null || result.keyNames().size() == (artifacts.size() + targetsToBuild.size() + aspects.size() + parallelTests.size()), "Build reported as successful but not all artifacts and targets built: %s, %s", result, artifacts);
        if (exitCode != null) {
            exitCodes.add(exitCode.orNull());
        }
        // Run exclusive tests: either tagged as "exclusive" or is run in an invocation with
        // --test_output=streamed.
        isBuildingExclusiveArtifacts.set(true);
        for (ConfiguredTarget exclusiveTest : exclusiveTests) {
            // Since only one artifact is being built at a time, we don't worry about an artifact being
            // built and then the build being interrupted.
            result = skyframeExecutor.buildArtifacts(reporter, executor, ImmutableSet.<Artifact>of(), targetsToBuild, aspects, ImmutableSet.of(exclusiveTest), /*exclusiveTesting=*/
            true, keepGoing, explain, finalizeActionsToOutputService, numJobs, actionCacheChecker, null, topLevelArtifactContext);
            exitCode = processResult(reporter, result, keepGoing, skyframeExecutor);
            Preconditions.checkState(exitCode != null || !result.keyNames().isEmpty(), "Build reported as successful but test %s not executed: %s", exclusiveTest, result);
            if (exitCode != null) {
                exitCodes.add(exitCode.orNull());
            }
        }
    } finally {
        watchdog.stop();
        skyframeExecutor.setActionExecutionProgressReportingObjects(null, null, null);
        statusReporter.unregisterFromEventBus();
    }
    if (!exitCodes.isEmpty()) {
        if (keepGoing) {
            // Use the exit code with the highest priority.
            throw new BuildFailedException(null, Collections.max(exitCodes, ExitCodeComparator.INSTANCE));
        } else {
            throw new BuildFailedException();
        }
    }
}
Also used : ExitCode(com.google.devtools.build.lib.util.ExitCode) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) ExecutionProgressReceiverAvailableEvent(com.google.devtools.build.lib.buildtool.buildevent.ExecutionProgressReceiverAvailableEvent) LinkedList(java.util.LinkedList) Artifact(com.google.devtools.build.lib.actions.Artifact) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ActionExecutionInactivityWatchdog(com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)

Aggregations

ActionExecutionStatusReporter (com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 ExecutionProgressReceiverAvailableEvent (com.google.devtools.build.lib.buildtool.buildevent.ExecutionProgressReceiverAvailableEvent)1 ActionExecutionInactivityWatchdog (com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog)1 ExitCode (com.google.devtools.build.lib.util.ExitCode)1 LinkedList (java.util.LinkedList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1