Search in sources :

Example 1 with BlazeBuildError

use of com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError in project intellij by bazelbuild.

the class FastBuildServiceImpl method buildDeployJar.

private FastBuildState.BuildOutput buildDeployJar(BlazeContext context, Label label, FastBuildParameters buildParameters, BuildResultHelper resultHelper) {
    Label deployJarLabel = createDeployJarLabel(label);
    context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
    BlazeInfo blazeInfo = getBlazeInfo(context, buildParameters);
    FastBuildAspectStrategy aspectStrategy = FastBuildAspectStrategy.getInstance(Blaze.getBuildSystemName(project));
    Stopwatch timer = Stopwatch.createStarted();
    BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.buildFlags()).addBlazeFlags(resultHelper.getBuildFlags());
    aspectStrategy.addAspectAndOutputGroups(command, /* additionalOutputGroups...= */
    "default");
    int exitCode = ExternalTask.builder(WorkspaceRoot.fromProject(project)).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
    BuildResult result = BuildResult.fromExitCode(exitCode);
    context.output(FastBuildLogOutput.keyValue("deploy_jar_build_result", result.status.toString()));
    context.output(FastBuildLogOutput.milliseconds("deploy_jar_build_time_ms", timer));
    if (result.status != Status.SUCCESS) {
        throw new FastBuildTunnelException(new BlazeBuildError("Blaze failure building deploy jar"));
    }
    Predicate<String> filePredicate = file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file);
    try {
        ImmutableList<File> deployJarArtifacts = BlazeArtifact.getLocalFiles(resultHelper.getBuildArtifactsForTarget(deployJarLabel, filePredicate));
        checkState(deployJarArtifacts.size() == 1);
        File deployJar = deployJarArtifacts.get(0);
        ImmutableList<File> ideInfoFiles = BlazeArtifact.getLocalFiles(resultHelper.getArtifactsForOutputGroup(aspectStrategy.getAspectOutputGroup(), filePredicate));
        // if targets are built with multiple configurations, just take the first one
        // TODO(brendandouglas): choose a consistent configuration instead
        ImmutableMap<Label, FastBuildBlazeData> blazeData = ideInfoFiles.stream().map(aspectStrategy::readFastBuildBlazeData).collect(toImmutableMap(FastBuildBlazeData::label, i -> i, (i, j) -> i));
        return BuildOutput.create(deployJar, blazeData, blazeInfo);
    } catch (GetArtifactsException e) {
        throw new RuntimeException("Blaze failure building deploy jar: " + e.getMessage());
    }
}
Also used : ExternalTask(com.google.idea.blaze.base.async.process.ExternalTask) BlazeInfoRunner(com.google.idea.blaze.base.command.info.BlazeInfoRunner) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) AndroidBlazeRules(com.google.idea.blaze.java.AndroidBlazeRules) GetArtifactsException(com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) Future(java.util.concurrent.Future) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) FileUtil(com.intellij.openapi.util.io.FileUtil) ProjectComponent(com.intellij.openapi.components.ProjectComponent) ChangedSources(com.google.idea.blaze.java.fastbuild.FastBuildChangedFilesService.ChangedSources) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BlazeConsoleLineProcessorProvider(com.google.idea.blaze.base.console.BlazeConsoleLineProcessorProvider) Blaze(com.google.idea.blaze.base.settings.Blaze) BuildOutput(com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput) ImmutableMap(com.google.common.collect.ImmutableMap) CancellationException(java.util.concurrent.CancellationException) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) Set(java.util.Set) BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) FastBuildLogOutput(com.google.idea.blaze.java.fastbuild.FastBuildLogDataScope.FastBuildLogOutput) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) Status(com.google.idea.blaze.base.sync.aspects.BuildResult.Status) BlazeBuildError(com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError) BuildResultHelperProvider(com.google.idea.blaze.base.command.buildresult.BuildResultHelperProvider) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Stopwatch(com.google.common.base.Stopwatch) BlazeCommandRunConfigurationType(com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) Kind(com.google.idea.blaze.base.model.primitives.Kind) ImmutableList(com.google.common.collect.ImmutableList) Project(com.intellij.openapi.project.Project) Nullable(javax.annotation.Nullable) Files(java.nio.file.Files) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) JavaBlazeRules(com.google.idea.blaze.java.JavaBlazeRules) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) ExecutorType(com.google.idea.blaze.base.run.ExecutorType) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeFlags(com.google.idea.blaze.base.command.BlazeFlags) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Label(com.google.idea.blaze.base.model.primitives.Label) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) Stopwatch(com.google.common.base.Stopwatch) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) GetArtifactsException(com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException) BlazeBuildError(com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError) File(java.io.File)

Example 2 with BlazeBuildError

use of com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError 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)

Aggregations

Label (com.google.idea.blaze.base.model.primitives.Label)2 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)1 ProgressiveTaskWithProgressIndicator (com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator)1 ExternalTask (com.google.idea.blaze.base.async.process.ExternalTask)1 LineProcessingOutputStream (com.google.idea.blaze.base.async.process.LineProcessingOutputStream)1 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)1 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)1 BlazeFlags (com.google.idea.blaze.base.command.BlazeFlags)1 BlazeInvocationContext (com.google.idea.blaze.base.command.BlazeInvocationContext)1