Search in sources :

Example 1 with WithBrowserHyperlinkExecutionException

use of com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException 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)

Aggregations

BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)1 WithBrowserHyperlinkExecutionException (com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException)1 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)1 ExecutionException (com.intellij.execution.ExecutionException)1 RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)1 Project (com.intellij.openapi.project.Project)1 File (java.io.File)1 CancellationException (java.util.concurrent.CancellationException)1