Search in sources :

Example 1 with OutputGroupProvider

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

the class SkylarkAspectsTest method outputGroupsFromTwoAspects.

@Test
public void outputGroupsFromTwoAspects() throws Exception {
    scratch.file("test/aspect.bzl", "def _a1_impl(target, ctx):", "  f = ctx.new_file(target.label.name + '_a1.txt')", "  ctx.file_action(f, 'f')", "  return struct(output_groups = { 'a1_group' : depset([f]) })", "", "a1 = aspect(implementation=_a1_impl, attr_aspects = ['dep'])", "def _rule_impl(ctx):", "  if not ctx.attr.dep:", "     return struct()", "  og = {k:ctx.attr.dep.output_groups[k] for k in ctx.attr.dep.output_groups}", "  return struct(output_groups = og)", "my_rule1 = rule(_rule_impl, attrs = { 'dep' : attr.label(aspects = [a1]) })", "def _a2_impl(target, ctx):", "  g = ctx.new_file(target.label.name + '_a2.txt')", "  ctx.file_action(g, 'f')", "  return struct(output_groups = { 'a2_group' : depset([g]) })", "", "a2 = aspect(implementation=_a2_impl, attr_aspects = ['dep'])", "my_rule2 = rule(_rule_impl, attrs = { 'dep' : attr.label(aspects = [a2]) })");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'my_rule1', 'my_rule2')", "my_rule1(name = 'base')", "my_rule1(name = 'xxx', dep = ':base')", "my_rule2(name = 'yyy', dep = ':xxx')");
    AnalysisResult analysisResult = update("//test:yyy");
    OutputGroupProvider outputGroupProvider = Iterables.getOnlyElement(analysisResult.getTargetsToBuild()).getProvider(OutputGroupProvider.class);
    assertThat(getOutputGroupContents(outputGroupProvider, "a1_group")).containsExactly("test/base_a1.txt");
    assertThat(getOutputGroupContents(outputGroupProvider, "a2_group")).containsExactly("test/xxx_a2.txt");
}
Also used : OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 2 with OutputGroupProvider

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

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

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

the class AndroidStudioInfoAspectTestBase method getOutputGroupResult.

protected List<String> getOutputGroupResult(String outputGroup) {
    OutputGroupProvider outputGroupProvider = this.configuredAspect.getProvider(OutputGroupProvider.class);
    assert outputGroupProvider != null;
    NestedSet<Artifact> artifacts = outputGroupProvider.getOutputGroup(outputGroup);
    for (Artifact artifact : artifacts) {
        if (artifact.isSourceArtifact()) {
            continue;
        }
        assertWithMessage("Artifact %s has no generating action", artifact).that(getGeneratingAction(artifact)).isNotNull();
    }
    List<String> artifactRelativePaths = Lists.newArrayList();
    for (Artifact artifact : artifacts) {
        artifactRelativePaths.add(artifact.getRootRelativePathString());
    }
    return artifactRelativePaths;
}
Also used : OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)

Example 5 with OutputGroupProvider

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

the class SkylarkAspectsTest method aspectWithOutputGroupsAsList.

@Test
public void aspectWithOutputGroupsAsList() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   g = target.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", "   return struct(output_groups = { 'my_result' : [ f for f in g] })", "", "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(transform(analysisResult.getTargetsToBuild(), new Function<ConfiguredTarget, String>() {

        @Nullable
        @Override
        public String apply(ConfiguredTarget configuredTarget) {
            return configuredTarget.getLabel().toString();
        }
    })).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) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Nullable(javax.annotation.Nullable) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Aggregations

OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)8 Artifact (com.google.devtools.build.lib.actions.Artifact)7 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)3 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)3 LibraryArtifact (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)3 Test (org.junit.Test)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 Builder (com.google.devtools.build.lib.analysis.ConfiguredAspect.Builder)1 InputFileConfiguredTarget (com.google.devtools.build.lib.analysis.InputFileConfiguredTarget)1 OutputFileConfiguredTarget (com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)1 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)1 Label (com.google.devtools.build.lib.cmdline.Label)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 ExecutionOptions (com.google.devtools.build.lib.exec.ExecutionOptions)1 OutErr (com.google.devtools.build.lib.util.io.OutErr)1 PyIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.PyIdeInfo)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1