Search in sources :

Example 6 with RunCanceledByUserException

use of com.intellij.execution.RunCanceledByUserException in project intellij by bazelbuild.

the class BlazePyRunConfigurationRunner method getExecutableToDebug.

/**
 * Builds blaze python target and returns the output build artifact.
 *
 * @throws ExecutionException if the target cannot be debugged.
 */
private static File getExecutableToDebug(ExecutionEnvironment env) throws ExecutionException {
    BlazeCommandRunConfiguration configuration = getConfiguration(env);
    Project project = configuration.getProject();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        throw new ExecutionException("Not synced yet, please sync project");
    }
    String validationError = BlazePyDebugHelper.validateDebugTarget(env.getProject(), configuration.getTarget());
    if (validationError != null) {
        throw new WithBrowserHyperlinkExecutionException(validationError);
    }
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
        ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, BlazePyDebugHelper.getAllBlazeDebugFlags(Blaze.getBuildSystem(project)), ImmutableList.of(), "Building debug binary");
        try {
            SaveUtil.saveAllFiles();
            BuildResult result = buildOperation.get();
            if (result.status != BuildResult.Status.SUCCESS) {
                throw new ExecutionException("Blaze failure building debug binary");
            }
        } catch (InterruptedException | CancellationException e) {
            buildOperation.cancel(true);
            throw new RunCanceledByUserException();
        } catch (java.util.concurrent.ExecutionException e) {
            throw new ExecutionException(e);
        }
        List<File> candidateFiles = buildResultHelper.getBuildArtifactsForTarget((Label) configuration.getTarget()).stream().filter(File::canExecute).collect(Collectors.toList());
        if (candidateFiles.isEmpty()) {
            throw new ExecutionException(String.format("No output artifacts found when building %s", configuration.getTarget()));
        }
        File file = findExecutable((Label) configuration.getTarget(), candidateFiles);
        if (file == null) {
            throw new ExecutionException(String.format("More than 1 executable was produced when building %s; " + "don't know which one to debug", configuration.getTarget()));
        }
        LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
        return file;
    }
}
Also used : WithBrowserHyperlinkExecutionException(com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException) Label(com.google.idea.blaze.base.model.primitives.Label) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionException(com.intellij.execution.ExecutionException) WithBrowserHyperlinkExecutionException(com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

Example 7 with RunCanceledByUserException

use of com.intellij.execution.RunCanceledByUserException in project intellij by bazelbuild.

the class BlazeCidrRunConfigurationRunner method getExecutableToDebug.

/**
 * Builds blaze C/C++ target in debug mode, and returns the output build artifact.
 *
 * @throws ExecutionException if no unique output artifact was found.
 */
private File getExecutableToDebug() throws ExecutionException {
    BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true);
    ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, ImmutableList.of("-c", "dbg", "--copt=-O0", "--copt=-g", "--strip=never"), ImmutableList.of("--dynamic_mode=off"), "Building debug binary");
    try {
        SaveUtil.saveAllFiles();
        BuildResult result = buildOperation.get();
        if (result.status != BuildResult.Status.SUCCESS) {
            throw new ExecutionException("Blaze failure building debug binary");
        }
    } catch (InterruptedException | CancellationException e) {
        buildOperation.cancel(true);
        throw new RunCanceledByUserException();
    } catch (java.util.concurrent.ExecutionException e) {
        throw new ExecutionException(e);
    }
    List<File> candidateFiles = buildResultHelper.getBuildArtifactsForTarget((Label) configuration.getTarget()).stream().filter(File::canExecute).collect(Collectors.toList());
    if (candidateFiles.isEmpty()) {
        throw new ExecutionException(String.format("No output artifacts found when building %s", configuration.getTarget()));
    }
    File file = findExecutable((Label) configuration.getTarget(), candidateFiles);
    if (file == null) {
        throw new ExecutionException(String.format("More than 1 executable was produced when building %s; don't know which one to debug", configuration.getTarget()));
    }
    LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
    return file;
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 8 with RunCanceledByUserException

use of com.intellij.execution.RunCanceledByUserException in project intellij by bazelbuild.

the class ClassFileManifestBuilder method buildManifest.

/**
 * Builds a .class file manifest, then diffs against any previously calculated manifest for this
 * debugging session.
 *
 * @return null if no diff is available (either no manifest could be calculated, or no previously
 *     calculated manifest is available.
 */
@Nullable
public static ClassFileManifest.Diff buildManifest(ExecutionEnvironment env, @Nullable HotSwapProgress progress) throws ExecutionException {
    if (!HotSwapUtils.canHotSwap(env)) {
        return null;
    }
    BlazeCommandRunConfiguration configuration = getConfiguration(env);
    Project project = configuration.getProject();
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        throw new ExecutionException("Not synced yet; please sync project");
    }
    JavaClasspathAspectStrategy aspectStrategy = JavaClasspathAspectStrategy.findStrategy(projectData.blazeVersionData);
    if (aspectStrategy == null) {
        return null;
    }
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
        ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, aspectStrategy.getBuildFlags(), ImmutableList.of(), "Building debug binary");
        if (progress != null) {
            progress.setCancelWorker(() -> buildOperation.cancel(true));
        }
        try {
            SaveUtil.saveAllFiles();
            BuildResult result = buildOperation.get();
            if (result.status != BuildResult.Status.SUCCESS) {
                throw new ExecutionException("Blaze failure building debug binary");
            }
        } catch (InterruptedException | CancellationException e) {
            buildOperation.cancel(true);
            throw new RunCanceledByUserException();
        } catch (java.util.concurrent.ExecutionException e) {
            throw new ExecutionException(e);
        }
        ImmutableList<File> jars = buildResultHelper.getArtifactsForOutputGroups(ImmutableSet.of(JavaClasspathAspectStrategy.OUTPUT_GROUP)).stream().filter(f -> f.getName().endsWith(".jar")).collect(toImmutableList());
        ClassFileManifest oldManifest = getManifest(env);
        ClassFileManifest newManifest = ClassFileManifest.build(jars, oldManifest);
        env.getCopyableUserData(MANIFEST_KEY).set(newManifest);
        return oldManifest != null ? ClassFileManifest.modifiedClasses(oldManifest, newManifest) : null;
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) RunProfile(com.intellij.execution.configurations.RunProfile) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) WrappingRunConfiguration(com.intellij.execution.configurations.WrappingRunConfiguration) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeBeforeRunCommandHelper(com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ImmutableList(com.google.common.collect.ImmutableList) HotSwapProgress(com.intellij.debugger.impl.HotSwapProgress) Project(com.intellij.openapi.project.Project) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) GuavaHelper.toImmutableList(com.google.idea.common.guava.GuavaHelper.toImmutableList) Nullable(javax.annotation.Nullable) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Nullable(javax.annotation.Nullable)

Aggregations

RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)8 ExecutionException (com.intellij.execution.ExecutionException)6 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)3 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)3 CancellationException (java.util.concurrent.CancellationException)3 NotNull (org.jetbrains.annotations.NotNull)3 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 Label (com.google.idea.blaze.base.model.primitives.Label)2 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Key (com.intellij.openapi.util.Key)2 CloudAttachDialog (com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 BlazeBeforeRunCommandHelper (com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper)1 WithBrowserHyperlinkExecutionException (com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException)1