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;
}
}
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;
}
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;
}
}
Aggregations