use of com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy in project intellij by bazelbuild.
the class BuildPhaseSyncTask method doRun.
private void doRun(BlazeContext context) throws SyncFailedException, SyncCanceledException {
List<TargetExpression> targets = Lists.newArrayList();
ProjectViewSet viewSet = projectState.getProjectViewSet();
if (syncParams.addWorkingSet() && projectState.getWorkingSet() != null) {
Collection<TargetExpression> workingSetTargets = getWorkingSetTargets(context);
if (!workingSetTargets.isEmpty()) {
targets.addAll(workingSetTargets);
printTargets(context, "working set", workingSetTargets);
}
}
if (syncParams.addProjectViewTargets()) {
ProjectTargets projectTargets = SyncProjectTargetsHelper.getProjectTargets(project, context, viewSet, projectState.getWorkspacePathResolver(), projectState.getLanguageSettings());
if (!projectTargets.derivedTargets.isEmpty()) {
buildStats.setTargetsDerivedFromDirectories(true);
printTargets(context, "project view directories", projectTargets.derivedTargets);
}
if (!projectTargets.explicitTargets.isEmpty()) {
printTargets(context, "project view targets", projectTargets.explicitTargets);
}
targets.addAll(projectTargets.getTargetsToSync());
}
if (!syncParams.sourceFilesToSync().isEmpty()) {
Collection<TargetExpression> targetsFromSources = findTargetsBuildingSourceFiles(syncParams.sourceFilesToSync(), context);
if (!targetsFromSources.isEmpty()) {
targets.addAll(targetsFromSources);
printTargets(context, syncParams.title() + " (targets derived from query)", targetsFromSources);
}
}
if (!syncParams.targetExpressions().isEmpty()) {
targets.addAll(syncParams.targetExpressions());
printTargets(context, syncParams.title(), syncParams.targetExpressions());
}
buildStats.setTargets(targets);
notifyBuildStarted(context, syncParams.addProjectViewTargets(), ImmutableList.copyOf(targets));
BuildInvoker localInvoker = buildSystem.getBuildInvoker(project, context);
ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, viewSet, projectState.getWorkspacePathResolver(), targets, localInvoker, buildSystem.getSyncStrategy(project));
if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
throw new SyncFailedException();
}
ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
boolean parallel;
SyncStrategy strategy = buildSystem.getSyncStrategy(project);
switch(strategy) {
case PARALLEL:
parallel = true;
break;
case DECIDE_AUTOMATICALLY:
parallel = shardedTargets.shardCount() > 1;
break;
case SERIAL:
parallel = false;
break;
default:
throw new IllegalStateException("Invalid sync strategy: " + strategy);
}
if (!shardedTargetsResult.shardedTargets.shardStats().shardingApproach().equals(ShardingApproach.PARTITION_WITHOUT_EXPANDING)) {
int targetCount = shardedTargets.shardStats().actualTargetSizePerShard().stream().mapToInt(Integer::intValue).sum();
printShardingSummary(context, targetCount, shardedTargets.shardCount(), parallel);
}
BuildInvoker syncBuildInvoker = null;
if (parallel) {
syncBuildInvoker = buildSystem.getParallelBuildInvoker(project, context).orElse(null);
}
if (syncBuildInvoker == null) {
syncBuildInvoker = localInvoker;
}
resultBuilder.setBlazeInfo(syncBuildInvoker.getBlazeInfo());
buildStats.setSyncSharded(shardedTargets.shardCount() > 1).setShardCount(shardedTargets.shardCount()).setShardStats(shardedTargets.shardStats()).setParallelBuilds(syncBuildInvoker.supportsParallelism());
BlazeBuildOutputs blazeBuildResult = getBlazeBuildResult(context, viewSet, shardedTargets, syncBuildInvoker);
resultBuilder.setBuildResult(blazeBuildResult);
buildStats.setBuildResult(blazeBuildResult.buildResult).setBuildIds(blazeBuildResult.buildIds).setBuildBinaryType(syncBuildInvoker.getType()).setBepBytesConsumed(blazeBuildResult.bepBytesConsumed);
if (context.isCancelled()) {
throw new SyncCanceledException();
}
String invocationResultMsg = "Build invocation result: " + blazeBuildResult.buildResult.status;
if (blazeBuildResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
context.setHasError();
if (blazeBuildResult.buildResult.outOfMemory()) {
SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
}
context.output(PrintOutput.error(invocationResultMsg));
throw new SyncFailedException();
}
context.output(PrintOutput.log(invocationResultMsg));
}
Aggregations