use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException in project intellij by bazelbuild.
the class CommandLineBlazeCommandRunner method run.
@Override
public BlazeBuildOutputs run(Project project, BlazeCommand.Builder blazeCommandBuilder, BlazeBuildParams buildParams, BuildResultHelper buildResultHelper, WorkspaceRoot workspaceRoot, BlazeContext context) {
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(blazeCommandBuilder.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
BuildResult buildResult = BuildResult.fromExitCode(retVal);
if (buildResult.status == Status.FATAL_ERROR) {
return BlazeBuildOutputs.noOutputs(buildResult);
}
try {
return BlazeBuildOutputs.fromParsedBepOutput(buildResult, buildResultHelper.getBuildOutput());
} catch (GetArtifactsException e) {
IssueOutput.error("Failed to get build outputs: " + e.getMessage()).submit(context);
return BlazeBuildOutputs.noOutputs(buildResult);
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException in project intellij by bazelbuild.
the class MobileInstallBuildStep method build.
@Override
public void build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
IssueOutput.error("Missing project data. Please sync and try again.").submit(context);
return;
}
DeviceFutures deviceFutures = deviceSession.deviceFutures;
if (deviceFutures == null) {
IssueOutput.error("Error fetching devices!").submit(context);
return;
}
context.output(new StatusOutput("Waiting for target device..."));
IDevice device = resolveDevice(context, deviceFutures);
if (device == null) {
return;
}
BuildInvoker invoker = Blaze.getBuildSystemProvider(project).getBuildSystem().getBuildInvoker(project, context);
BlazeCommand.Builder command = BlazeCommand.builder(invoker, BlazeCommandName.MOBILE_INSTALL);
if (passAdbArgWithSerialToMi.getValue()) {
// 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 (!StudioDeployerExperiment.isEnabled()) {
MobileInstallAdbLocationProvider.getAdbLocationForMobileInstall(project).ifPresent((location) -> command.addBlazeFlags(BlazeFlags.ADB, location));
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
final String deployInfoSuffix = getDeployInfoSuffix(Blaze.getBuildSystemName(project));
try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper();
AdbTunnelConfigurator tunnelConfig = getTunnelConfigurator(context)) {
tunnelConfig.setupConnection(context);
if (!StudioDeployerExperiment.isEnabled()) {
String deviceFlag = device.getSerialNumber();
if (tunnelConfig.isActive()) {
deviceFlag += ":tcp:" + tunnelConfig.getAdbServerPort();
} else {
InetSocketAddress adbAddr = AndroidDebugBridge.getSocketAddress();
if (adbAddr == null) {
IssueOutput.warn("Can't get ADB server port, please ensure ADB server is running. Will fallback" + " to the default adb server.").submit(context);
} else {
deviceFlag += ":tcp:" + adbAddr.getPort();
}
}
command.addBlazeFlags(BlazeFlags.DEVICE, deviceFlag);
}
command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addExeFlags(exeFlags).addExeFlags("--nolaunch_app");
if (StudioDeployerExperiment.isEnabled()) {
command.addExeFlags("--nodeploy");
}
SaveUtil.saveAllFiles();
context.output(new StatusOutput("Invoking mobile-install..."));
ExternalTask task = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stdout(LineProcessingOutputStream.of(new PrintOutputLineProcessor(context))).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build();
Stopwatch s = Stopwatch.createStarted();
int exitCode = task.run();
logBuildTime(launchId, StudioDeployerExperiment.isEnabled(), s.elapsed(), exitCode);
if (exitCode != 0) {
IssueOutput.error("Blaze build failed. See Blaze Console for details.").submit(context);
return;
}
ListenableFuture<Void> unusedFuture = FileCaches.refresh(project, context, BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(exitCode)));
context.output(new StatusOutput("Reading deployment information..."));
String executionRoot = ExecRootUtil.getExecutionRoot(buildResultHelper, project, blazeFlags, context);
if (executionRoot == null) {
IssueOutput.error("Could not locate execroot!").submit(context);
return;
}
AndroidDeployInfo deployInfoProto = deployInfoHelper.readDeployInfoProtoForTarget(label, buildResultHelper, fileName -> fileName.endsWith(deployInfoSuffix));
deployInfo = deployInfoHelper.extractDeployInfoAndInvalidateManifests(project, new File(executionRoot), deployInfoProto);
String msg;
if (StudioDeployerExperiment.isEnabled()) {
msg = "mobile-install build completed, deploying split apks...";
} else {
msg = "Done.";
}
context.output(new StatusOutput(msg));
} catch (GetArtifactsException e) {
IssueOutput.error("Could not read BEP output: " + e.getMessage()).submit(context);
} catch (GetDeployInfoException e) {
IssueOutput.error("Could not read apk deploy info from build: " + e.getMessage()).submit(context);
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException 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(ExecutionEnvironment env) throws ExecutionException {
SaveUtil.saveAllFiles();
try (BuildResultHelper buildResultHelper = BuildResultHelperProvider.createForLocalBuild(env.getProject())) {
List<String> extraDebugFlags;
if (!BlazeGDBServerProvider.shouldUseGdbserver()) {
extraDebugFlags = ImmutableList.of("--compilation_mode=dbg", "--copt=-O0", "--copt=-g", "--strip=never", "--dynamic_mode=off", "--fission=yes");
} else {
extraDebugFlags = BlazeGDBServerProvider.getFlagsForDebugging(configuration.getHandler().getState());
}
ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeCommand(BlazeCommandName.BUILD, configuration, buildResultHelper, ImmutableList.of(), extraDebugFlags, BlazeInvocationContext.runConfigContext(ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), true), "Building debug binary");
Label target = getSingleTarget(configuration);
try {
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;
try {
candidateFiles = BlazeArtifact.getLocalFiles(buildResultHelper.getBuildArtifactsForTarget(target, file -> true)).stream().filter(File::canExecute).collect(Collectors.toList());
} catch (GetArtifactsException e) {
throw new ExecutionException(String.format("Failed to get output artifacts when building %s: %s", target, e.getMessage()));
}
if (candidateFiles.isEmpty()) {
throw new ExecutionException(String.format("No output artifacts found when building %s", target));
}
File file = findExecutable(target, candidateFiles);
if (file == null) {
throw new ExecutionException(String.format("More than 1 executable was produced when building %s; don't know which to debug", target));
}
LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
return file;
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException in project intellij by bazelbuild.
the class BlazeInstrumentationTestApkBuildStep method build.
@Override
public void build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
IssueOutput.error("Invalid project data. Please sync the project.").submit(context);
return;
}
InstrumentorToTarget testComponents = getInstrumentorToTargetPair(context, projectData);
if (testComponents == null) {
return;
}
BuildInvoker invoker = Blaze.getBuildSystemProvider(project).getBuildSystem().getBuildInvoker(project, context);
BlazeCommand.Builder command = BlazeCommand.builder(invoker, BlazeCommandName.BUILD);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
// are on the local filesystem).
try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper()) {
if (testComponents.isSelfInstrumentingTest()) {
command.addTargets(testComponents.instrumentor);
} else {
command.addTargets(testComponents.target, testComponents.instrumentor);
}
command.addBlazeFlags("--output_groups=+android_deploy_info").addBlazeFlags(buildFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
ListenableFuture<Void> unusedFuture = FileCaches.refresh(project, context, BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(retVal)));
if (retVal != 0) {
IssueOutput.error("Blaze build failed. See Blaze Console for details.").submit(context);
return;
}
try {
context.output(new StatusOutput("Reading deployment information..."));
String executionRoot = ExecRootUtil.getExecutionRoot(buildResultHelper, project, buildFlags, context);
if (executionRoot == null) {
IssueOutput.error("Could not locate execroot!").submit(context);
return;
}
AndroidDeployInfo instrumentorDeployInfoProto = deployInfoHelper.readDeployInfoProtoForTarget(testComponents.instrumentor, buildResultHelper, fileName -> fileName.endsWith(DEPLOY_INFO_FILE_SUFFIX));
if (testComponents.isSelfInstrumentingTest()) {
deployInfo = deployInfoHelper.extractDeployInfoAndInvalidateManifests(project, new File(executionRoot), instrumentorDeployInfoProto);
} else {
AndroidDeployInfo targetDeployInfoProto = deployInfoHelper.readDeployInfoProtoForTarget(testComponents.target, buildResultHelper, fileName -> fileName.endsWith(DEPLOY_INFO_FILE_SUFFIX));
deployInfo = deployInfoHelper.extractInstrumentationTestDeployInfoAndInvalidateManifests(project, new File(executionRoot), instrumentorDeployInfoProto, targetDeployInfoProto);
}
} catch (GetArtifactsException e) {
IssueOutput.error("Could not read BEP output: " + e.getMessage()).submit(context);
} catch (GetDeployInfoException e) {
IssueOutput.error("Could not read apk deploy info from build: " + e.getMessage()).submit(context);
}
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException in project intellij by bazelbuild.
the class FullApkBuildStep method build.
@Override
public void build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
IssueOutput.error("Missing project data. Please sync and try again.").submit(context);
return;
}
BuildInvoker invoker = Blaze.getBuildSystemProvider(project).getBuildSystem().getBuildInvoker(project, context);
BlazeCommand.Builder command = BlazeCommand.builder(invoker, BlazeCommandName.BUILD);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper()) {
command.addTargets(label).addBlazeFlags("--output_groups=+android_deploy_info").addBlazeFlags(buildFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
ListenableFuture<Void> unusedFuture = FileCaches.refresh(project, context, BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(retVal)));
if (retVal != 0) {
IssueOutput.error("Blaze build failed. See Blaze Console for details.").submit(context);
return;
}
context.output(new StatusOutput("Reading deployment information..."));
String executionRoot = ExecRootUtil.getExecutionRoot(buildResultHelper, project, buildFlags, context);
if (executionRoot == null) {
IssueOutput.error("Could not locate execroot!").submit(context);
return;
}
AndroidDeployInfo deployInfoProto = deployInfoHelper.readDeployInfoProtoForTarget(label, buildResultHelper, fileName -> fileName.endsWith(DEPLOY_INFO_SUFFIX));
deployInfo = deployInfoHelper.extractDeployInfoAndInvalidateManifests(project, new File(executionRoot), deployInfoProto);
} catch (GetArtifactsException e) {
IssueOutput.error("Could not read BEP output: " + e.getMessage()).submit(context);
} catch (GetDeployInfoException e) {
IssueOutput.error("Could not read apk deploy info from build: " + e.getMessage()).submit(context);
}
if (FETCH_REMOTE_APKS.getValue() && deployInfo != null && apksRequireDownload(deployInfo)) {
context.output(new StatusOutput("Fetching remotely built APKs... "));
ImmutableList<File> localApks = deployInfo.getApksToDeploy().stream().map(apk -> FullApkBuildStep.downloadApkIfRemote(apk, context)).collect(ImmutableList.toImmutableList());
deployInfo = new BlazeAndroidDeployInfo(deployInfo.getMergedManifest(), deployInfo.getTestTargetMergedManifest(), localApks);
context.output(new StatusOutput("Done fetching APKs."));
}
}
Aggregations