Search in sources :

Example 1 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class BuildView method createResult.

private AnalysisResult createResult(ExtendedEventHandler eventHandler, LoadingResult loadingResult, TopLevelArtifactContext topLevelOptions, BuildView.Options viewOptions, SkyframeAnalysisResult skyframeAnalysisResult) throws InterruptedException {
    Collection<Target> testsToRun = loadingResult.getTestsToRun();
    Collection<ConfiguredTarget> configuredTargets = skyframeAnalysisResult.getConfiguredTargets();
    Collection<AspectValue> aspects = skyframeAnalysisResult.getAspects();
    Collection<ConfiguredTarget> allTargetsToTest = null;
    if (testsToRun != null) {
        // Determine the subset of configured targets that are meant to be run as tests.
        // Do not remove <ConfiguredTarget>: workaround for Java 7 type inference.
        allTargetsToTest = Lists.<ConfiguredTarget>newArrayList(filterTestsByTargets(configuredTargets, Sets.newHashSet(testsToRun)));
    }
    Set<Artifact> artifactsToBuild = new HashSet<>();
    Set<ConfiguredTarget> parallelTests = new HashSet<>();
    Set<ConfiguredTarget> exclusiveTests = new HashSet<>();
    // build-info and build-changelist.
    Collection<Artifact> buildInfoArtifacts = skyframeExecutor.getWorkspaceStatusArtifacts(eventHandler);
    Preconditions.checkState(buildInfoArtifacts.size() == 2, buildInfoArtifacts);
    artifactsToBuild.addAll(buildInfoArtifacts);
    // Extra actions
    addExtraActionsIfRequested(viewOptions, configuredTargets, aspects, artifactsToBuild);
    // Coverage
    NestedSet<Artifact> baselineCoverageArtifacts = getBaselineCoverageArtifacts(configuredTargets);
    Iterables.addAll(artifactsToBuild, baselineCoverageArtifacts);
    if (coverageReportActionFactory != null) {
        CoverageReportActionsWrapper actionsWrapper;
        actionsWrapper = coverageReportActionFactory.createCoverageReportActionsWrapper(eventHandler, directories, allTargetsToTest, baselineCoverageArtifacts, getArtifactFactory(), CoverageReportValue.ARTIFACT_OWNER);
        if (actionsWrapper != null) {
            ImmutableList<ActionAnalysisMetadata> actions = actionsWrapper.getActions();
            skyframeExecutor.injectCoverageReportData(actions);
            artifactsToBuild.addAll(actionsWrapper.getCoverageOutputs());
        }
    }
    // Tests. This must come last, so that the exclusive tests are scheduled after everything else.
    scheduleTestsIfRequested(parallelTests, exclusiveTests, topLevelOptions, allTargetsToTest);
    String error = createErrorMessage(loadingResult, skyframeAnalysisResult);
    final WalkableGraph graph = skyframeAnalysisResult.getWalkableGraph();
    final ActionGraph actionGraph = new ActionGraph() {

        @Nullable
        @Override
        public ActionAnalysisMetadata getGeneratingAction(Artifact artifact) {
            ArtifactOwner artifactOwner = artifact.getArtifactOwner();
            if (artifactOwner instanceof ActionLookupValue.ActionLookupKey) {
                SkyKey key = ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner);
                ActionLookupValue val;
                try {
                    val = (ActionLookupValue) graph.getValue(key);
                } catch (InterruptedException e) {
                    throw new IllegalStateException("Interruption not expected from this graph: " + key, e);
                }
                return val == null ? null : val.getGeneratingAction(artifact);
            }
            return null;
        }
    };
    return new AnalysisResult(configuredTargets, aspects, allTargetsToTest, error, actionGraph, artifactsToBuild, parallelTests, exclusiveTests, topLevelOptions, skyframeAnalysisResult.getPackageRoots(), loadingResult.getWorkspaceName());
}
Also used : Target(com.google.devtools.build.lib.packages.Target) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SkyKey(com.google.devtools.build.skyframe.SkyKey) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) ActionGraph(com.google.devtools.build.lib.actions.ActionGraph) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Artifact(com.google.devtools.build.lib.actions.Artifact) SkyframeAnalysisResult(com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) CoverageReportActionsWrapper(com.google.devtools.build.lib.rules.test.CoverageReportActionFactory.CoverageReportActionsWrapper) ActionLookupValue(com.google.devtools.build.lib.skyframe.ActionLookupValue)

Example 2 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectAllowsFragmentsToBeSpecified.

@Test
public void aspectAllowsFragmentsToBeSpecified() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   print('This aspect does nothing')", "   return struct()", "MyAspect = aspect(implementation=_impl, fragments=['jvm'], host_fragments=['cpp'])");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    AspectValue aspectValue = Iterables.getOnlyElement(analysisResult.getAspects());
    AspectDefinition aspectDefinition = aspectValue.getAspect().getDefinition();
    assertThat(aspectDefinition.getConfigurationFragmentPolicy().isLegalConfigurationFragment(Jvm.class, ConfigurationTransition.NONE)).isTrue();
    assertThat(aspectDefinition.getConfigurationFragmentPolicy().isLegalConfigurationFragment(Jvm.class, ConfigurationTransition.HOST)).isFalse();
    assertThat(aspectDefinition.getConfigurationFragmentPolicy().isLegalConfigurationFragment(CppConfiguration.class, ConfigurationTransition.NONE)).isFalse();
    assertThat(aspectDefinition.getConfigurationFragmentPolicy().isLegalConfigurationFragment(CppConfiguration.class, ConfigurationTransition.HOST)).isTrue();
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) AspectDefinition(com.google.devtools.build.lib.packages.AspectDefinition) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 3 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectWithOutputGroups.

@Test
public void aspectWithOutputGroups() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   f = target.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", "   return struct(output_groups = { 'my_result' : f })", "", "MyAspect = aspect(", "   implementation=_impl,", ")");
    scratch.file("test/BUILD", "java_library(", "     name = 'xxx',", "     srcs = ['A.java'],", ")");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
    AspectValue aspectValue = analysisResult.getAspects().iterator().next();
    OutputGroupProvider outputGroupProvider = aspectValue.getConfiguredAspect().getProvider(OutputGroupProvider.class);
    assertThat(outputGroupProvider).isNotNull();
    NestedSet<Artifact> names = outputGroupProvider.getOutputGroup("my_result");
    assertThat(names).isNotEmpty();
    NestedSet<Artifact> expectedSet = getConfiguredTarget("//test:xxx").getProvider(OutputGroupProvider.class).getOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL);
    assertThat(names).containsExactlyElementsIn(expectedSet);
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 4 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue 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 5 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class TopLevelArtifactHelper method getAllArtifactsToBuildFromAspects.

/**
   * Utility function to form a NestedSet of all top-level Artifacts of the given targets.
   */
public static ArtifactsToBuild getAllArtifactsToBuildFromAspects(Iterable<AspectValue> aspects, TopLevelArtifactContext context) {
    NestedSetBuilder<ArtifactsInOutputGroup> artifacts = NestedSetBuilder.stableOrder();
    for (AspectValue aspect : aspects) {
        ArtifactsToBuild aspectArtifacts = getAllArtifactsToBuild(aspect, context);
        artifacts.addTransitive(aspectArtifacts.getAllArtifactsByOutputGroup());
    }
    return new ArtifactsToBuild(artifacts.build());
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue)

Aggregations

AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)7 Artifact (com.google.devtools.build.lib.actions.Artifact)6 Test (org.junit.Test)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 Label (com.google.devtools.build.lib.cmdline.Label)4 Nullable (javax.annotation.Nullable)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)3 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)3 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)2 InputFileConfiguredTarget (com.google.devtools.build.lib.analysis.InputFileConfiguredTarget)2 OutputFileConfiguredTarget (com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)2 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)2 OutErr (com.google.devtools.build.lib.util.io.OutErr)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Stopwatch (com.google.common.base.Stopwatch)1 EventBus (com.google.common.eventbus.EventBus)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1