use of com.google.idea.blaze.base.sync.BlazeBuildParams in project intellij by bazelbuild.
the class BlazeBuildTargetSharder method doExpandWildcardTargets.
private static ExpandedTargetsResult doExpandWildcardTargets(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, BlazeBuildParams buildParams, ProjectViewSet projectViewSet, WorkspacePathResolver pathResolver, List<TargetExpression> targets) {
List<WildcardTargetPattern> includes = getWildcardPatterns(targets);
if (includes.isEmpty()) {
return new ExpandedTargetsResult(targets, BuildResult.SUCCESS);
}
Map<TargetExpression, List<TargetExpression>> expandedTargets = WildcardTargetExpander.expandToNonRecursiveWildcardTargets(project, context, pathResolver, includes);
if (expandedTargets == null) {
return new ExpandedTargetsResult(ImmutableList.of(), BuildResult.FATAL_ERROR);
}
// replace original recursive targets with expanded list, retaining relative ordering
List<TargetExpression> fullList = new ArrayList<>();
for (TargetExpression target : targets) {
List<TargetExpression> expanded = expandedTargets.get(target);
if (expanded == null) {
fullList.add(target);
} else {
fullList.addAll(expanded);
}
}
ExpandedTargetsResult result = WildcardTargetExpander.expandToSingleTargets(project, context, workspaceRoot, buildParams, projectViewSet, fullList);
// finally add back any explicitly-specified, unexcluded single targets which may have been
// removed by the query (for example, because they have the 'manual' tag)
TargetExpressionList helper = TargetExpressionList.create(targets);
List<TargetExpression> singleTargets = targets.stream().filter(t -> !t.isExcluded()).filter(t -> !isWildcardPattern(t)).filter(t -> t instanceof Label).filter(t -> helper.includesTarget((Label) t)).collect(toImmutableList());
return ExpandedTargetsResult.merge(result, new ExpandedTargetsResult(singleTargets, result.buildResult));
}
use of com.google.idea.blaze.base.sync.BlazeBuildParams in project intellij by bazelbuild.
the class BlazeBuildService method buildTargetExpressions.
private static void buildTargetExpressions(Project project, ProjectViewSet projectView, BlazeProjectData projectData, ScopedFunction<List<TargetExpression>> targetsFunction, NotificationScope notificationScope, String taskName) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
// this never being called *and* relied on PROJECT_LAST_BUILD_TIMESTAMP_KEY being set
return;
}
FocusBehavior problemsViewFocus = BlazeUserSettings.getInstance().getShowProblemsViewOnRun();
// go/futurereturn-lsc
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = ProgressiveTaskWithProgressIndicator.builder(project, "Building targets").submitTaskWithResult(new ScopedTask<Void>() {
@Override
public Void execute(BlazeContext context) {
Task task = new Task(taskName, Task.Type.BLAZE_MAKE);
context.push(new ToolWindowScope.Builder(project, task).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.ContextType.Sync)).build()).push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.ContextType.Sync, true)).build()).push(new ProblemsViewScope(project, problemsViewFocus)).push(new IdeaLogScope()).push(new TimingScope("Make", EventType.BlazeInvocation)).push(notificationScope);
List<TargetExpression> targets = targetsFunction.execute(context);
if (targets == null) {
return null;
}
BlazeBuildParams buildParams = BlazeBuildParams.fromProject(project);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
SaveUtil.saveAllFiles();
BlazeBuildListener.EP_NAME.extensions().forEach(e -> e.buildStarting(project));
ShardedTargetsResult shardedTargets = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, buildParams, projectView, projectData.getWorkspacePathResolver(), targets);
if (shardedTargets.buildResult.status == BuildResult.Status.FATAL_ERROR) {
return null;
}
BlazeBuildOutputs buildOutputs = BlazeIdeInterface.getInstance().build(project, context, workspaceRoot, projectData.getBlazeVersionData(), buildParams, projectView, projectData.getBlazeInfo(), shardedTargets.shardedTargets, projectData.getWorkspaceLanguageSettings(), ImmutableSet.of(OutputGroup.COMPILE));
refreshFileCachesAndNotifyListeners(context, buildOutputs, project);
if (buildOutputs.buildResult.status != BuildResult.Status.SUCCESS) {
context.setHasError();
}
return null;
}
});
}
use of com.google.idea.blaze.base.sync.BlazeBuildParams in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method build.
@Override
public BlazeBuildOutputs build(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, BlazeVersionData blazeVersion, BlazeBuildParams buildParams, ProjectViewSet projectViewSet, BlazeInfo blazeInfo, ShardedTargetList shardedTargets, WorkspaceLanguageSettings workspaceLanguageSettings, ImmutableSet<OutputGroup> outputGroups) {
AspectStrategy aspectStrategy = AspectStrategy.getInstance(blazeVersion);
final Ref<BlazeBuildOutputs> combinedResult = new Ref<>();
boolean parallelize = buildParams.parallelizeBuilds();
// The build is a sync iff INFO output group is present
boolean isSync = outputGroups.contains(OutputGroup.INFO);
Function<Integer, String> progressMessage = count -> String.format("Building targets for shard %s of %s...", count, shardedTargets.shardCount());
final ShardedBuildProgressTracker progressTracker = new ShardedBuildProgressTracker(shardedTargets.shardCount());
BiFunction<List<? extends TargetExpression>, Integer, BuildResult> invocation = (targets, shard) -> Scope.push(context, (childContext) -> {
setupToolWindow(project, context, childContext, workspaceRoot, "Build shard " + shard, isSync);
// we use context (rather than childContext) here since the shard state relates
// to the parent task (which encapsulates all the build shards).
progressTracker.onBuildStarted(context);
BlazeBuildOutputs result = runBuildForTargets(project, childContext, workspaceRoot, buildParams, projectViewSet, blazeInfo, workspaceLanguageSettings.getActiveLanguages(), targets, aspectStrategy, outputGroups);
// TODO(b/216104482) track failures
progressTracker.onBuildCompleted(context);
if (!result.buildResult.outOfMemory()) {
combinedResult.set(combinedResult.isNull() ? result : combinedResult.get().updateOutputs(result));
}
return result.buildResult;
});
BuildResult buildResult = shardedTargets.runShardedCommand(project, context, progressMessage, invocation, parallelize);
if (combinedResult.isNull() || buildResult.status == Status.FATAL_ERROR) {
return BlazeBuildOutputs.noOutputs(buildResult);
}
return combinedResult.get();
}
Aggregations