Search in sources :

Example 1 with FocusBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior 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, BuildSystem buildSystem) {
    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(project, taskName, Task.Type.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;
            }
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
            SaveUtil.saveAllFiles();
            BlazeBuildListener.EP_NAME.extensions().forEach(e -> e.buildStarting(project));
            BuildInvoker buildInvoker = buildSystem.getBuildInvoker(project, context);
            ShardedTargetsResult shardedTargets = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectView, projectData.getWorkspacePathResolver(), targets, buildInvoker, SyncStrategy.SERIAL);
            if (shardedTargets.buildResult.status == BuildResult.Status.FATAL_ERROR) {
                return null;
            }
            BlazeBuildOutputs buildOutputs = BlazeIdeInterface.getInstance().build(project, context, workspaceRoot, projectData.getBlazeVersionData(), buildInvoker, projectView, shardedTargets.shardedTargets, projectData.getWorkspaceLanguageSettings(), ImmutableSet.of(OutputGroup.COMPILE), BlazeInvocationContext.OTHER_CONTEXT);
            refreshFileCachesAndNotifyListeners(context, buildOutputs, project);
            if (buildOutputs.buildResult.status != BuildResult.Status.SUCCESS) {
                context.setHasError();
            }
            return null;
        }
    });
}
Also used : BlazeIdeInterface(com.google.idea.blaze.base.sync.aspects.BlazeIdeInterface) ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) ImmutableCollection(com.google.common.collect.ImmutableCollection) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) Task(com.google.idea.blaze.base.toolwindow.Task) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) BuildSystem(com.google.idea.blaze.base.bazel.BuildSystem) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableSet(com.google.common.collect.ImmutableSet) BuildInvoker(com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) List(java.util.List) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) ServiceManager(com.intellij.openapi.components.ServiceManager) FileCaches(com.google.idea.blaze.base.filecache.FileCaches) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ToolWindowScope(com.google.idea.blaze.base.scope.scopes.ToolWindowScope) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) NotificationScope(com.google.idea.blaze.base.scope.scopes.NotificationScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) Lists(com.google.common.collect.Lists) OutputGroup(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup) SyncProjectTargetsHelper(com.google.idea.blaze.base.sync.SyncProjectTargetsHelper) Project(com.intellij.openapi.project.Project) BlazeBuildTargetSharder(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder) Nullable(javax.annotation.Nullable) Key(com.intellij.openapi.util.Key) FutureCallback(com.google.common.util.concurrent.FutureCallback) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) Futures(com.google.common.util.concurrent.Futures) SyncStrategy(com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeIssueParser(com.google.idea.blaze.base.issueparser.BlazeIssueParser) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) Task(com.google.idea.blaze.base.toolwindow.Task) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) BuildInvoker(com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker) List(java.util.List)

Example 2 with FocusBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior 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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) Task(com.google.idea.blaze.base.toolwindow.Task) Label(com.google.idea.blaze.base.model.primitives.Label) FastBuildService(com.google.idea.blaze.java.fastbuild.FastBuildService) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) FastBuildLogDataScope(com.google.idea.blaze.java.fastbuild.FastBuildLogDataScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) FastBuildException(com.google.idea.blaze.java.fastbuild.FastBuildException) ExecutionException(com.intellij.execution.ExecutionException) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) FastBuildIncrementalCompileException(com.google.idea.blaze.java.fastbuild.FastBuildIncrementalCompileException) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) Project(com.intellij.openapi.project.Project) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) FastBuildInfo(com.google.idea.blaze.java.fastbuild.FastBuildInfo) ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) CancellationException(java.util.concurrent.CancellationException) BlazeBuildError(com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError)

Example 3 with FocusBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior 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;
        }
    });
}
Also used : BlazeIdeInterface(com.google.idea.blaze.base.sync.aspects.BlazeIdeInterface) ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) ImmutableCollection(com.google.common.collect.ImmutableCollection) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) BlazeBuildParams(com.google.idea.blaze.base.sync.BlazeBuildParams) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) Task(com.google.idea.blaze.base.toolwindow.Task) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableSet(com.google.common.collect.ImmutableSet) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) List(java.util.List) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) ServiceManager(com.intellij.openapi.components.ServiceManager) FileCaches(com.google.idea.blaze.base.filecache.FileCaches) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ToolWindowScope(com.google.idea.blaze.base.scope.scopes.ToolWindowScope) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) NotificationScope(com.google.idea.blaze.base.scope.scopes.NotificationScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) Lists(com.google.common.collect.Lists) OutputGroup(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup) SyncProjectTargetsHelper(com.google.idea.blaze.base.sync.SyncProjectTargetsHelper) Project(com.intellij.openapi.project.Project) BlazeBuildTargetSharder(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder) Nullable(javax.annotation.Nullable) Key(com.intellij.openapi.util.Key) FutureCallback(com.google.common.util.concurrent.FutureCallback) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) Futures(com.google.common.util.concurrent.Futures) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeIssueParser(com.google.idea.blaze.base.issueparser.BlazeIssueParser) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) BlazeBuildParams(com.google.idea.blaze.base.sync.BlazeBuildParams) ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) Task(com.google.idea.blaze.base.toolwindow.Task) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) List(java.util.List)

Aggregations

IssueOutputFilter (com.google.idea.blaze.base.issueparser.IssueOutputFilter)3 Label (com.google.idea.blaze.base.model.primitives.Label)3 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)3 BlazeConsoleScope (com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope)3 IdeaLogScope (com.google.idea.blaze.base.scope.scopes.IdeaLogScope)3 ProblemsViewScope (com.google.idea.blaze.base.scope.scopes.ProblemsViewScope)3 FocusBehavior (com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior)3 ImmutableCollection (com.google.common.collect.ImmutableCollection)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ProgressiveTaskWithProgressIndicator (com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator)2 BlazeInvocationContext (com.google.idea.blaze.base.command.BlazeInvocationContext)2 ExperimentScope (com.google.idea.blaze.base.experiments.ExperimentScope)2 FileCaches (com.google.idea.blaze.base.filecache.FileCaches)2 BlazeIssueParser (com.google.idea.blaze.base.issueparser.BlazeIssueParser)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2