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