use of com.google.idea.blaze.base.sync.aspects.BuildResult in project intellij by bazelbuild.
the class BlazeBuildService method buildTargetExpressions.
@VisibleForTesting
void buildTargetExpressions(Project project, List<TargetExpression> targets, ProjectViewSet projectViewSet, NotificationScope notificationScope) {
if (targets.isEmpty() || projectViewSet == null) {
return;
}
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return;
}
// go/futurereturn-lsc
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = ProgressiveTaskWithProgressIndicator.builder(project).setTitle("Building targets").submitTaskWithResult(new ScopedTask<Void>() {
@Override
public Void execute(BlazeContext context) {
context.push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.Sync, true)).build()).push(new IssuesScope(project, true)).push(new IdeaLogScope()).push(new TimingScope("Make", EventType.BlazeInvocation)).push(notificationScope);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
SaveUtil.saveAllFiles();
ShardedTargetsResult shardedTargets = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, blazeProjectData.workspacePathResolver, targets);
if (shardedTargets.buildResult.status == BuildResult.Status.FATAL_ERROR) {
return null;
}
BuildResult buildResult = BlazeIdeInterface.getInstance().compileIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeProjectData.blazeVersionData, blazeProjectData.workspaceLanguageSettings, shardedTargets.shardedTargets);
FileCaches.refresh(project);
if (buildResult.status != BuildResult.Status.SUCCESS) {
context.setHasError();
}
return null;
}
});
}
use of com.google.idea.blaze.base.sync.aspects.BuildResult in project intellij by bazelbuild.
the class ShardedTargetList method runShardedCommand.
/**
* Runs the provided blaze invocation on each target list shard, returning the combined {@link
* BuildResult}. Attempts to work around out of memory errors caused by lack of blaze garbage
* collection where possible.
*/
public BuildResult runShardedCommand(Project project, BlazeContext context, Function<Integer, String> progressMessage, Function<List<TargetExpression>, BuildResult> invocation) {
if (isEmpty()) {
return BuildResult.SUCCESS;
}
if (shardedTargets.size() == 1) {
return invocation.apply(shardedTargets.get(0));
}
int progress = 0;
BuildResult output = null;
for (int i = 0; i < shardedTargets.size(); i++, progress++) {
context.output(new StatusOutput(progressMessage.apply(i + 1)));
BuildResult result = invocation.apply(shardedTargets.get(i));
if (result.outOfMemory() && progress > 0) {
// re-try now that blaze server has restarted
progress = 0;
IssueOutput.warn(retryOnOomMessage(project, i)).submit(context);
result = invocation.apply(shardedTargets.get(i));
}
output = output == null ? result : BuildResult.combine(output, result);
if (output.status == BuildResult.Status.FATAL_ERROR) {
return output;
}
}
return output;
}
use of com.google.idea.blaze.base.sync.aspects.BuildResult in project intellij by bazelbuild.
the class WildcardTargetExpander method queryIndividualTargets.
/**
* Runs a blaze query to expand the input target patterns to individual blaze targets.
*/
private static ExpandedTargetsResult queryIndividualTargets(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ImmutableSet<String> handledRuleTypes, List<TargetExpression> targetPatterns) {
String query = queryString(targetPatterns);
if (query.isEmpty()) {
// will be empty if there are no non-excluded targets
return new ExpandedTargetsResult(ImmutableList.of(), BuildResult.SUCCESS);
}
BlazeCommand.Builder builder = BlazeCommand.builder(getBinaryPath(project), BlazeCommandName.QUERY).addBlazeFlags(BlazeFlags.KEEP_GOING).addBlazeFlags("--output=label_kind").addBlazeFlags(queryString(targetPatterns));
ImmutableList.Builder<TargetExpression> output = ImmutableList.builder();
// it's fine to include wildcards here; they're guaranteed not to clash with actual labels.
Set<String> explicitTargets = targetPatterns.stream().map(TargetExpression::toString).collect(Collectors.toSet());
Predicate<RuleTypeAndLabel> filter = !filterByRuleType.getValue() ? t -> true : t -> handledRuleTypes.contains(t.ruleType) || explicitTargets.contains(t.label);
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(builder.build()).context(context).stdout(LineProcessingOutputStream.of(new QueryResultLineProcessor(output, filter))).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
BuildResult buildResult = BuildResult.fromExitCode(retVal);
return new ExpandedTargetsResult(output.build(), buildResult);
}
use of com.google.idea.blaze.base.sync.aspects.BuildResult in project intellij by bazelbuild.
the class FastBuildServiceImpl method buildDeployJar.
private ListenableFuture<FastBuildState.BuildOutput> buildDeployJar(Label label, FastBuildParameters buildParameters) {
Label deployJarLabel = createDeployJarLabel(label);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
// TODO(plumpy): this assumes we're running this build as part of a run action. I try not to
// make that assumption anywhere else, so this should be supplied by the caller.
BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
AspectStrategy aspectStrategy = AspectStrategyProvider.findAspectStrategy(projectDataManager.getBlazeProjectData().blazeVersionData);
BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file));
ListenableFuture<BuildResult> buildResultFuture = ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {
@Override
protected BuildResult execute(BlazeContext context) {
context.push(new IssuesScope(project, /* focusProblemsViewOnIssue */
true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.blazeFlags()).addBlazeFlags(buildResultHelper.getBuildFlags());
List<String> outputGroups = new ArrayList<>();
// needed to retrieve the deploy jar
outputGroups.add("default");
outputGroups.addAll(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
aspectStrategy.addAspectAndOutputGroups(command, outputGroups);
int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
return BuildResult.fromExitCode(exitCode);
}
});
ListenableFuture<BuildOutput> buildOutputFuture = transform(buildResultFuture, result -> {
if (result.status != Status.SUCCESS) {
throw new RuntimeException("Blaze failure building deploy jar");
}
ImmutableList<File> deployJarArtifacts = buildResultHelper.getBuildArtifactsForTarget(deployJarLabel);
checkState(deployJarArtifacts.size() == 1);
File deployJar = deployJarArtifacts.get(0);
ImmutableList<File> ideInfoFiles = buildResultHelper.getArtifactsForOutputGroups(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
ImmutableMap<TargetKey, TargetIdeInfo> targetMap = ideInfoFiles.stream().map(file -> readTargetIdeInfo(aspectStrategy, file)).filter(Objects::nonNull).collect(toImmutableMap(ideInfo -> ideInfo.key, i -> i));
return BuildOutput.create(deployJar, new TargetMap(targetMap));
}, ConcurrencyUtil.getAppExecutorService());
buildOutputFuture.addListener(buildResultHelper::close, ConcurrencyUtil.getAppExecutorService());
return buildOutputFuture;
}
use of com.google.idea.blaze.base.sync.aspects.BuildResult in project intellij by bazelbuild.
the class BlazePyRunConfigurationRunner method getExecutableToDebug.
/**
* Builds blaze python target and returns the output build artifact.
*
* @throws ExecutionException if the target cannot be debugged.
*/
private static File getExecutableToDebug(ExecutionEnvironment env) throws ExecutionException {
BlazeCommandRunConfiguration configuration = getConfiguration(env);
Project project = configuration.getProject();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
throw new ExecutionException("Not synced yet, please sync project");
}
String validationError = BlazePyDebugHelper.validateDebugTarget(env.getProject(), configuration.getTarget());
if (validationError != null) {
throw new WithBrowserHyperlinkExecutionException(validationError);
}
try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, BlazePyDebugHelper.getAllBlazeDebugFlags(Blaze.getBuildSystem(project)), ImmutableList.of(), "Building debug binary");
try {
SaveUtil.saveAllFiles();
BuildResult result = buildOperation.get();
if (result.status != BuildResult.Status.SUCCESS) {
throw new ExecutionException("Blaze failure building debug binary");
}
} catch (InterruptedException | CancellationException e) {
buildOperation.cancel(true);
throw new RunCanceledByUserException();
} catch (java.util.concurrent.ExecutionException e) {
throw new ExecutionException(e);
}
List<File> candidateFiles = buildResultHelper.getBuildArtifactsForTarget((Label) configuration.getTarget()).stream().filter(File::canExecute).collect(Collectors.toList());
if (candidateFiles.isEmpty()) {
throw new ExecutionException(String.format("No output artifacts found when building %s", configuration.getTarget()));
}
File file = findExecutable((Label) configuration.getTarget(), candidateFiles);
if (file == null) {
throw new ExecutionException(String.format("More than 1 executable was produced when building %s; " + "don't know which one to debug", configuration.getTarget()));
}
LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
return file;
}
}
Aggregations