use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper 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.google.idea.blaze.base.command.buildresult.BuildResultHelper 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;
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper in project intellij by bazelbuild.
the class BlazeApkBuildStepMobileInstall method build.
@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
DeviceFutures deviceFutures = deviceSession.deviceFutures;
assert deviceFutures != null;
IDevice device = resolveDevice(context, deviceFutures);
if (device == null) {
return null;
}
BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.MOBILE_INSTALL);
command.addBlazeFlags(BlazeFlags.DEVICE, device.getSerialNumber());
// Redundant, but we need this to get around bug in bazel.
// https://github.com/bazelbuild/bazel/issues/4922
command.addBlazeFlags(BlazeFlags.ADB_ARG + "-s ", BlazeFlags.ADB_ARG + device.getSerialNumber());
if (USE_SDK_ADB.getValue()) {
File adb = AndroidSdkUtils.getAdb(project);
if (adb != null) {
command.addBlazeFlags(BlazeFlags.ADB, adb.toString());
}
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, blazeFlags);
BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags("--output_groups=android_deploy_info").addExeFlags(exeFlags);
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
FileCaches.refresh(project);
if (retVal != 0) {
context.setHasError();
return null;
}
deployInfo = deployInfoHelper.readDeployInfo(context);
if (deployInfo == null) {
IssueOutput.error("Could not read apk deploy info from build").submit(context);
}
return null;
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
try {
Futures.get(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
}
return context.shouldContinue();
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method doResolveIdeArtifacts.
/**
* Blaze build invocation requesting the 'intellij-resolve' aspect output group.
*
* <p>Prefetches the output artifacts built by this invocation.
*/
private static BuildResult doResolveIdeArtifacts(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, WorkspaceLanguageSettings workspaceLanguageSettings, List<TargetExpression> targets) {
try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(getGenfilePrefetchFilter())) {
BlazeCommand.Builder blazeCommandBuilder = BlazeCommand.builder(getBinaryPath(project), BlazeCommandName.BUILD).addTargets(targets).addBlazeFlags(BlazeFlags.KEEP_GOING).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.Sync));
// Request the 'intellij-resolve' aspect output group.
AspectStrategyProvider.findAspectStrategy(blazeVersionData).addAspectAndOutputGroups(blazeCommandBuilder, OutputGroup.RESOLVE, workspaceLanguageSettings.activeLanguages);
// Run the blaze build command, parsing any output artifacts produced.
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(blazeCommandBuilder.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run(new TimingScope("ExecuteBlazeCommand", EventType.BlazeInvocation));
BuildResult result = BuildResult.fromExitCode(retVal);
if (result.status != BuildResult.Status.FATAL_ERROR) {
prefetchGenfiles(project, context, buildResultHelper.getBuildArtifacts());
} else {
buildResultHelper.close();
}
return result;
}
}
Aggregations