use of com.google.idea.blaze.base.toolwindow.Task in project intellij by bazelbuild.
the class BlazeAndroidRunConfigurationRunner method executeBeforeRunTask.
@Override
public boolean executeBeforeRunTask(ExecutionEnvironment env) {
final Project project = env.getProject();
BlazeUserSettings settings = BlazeUserSettings.getInstance();
return Scope.root(context -> {
context.push(new ProblemsViewScope(project, settings.getShowProblemsViewOnRun())).push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(settings.getShowBlazeConsoleOnRun()).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.ContextType.BeforeRunTask, true)).build()).push(new ToolWindowScope.Builder(project, new Task(project, "Build apk", Task.Type.BEFORE_LAUNCH)).setPopupBehavior(settings.getShowBlazeConsoleOnRun()).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), ContextType.BeforeRunTask)).build()).push(new IdeaLogScope());
BlazeAndroidRunContext runContext = env.getCopyableUserData(RUN_CONTEXT_KEY);
if (runContext == null) {
IssueOutput.error("Could not find run context. Please try again").submit(context);
return false;
}
BlazeAndroidDeviceSelector.DeviceSession deviceSession = env.getCopyableUserData(DEVICE_SESSION_KEY);
ApkBuildStep buildStep = runContext.getBuildStep();
ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
buildStep.build(context, deviceSession);
return null;
}
};
try {
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project, String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
Futures.getChecked(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
} catch (Exception e) {
LOG.error(e);
return false;
}
return context.shouldContinue();
});
}
use of com.google.idea.blaze.base.toolwindow.Task in project intellij by bazelbuild.
the class FastBuildConfigurationRunner method executeBeforeRunTask.
@Override
public boolean executeBeforeRunTask(ExecutionEnvironment env) {
if (!canRun(env.getRunProfile())) {
return true;
}
Project project = env.getProject();
BlazeCommandRunConfiguration configuration = BlazeCommandRunConfigurationRunner.getBlazeConfig(env.getRunProfile());
BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
checkState(configuration.getSingleTarget() != null);
Label label = (Label) configuration.getSingleTarget();
String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath(project);
SaveUtil.saveAllFiles();
FastBuildService buildService = FastBuildService.getInstance(project);
Future<FastBuildInfo> buildFuture = null;
FocusBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getShowBlazeConsoleOnRun();
FocusBehavior problemsViewFocus = BlazeUserSettings.getInstance().getShowProblemsViewOnRun();
BlazeContext context = BlazeContext.create().push(new ToolWindowScope.Builder(project, new Task(project, "Fast Build " + label.targetName(), Task.Type.FAST_BUILD)).setPopupBehavior(consolePopupBehavior).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), ContextType.RunConfiguration)).build()).push(new ProblemsViewScope(project, problemsViewFocus)).push(new IdeaLogScope()).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), ContextType.RunConfiguration, /* linkToBlazeConsole= */
true)).build()).push(new FastBuildLogDataScope());
try {
buildFuture = buildService.createBuild(context, label, binaryPath, handlerState.getBlazeFlagsState().getFlagsForExternalProcesses());
FastBuildInfo fastBuildInfo = buildFuture.get();
env.getCopyableUserData(BUILD_INFO_KEY).set(fastBuildInfo);
env.getCopyableUserData(BLAZE_CONTEXT).set(context);
return true;
} catch (InterruptedException e) {
buildFuture.cancel(/* mayInterruptIfRunning= */
true);
Thread.currentThread().interrupt();
} catch (CancellationException e) {
ExecutionUtil.handleExecutionError(env.getProject(), env.getExecutor().getToolWindowId(), env.getRunProfile(), new RunCanceledByUserException());
} catch (FastBuildException e) {
if (!(e instanceof BlazeBuildError)) {
// no need to log blaze build errors; they're expected
logger.warn(e);
}
ExecutionUtil.handleExecutionError(env, new ExecutionException(e));
} catch (java.util.concurrent.ExecutionException e) {
logger.warn(e);
if (e.getCause() instanceof FastBuildIncrementalCompileException) {
handleJavacError(env, project, label, buildService, (FastBuildIncrementalCompileException) e.getCause());
} else {
ExecutionUtil.handleExecutionError(env, new ExecutionException(e.getCause()));
}
}
// Fall-through for all exceptions. If no exception was thrown, we return from the try{} block.
context.endScope();
return false;
}
use of com.google.idea.blaze.base.toolwindow.Task in project intellij by bazelbuild.
the class SyncPhaseCoordinator method queueUpdateTask.
private void queueUpdateTask(UpdatePhaseTask task, @Nullable ToolWindowScope syncToolWindowScope, BlazeSyncParams params) {
synchronized (this) {
if (pendingUpdateTask != null) {
// there's already a pending job, no need to kick off another one
pendingUpdateTask = UpdatePhaseTask.combineTasks(pendingUpdateTask, task);
return;
}
pendingUpdateTask = task;
}
Task toolWindowTask;
boolean startTaskOnScopeBegin;
if (syncToolWindowScope == null) {
toolWindowTask = new Task(params.title(), Task.Type.BLAZE_SYNC);
startTaskOnScopeBegin = true;
} else {
toolWindowTask = syncToolWindowScope.getTask();
syncToolWindowScope.setFinishTaskOnScopeEnd(false);
startTaskOnScopeBegin = false;
}
ProgressiveTaskWithProgressIndicator.builder(project, "Syncing Project").setExecutor(singleThreadedExecutor).submitTaskLater(indicator -> Scope.root(context -> {
UpdatePhaseTask updateTask = getAndClearPendingTask();
setupScopes(updateTask.syncParams(), context, indicator, SyncPhase.PROJECT_UPDATE, toolWindowTask, startTaskOnScopeBegin);
updateProjectAndFinishSync(updateTask, context);
}));
}
use of com.google.idea.blaze.base.toolwindow.Task 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.toolwindow.Task 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