Search in sources :

Example 1 with ActionExecutionStatusReporter

use of com.google.devtools.build.lib.actions.ActionExecutionStatusReporter in project bazel by bazelbuild.

the class SkyframeActionExecutor method prepareScheduleExecuteAndCompleteAction.

/**
   * Prepare, schedule, execute, and then complete the action.
   * When this function is called, we know that this action needs to be executed.
   * This function will prepare for the action's execution (i.e. delete the outputs);
   * schedule its execution; execute the action;
   * and then do some post-execution processing to complete the action:
   * set the outputs readonly and executable, and insert the action results in the
   * action cache.
   *
   * @param action  The action to execute
   * @param context services in the scope of the action
   * @param actionStartTime time when we started the first phase of the action execution.
   * @throws ActionExecutionException if the execution of the specified action
   *   failed for any reason.
   * @throws InterruptedException if the thread was interrupted.
   */
private void prepareScheduleExecuteAndCompleteAction(Action action, ActionExecutionContext context, long actionStartTime) throws ActionExecutionException, InterruptedException {
    // Delete the metadataHandler's cache of the action's outputs, since they are being deleted.
    context.getMetadataHandler().discardOutputMetadata();
    // the action really does produce the outputs.
    try {
        action.prepare(context.getExecutor().getExecRoot());
        createOutputDirectories(action);
    } catch (IOException e) {
        reportError("failed to delete output files before executing action", e, action, null);
    }
    postEvent(new ActionStartedEvent(action, actionStartTime));
    ActionExecutionStatusReporter statusReporter = statusReporterRef.get();
    try {
        // Mark the current action as being prepared.
        statusReporter.updateStatus(ActionStatusMessage.preparingStrategy(action));
        boolean outputDumped = executeActionTask(action, context);
        completeAction(action, context.getMetadataHandler(), context.getFileOutErr(), outputDumped);
    } finally {
        statusReporter.remove(action);
        postEvent(new ActionCompletionEvent(actionStartTime, action));
    }
}
Also used : ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) IOException(java.io.IOException) ActionCompletionEvent(com.google.devtools.build.lib.actions.ActionCompletionEvent)

Example 2 with ActionExecutionStatusReporter

use of com.google.devtools.build.lib.actions.ActionExecutionStatusReporter 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)

Example 3 with ActionExecutionStatusReporter

use of com.google.devtools.build.lib.actions.ActionExecutionStatusReporter in project bazel by bazelbuild.

the class TimestampBuilderTestCase method createBuilder.

protected Builder createBuilder(final ActionCache actionCache, final int threadCount, final boolean keepGoing, @Nullable EvaluationProgressReceiver evaluationProgressReceiver) throws Exception {
    AtomicReference<PathPackageLocator> pkgLocator = new AtomicReference<>(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)));
    AtomicReference<TimestampGranularityMonitor> tsgmRef = new AtomicReference<>(tsgm);
    BlazeDirectories directories = new BlazeDirectories(rootDirectory, outputBase, rootDirectory, TestConstants.PRODUCT_NAME);
    ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocator, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, directories);
    differencer = new RecordingDifferencer();
    ActionExecutionStatusReporter statusReporter = ActionExecutionStatusReporter.create(new StoredEventHandler());
    final SkyframeActionExecutor skyframeActionExecutor = new SkyframeActionExecutor(eventBusRef, new AtomicReference<>(statusReporter));
    Path actionOutputBase = scratch.dir("/usr/local/google/_blaze_jrluser/FAKEMD5/action_out/");
    skyframeActionExecutor.setActionLogBufferPathGenerator(new ActionLogBufferPathGenerator(actionOutputBase));
    ActionInputFileCache cache = new SingleBuildFileCache(rootDirectory.getPathString(), scratch.getFileSystem());
    skyframeActionExecutor.setFileCache(cache);
    final InMemoryMemoizingEvaluator evaluator = new InMemoryMemoizingEvaluator(ImmutableMap.<SkyFunctionName, SkyFunction>builder().put(SkyFunctions.FILE_STATE, new FileStateFunction(tsgmRef, externalFilesHelper)).put(SkyFunctions.FILE, new FileFunction(pkgLocator)).put(SkyFunctions.ARTIFACT, new ArtifactFunction(Predicates.<PathFragment>alwaysFalse())).put(SkyFunctions.ACTION_EXECUTION, new ActionExecutionFunction(skyframeActionExecutor, tsgmRef)).put(SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null)).put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(null, CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD))).put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())).put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(TestRuleClassProvider.getRuleClassProvider(), TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create(TestRuleClassProvider.getRuleClassProvider(), scratch.getFileSystem()), directories)).put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()).put(SkyFunctions.ACTION_TEMPLATE_EXPANSION, new DelegatingActionTemplateExpansionFunction()).build(), differencer, evaluationProgressReceiver);
    final SequentialBuildDriver driver = new SequentialBuildDriver(evaluator);
    PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
    PrecomputedValue.ACTION_ENV.set(differencer, ImmutableMap.<String, String>of());
    PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
    return new Builder() {

        private void setGeneratingActions() {
            if (evaluator.getExistingValueForTesting(OWNER_KEY) == null) {
                differencer.inject(ImmutableMap.of(OWNER_KEY, new ActionLookupValue(ImmutableList.copyOf(actions))));
            }
        }

        @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, Range<Long> lastExecutionTimeRange, TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, AbruptExitException, InterruptedException, TestExecException {
            skyframeActionExecutor.prepareForExecution(reporter, executor, keepGoing, /*explain=*/
            false, new ActionCacheChecker(actionCache, null, ALWAYS_EXECUTE_FILTER, null), null);
            List<SkyKey> keys = new ArrayList<>();
            for (Artifact artifact : artifacts) {
                keys.add(ArtifactSkyKey.key(artifact, true));
            }
            setGeneratingActions();
            EvaluationResult<SkyValue> result = driver.evaluate(keys, keepGoing, threadCount, reporter);
            if (result.hasError()) {
                boolean hasCycles = false;
                for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
                    Iterable<CycleInfo> cycles = entry.getValue().getCycleInfo();
                    hasCycles |= !Iterables.isEmpty(cycles);
                }
                if (hasCycles) {
                    throw new BuildFailedException(CYCLE_MSG);
                } else if (result.errorMap().isEmpty() || keepGoing) {
                    throw new BuildFailedException();
                } else {
                    SkyframeBuilder.rethrow(Preconditions.checkNotNull(result.getError().getException()));
                }
            }
        }
    };
}
Also used : SkyframeBuilder(com.google.devtools.build.lib.buildtool.SkyframeBuilder) ArrayList(java.util.ArrayList) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) SkyKey(com.google.devtools.build.skyframe.SkyKey) InMemoryMemoizingEvaluator(com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Range(com.google.common.collect.Range) ActionLogBufferPathGenerator(com.google.devtools.build.lib.actions.ActionLogBufferPathGenerator) ActionCacheChecker(com.google.devtools.build.lib.actions.ActionCacheChecker) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RecordingDifferencer(com.google.devtools.build.skyframe.RecordingDifferencer) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) CycleInfo(com.google.devtools.build.skyframe.CycleInfo) SkyValue(com.google.devtools.build.skyframe.SkyValue) SkyFunctionName(com.google.devtools.build.skyframe.SkyFunctionName) Executor(com.google.devtools.build.lib.actions.Executor) DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) SingleBuildFileCache(com.google.devtools.build.lib.exec.SingleBuildFileCache) Path(com.google.devtools.build.lib.vfs.Path) Reporter(com.google.devtools.build.lib.events.Reporter) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Artifact(com.google.devtools.build.lib.actions.Artifact) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext)

Aggregations

ActionExecutionStatusReporter (com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Range (com.google.common.collect.Range)1 ActionCacheChecker (com.google.devtools.build.lib.actions.ActionCacheChecker)1 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1 ActionLogBufferPathGenerator (com.google.devtools.build.lib.actions.ActionLogBufferPathGenerator)1 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)1 Executor (com.google.devtools.build.lib.actions.Executor)1 ResourceSet (com.google.devtools.build.lib.actions.ResourceSet)1 DummyExecutor (com.google.devtools.build.lib.actions.util.DummyExecutor)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)1 SkyframeBuilder (com.google.devtools.build.lib.buildtool.SkyframeBuilder)1 ExecutionProgressReceiverAvailableEvent (com.google.devtools.build.lib.buildtool.buildevent.ExecutionProgressReceiverAvailableEvent)1 Reporter (com.google.devtools.build.lib.events.Reporter)1