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");
}
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);
}
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");
}
}
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;
}
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);
}
Aggregations