Search in sources :

Example 1 with TopLevelArtifactContext

use of com.google.devtools.build.lib.analysis.TopLevelArtifactContext in project bazel by bazelbuild.

the class BuildResultPrinter method showBuildResult.

/**
   * Shows the result of the build. Information includes the list of up-to-date
   * and failed targets and list of output artifacts for successful targets
   *
   * <p>This corresponds to the --show_result flag.
   */
public void showBuildResult(BuildRequest request, BuildResult result, Collection<ConfiguredTarget> configuredTargets, Collection<AspectValue> aspects) {
    // NOTE: be careful what you print!  We don't want to create a consistency
    // problem where the summary message and the exit code disagree.  The logic
    // here is already complex.
    Collection<ConfiguredTarget> targetsToPrint = filterTargetsToPrint(configuredTargets);
    Collection<AspectValue> aspectsToPrint = filterAspectsToPrint(aspects);
    // Filter the targets we care about into two buckets:
    Collection<ConfiguredTarget> succeeded = new ArrayList<>();
    Collection<ConfiguredTarget> failed = new ArrayList<>();
    for (ConfiguredTarget target : targetsToPrint) {
        Collection<ConfiguredTarget> successfulTargets = result.getSuccessfulTargets();
        (successfulTargets.contains(target) ? succeeded : failed).add(target);
    }
    // Suppress summary if --show_result value is exceeded:
    if (succeeded.size() + failed.size() + aspectsToPrint.size() > request.getBuildOptions().maxResultTargets) {
        return;
    }
    OutErr outErr = request.getOutErr();
    TopLevelArtifactContext context = request.getTopLevelArtifactContext();
    for (ConfiguredTarget target : succeeded) {
        Label label = target.getLabel();
        // For up-to-date targets report generated artifacts, but only
        // if they have associated action and not middleman artifacts.
        boolean headerFlag = true;
        for (Artifact artifact : TopLevelArtifactHelper.getAllArtifactsToBuild(target, context).getImportantArtifacts()) {
            if (shouldPrint(artifact)) {
                if (headerFlag) {
                    outErr.printErr("Target " + label + " up-to-date:\n");
                    headerFlag = false;
                }
                outErr.printErrLn(formatArtifactForShowResults(artifact, request));
            }
        }
        if (headerFlag) {
            outErr.printErr("Target " + label + " up-to-date (nothing to build)\n");
        }
    }
    for (AspectValue aspect : aspectsToPrint) {
        Label label = aspect.getLabel();
        String aspectName = aspect.getConfiguredAspect().getName();
        boolean headerFlag = true;
        NestedSet<Artifact> importantArtifacts = TopLevelArtifactHelper.getAllArtifactsToBuild(aspect, context).getImportantArtifacts();
        for (Artifact importantArtifact : importantArtifacts) {
            if (headerFlag) {
                outErr.printErr("Aspect " + aspectName + " of " + label + " up-to-date:\n");
                headerFlag = false;
            }
            if (shouldPrint(importantArtifact)) {
                outErr.printErrLn(formatArtifactForShowResults(importantArtifact, request));
            }
        }
        if (headerFlag) {
            outErr.printErr("Aspect " + aspectName + " of " + label + " up-to-date (nothing to build)\n");
        }
    }
    for (ConfiguredTarget target : failed) {
        outErr.printErr("Target " + target.getLabel() + " failed to build\n");
        // For failed compilation, it is still useful to examine temp artifacts,
        // (ie, preprocessed and assembler files).
        OutputGroupProvider topLevelProvider = target.getProvider(OutputGroupProvider.class);
        String productName = env.getRuntime().getProductName();
        if (topLevelProvider != null) {
            for (Artifact temp : topLevelProvider.getOutputGroup(OutputGroupProvider.TEMP_FILES)) {
                if (temp.getPath().exists()) {
                    outErr.printErrLn("  See temp at " + OutputDirectoryLinksUtils.getPrettyPath(temp.getPath(), env.getWorkspaceName(), env.getWorkspace(), request.getBuildOptions().getSymlinkPrefix(productName), productName));
                }
            }
        }
    }
    if (!failed.isEmpty() && !request.getOptions(ExecutionOptions.class).verboseFailures) {
        outErr.printErr("Use --verbose_failures to see the command lines of failed build steps.\n");
    }
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutErr(com.google.devtools.build.lib.util.io.OutErr) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) OutputFileConfiguredTarget(com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget) InputFileConfiguredTarget(com.google.devtools.build.lib.analysis.InputFileConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) ExecutionOptions(com.google.devtools.build.lib.exec.ExecutionOptions) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext)

Example 2 with TopLevelArtifactContext

use of com.google.devtools.build.lib.analysis.TopLevelArtifactContext in project bazel by bazelbuild.

the class TestCompletionFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    TestCompletionValue.TestCompletionKey key = (TestCompletionValue.TestCompletionKey) skyKey.argument();
    LabelAndConfiguration lac = key.labelAndConfiguration();
    TopLevelArtifactContext ctx = key.topLevelArtifactContext();
    if (env.getValue(TargetCompletionValue.key(lac, ctx)) == null) {
        return null;
    }
    ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key(lac.getLabel(), lac.getConfiguration()));
    if (ctValue == null) {
        return null;
    }
    ConfiguredTarget ct = ctValue.getConfiguredTarget();
    if (key.exclusiveTesting()) {
        // Request test artifacts iteratively if testing exclusively.
        for (Artifact testArtifact : TestProvider.getTestStatusArtifacts(ct)) {
            if (env.getValue(ArtifactSkyKey.key(testArtifact, /*isMandatory=*/
            true)) == null) {
                return null;
            }
        }
    } else {
        env.getValues(ArtifactSkyKey.mandatoryKeys(TestProvider.getTestStatusArtifacts(ct)));
        if (env.valuesMissing()) {
            return null;
        }
    }
    return TestCompletionValue.TEST_COMPLETION_MARKER;
}
Also used : LabelAndConfiguration(com.google.devtools.build.lib.analysis.LabelAndConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 3 with TopLevelArtifactContext

use of com.google.devtools.build.lib.analysis.TopLevelArtifactContext in project bazel by bazelbuild.

the class BuildResultPrinter method showArtifacts.

/**
   * Prints a flat list of all artifacts built by the passed top-level targets.
   *
   * <p>This corresponds to the --experimental_show_artifacts flag.
   */
public void showArtifacts(BuildRequest request, Collection<ConfiguredTarget> configuredTargets, Collection<AspectValue> aspects) {
    TopLevelArtifactContext context = request.getTopLevelArtifactContext();
    Collection<ConfiguredTarget> targetsToPrint = filterTargetsToPrint(configuredTargets);
    Collection<AspectValue> aspectsToPrint = filterAspectsToPrint(aspects);
    NestedSetBuilder<Artifact> artifactsBuilder = NestedSetBuilder.stableOrder();
    for (ConfiguredTarget target : targetsToPrint) {
        artifactsBuilder.addTransitive(TopLevelArtifactHelper.getAllArtifactsToBuild(target, context).getImportantArtifacts());
    }
    for (AspectValue aspect : aspectsToPrint) {
        artifactsBuilder.addTransitive(TopLevelArtifactHelper.getAllArtifactsToBuild(aspect, context).getImportantArtifacts());
    }
    OutErr outErr = request.getOutErr();
    outErr.printErrLn("Build artifacts:");
    NestedSet<Artifact> artifacts = artifactsBuilder.build();
    for (Artifact artifact : artifacts) {
        if (!artifact.isSourceArtifact()) {
            outErr.printErrLn(">>>" + artifact.getPath());
        }
    }
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutErr(com.google.devtools.build.lib.util.io.OutErr) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) OutputFileConfiguredTarget(com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget) InputFileConfiguredTarget(com.google.devtools.build.lib.analysis.InputFileConfiguredTarget) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 4 with TopLevelArtifactContext

use of com.google.devtools.build.lib.analysis.TopLevelArtifactContext in project bazel by bazelbuild.

the class CompletionFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws CompletionFunctionException, InterruptedException {
    TValue value = completor.getValueFromSkyKey(skyKey, env);
    TopLevelArtifactContext topLevelContext = completor.getTopLevelArtifactContext(skyKey);
    if (env.valuesMissing()) {
        return null;
    }
    Map<SkyKey, ValueOrException2<MissingInputFileException, ActionExecutionException>> inputDeps = env.getValuesOrThrow(ArtifactSkyKey.mandatoryKeys(completor.getAllArtifactsToBuild(value, topLevelContext).getAllArtifacts()), MissingInputFileException.class, ActionExecutionException.class);
    int missingCount = 0;
    ActionExecutionException firstActionExecutionException = null;
    MissingInputFileException missingInputException = null;
    NestedSetBuilder<Cause> rootCausesBuilder = NestedSetBuilder.stableOrder();
    for (Map.Entry<SkyKey, ValueOrException2<MissingInputFileException, ActionExecutionException>> depsEntry : inputDeps.entrySet()) {
        Artifact input = ArtifactSkyKey.artifact(depsEntry.getKey());
        try {
            depsEntry.getValue().get();
        } catch (MissingInputFileException e) {
            missingCount++;
            final Label inputOwner = input.getOwner();
            if (inputOwner != null) {
                Cause cause = new LabelCause(inputOwner);
                rootCausesBuilder.add(cause);
                env.getListener().handle(completor.getRootCauseError(value, cause));
            }
        } catch (ActionExecutionException e) {
            rootCausesBuilder.addTransitive(e.getRootCauses());
            if (firstActionExecutionException == null) {
                firstActionExecutionException = e;
            }
        }
    }
    if (missingCount > 0) {
        missingInputException = completor.getMissingFilesException(value, missingCount);
    }
    NestedSet<Cause> rootCauses = rootCausesBuilder.build();
    if (!rootCauses.isEmpty()) {
        eventBusRef.get().post(completor.createFailed(value, rootCauses));
        if (firstActionExecutionException != null) {
            throw new CompletionFunctionException(firstActionExecutionException);
        } else {
            throw new CompletionFunctionException(missingInputException);
        }
    }
    return env.valuesMissing() ? null : completor.createResult(value);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Label(com.google.devtools.build.lib.cmdline.Label) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) Artifact(com.google.devtools.build.lib.actions.Artifact) Cause(com.google.devtools.build.lib.causes.Cause) LabelCause(com.google.devtools.build.lib.causes.LabelCause) LabelCause(com.google.devtools.build.lib.causes.LabelCause) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) Map(java.util.Map) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException) Nullable(javax.annotation.Nullable)

Example 5 with TopLevelArtifactContext

use of com.google.devtools.build.lib.analysis.TopLevelArtifactContext 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

Artifact (com.google.devtools.build.lib.actions.Artifact)5 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)5 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 InputFileConfiguredTarget (com.google.devtools.build.lib.analysis.InputFileConfiguredTarget)2 OutputFileConfiguredTarget (com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)2 Label (com.google.devtools.build.lib.cmdline.Label)2 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)2 OutErr (com.google.devtools.build.lib.util.io.OutErr)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 Map (java.util.Map)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 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 ActionExecutionStatusReporter (com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1 ActionLogBufferPathGenerator (com.google.devtools.build.lib.actions.ActionLogBufferPathGenerator)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 Executor (com.google.devtools.build.lib.actions.Executor)1