use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException in project intellij by bazelbuild.
the class BlazeApkDeployInfoProtoHelper method readDeployInfoProtoForTarget.
public AndroidDeployInfo readDeployInfoProtoForTarget(Label target, BuildResultHelper buildResultHelper, Predicate<String> pathFilter) throws GetDeployInfoException {
ImmutableList<File> deployInfoFiles;
try {
deployInfoFiles = BlazeArtifact.getLocalFiles(buildResultHelper.getBuildArtifactsForTarget(target, pathFilter));
} catch (GetArtifactsException e) {
throw new GetDeployInfoException(e.getMessage());
}
if (deployInfoFiles.isEmpty()) {
Logger log = Logger.getInstance(BlazeApkDeployInfoProtoHelper.class.getName());
try {
ParsedBepOutput bepOutput = buildResultHelper.getBuildOutput();
log.warn("Local execroot: " + bepOutput.getLocalExecRoot());
log.warn("All output artifacts:");
for (OutputArtifact outputArtifact : bepOutput.getAllOutputArtifacts(path -> true)) {
log.warn(outputArtifact.getKey() + " -> " + outputArtifact.getRelativePath());
}
log.warn("All local artifacts for " + target + ":");
List<OutputArtifact> allBuildArtifacts = buildResultHelper.getBuildArtifactsForTarget(target, path -> true);
List<File> allLocalFiles = BlazeArtifact.getLocalFiles(allBuildArtifacts);
for (File file : allLocalFiles) {
String path = file.getPath();
log.warn(path);
if (pathFilter.test(path)) {
log.warn("Note: " + path + " passes pathFilter but was not recognized!");
}
}
} catch (GetArtifactsException e) {
log.warn("Error occured when gathering logs:", e);
}
throw new GetDeployInfoException("No deploy info proto artifact found. Was android_deploy_info in the output groups?");
}
if (deployInfoFiles.size() > 1) {
throw new GetDeployInfoException("More than one deploy info proto artifact found: " + deployInfoFiles.stream().map(File::getPath).collect(Collectors.joining(", ", "[", "]")));
}
try (InputStream inputStream = new FileInputStream(deployInfoFiles.get(0))) {
return AndroidDeployInfo.parseFrom(inputStream);
} catch (IOException e) {
throw new GetDeployInfoException(e.getMessage());
}
}
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, 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 {
context.output(PrintOutput.log("Build command finished. Retrieving BEP outputs..."));
Interner<String> stringInterner = Optional.ofNullable(context.getScope(SharedStringPoolScope.class)).map(SharedStringPoolScope::getStringInterner).orElse(null);
return BlazeBuildOutputs.fromParsedBepOutput(buildResult, buildResultHelper.getBuildOutput(stringInterner));
} 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 FastBuildServiceImpl method buildDeployJar.
private FastBuildState.BuildOutput buildDeployJar(BlazeContext context, Label label, FastBuildParameters buildParameters, BuildResultHelper resultHelper) {
Label deployJarLabel = createDeployJarLabel(label);
context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
BlazeInfo blazeInfo = getBlazeInfo(context, buildParameters);
FastBuildAspectStrategy aspectStrategy = FastBuildAspectStrategy.getInstance(Blaze.getBuildSystemName(project));
Stopwatch timer = Stopwatch.createStarted();
BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.buildFlags()).addBlazeFlags(resultHelper.getBuildFlags());
aspectStrategy.addAspectAndOutputGroups(command, /* additionalOutputGroups...= */
"default");
int exitCode = ExternalTask.builder(WorkspaceRoot.fromProject(project)).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
BuildResult result = BuildResult.fromExitCode(exitCode);
context.output(FastBuildLogOutput.keyValue("deploy_jar_build_result", result.status.toString()));
context.output(FastBuildLogOutput.milliseconds("deploy_jar_build_time_ms", timer));
if (result.status != Status.SUCCESS) {
throw new FastBuildTunnelException(new BlazeBuildError("Blaze failure building deploy jar"));
}
Predicate<String> filePredicate = file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file);
try {
ImmutableList<File> deployJarArtifacts = BlazeArtifact.getLocalFiles(resultHelper.getBuildArtifactsForTarget(deployJarLabel, filePredicate));
checkState(deployJarArtifacts.size() == 1);
File deployJar = deployJarArtifacts.get(0);
ImmutableList<File> ideInfoFiles = BlazeArtifact.getLocalFiles(resultHelper.getArtifactsForOutputGroup(aspectStrategy.getAspectOutputGroup(), filePredicate));
// if targets are built with multiple configurations, just take the first one
// TODO(brendandouglas): choose a consistent configuration instead
ImmutableMap<Label, FastBuildBlazeData> blazeData = ideInfoFiles.stream().map(aspectStrategy::readFastBuildBlazeData).collect(toImmutableMap(FastBuildBlazeData::label, i -> i, (i, j) -> i));
return BuildOutput.create(deployJar, blazeData, blazeInfo);
} catch (GetArtifactsException e) {
throw new RuntimeException("Blaze failure building deploy jar: " + e.getMessage());
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException in project intellij by bazelbuild.
the class GenerateDeployableJarTaskProvider method getDeployableJar.
/**
* Builds a deployable jar for the given target, and returns the corresponding output artifact.
*
* @throws ExecutionException if the build failed, or the output artifact cannot be found.
*/
private static File getDeployableJar(RunConfiguration configuration, ExecutionEnvironment env, Label target) throws ExecutionException {
Project project = env.getProject();
try (BuildResultHelper buildResultHelper = BuildResultHelperProvider.createForLocalBuild(project)) {
SaveUtil.saveAllFiles();
ListenableFuture<BuildResult> buildOperation = runBazelBuild(project, target, buildResultHelper, BlazeInvocationContext.runConfigContext(ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), true));
try {
BuildResult result = buildOperation.get();
if (result.status != BuildResult.Status.SUCCESS) {
throw new ExecutionException("Bazel failure building deployable jar");
}
} catch (InterruptedException | CancellationException e) {
buildOperation.cancel(true);
throw new RunCanceledByUserException();
} catch (java.util.concurrent.ExecutionException e) {
throw new ExecutionException(e);
}
List<File> outputs = BlazeArtifact.getLocalFiles(buildResultHelper.getBuildArtifactsForTarget(target.withTargetName(target.targetName() + "_deploy.jar"), file -> true));
if (outputs.isEmpty()) {
throw new ExecutionException(String.format("Failed to find deployable jar when building %s", target));
}
return outputs.get(0);
} catch (GetArtifactsException e) {
throw new ExecutionException(String.format("Failed to find deployable jar when building %s: %s", target, e.getMessage()));
}
}
use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException 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 PyExecutionInfo getExecutableToDebug(ExecutionEnvironment env) throws ExecutionException {
BlazeCommandRunConfiguration configuration = BlazeCommandRunConfigurationRunner.getConfiguration(env);
Project project = configuration.getProject();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
throw new ExecutionException("Not synced yet, please sync project");
}
Label target = getSingleTarget(configuration);
ImmutableList<String> args = getPythonArgsFor(blazeProjectData, target);
String validationError = BlazePyDebugHelper.validateDebugTarget(env.getProject(), target);
if (validationError != null) {
throw new WithBrowserHyperlinkExecutionException(validationError);
}
SaveUtil.saveAllFiles();
// present locally
try (BuildResultHelper buildResultHelper = BuildResultHelperProvider.createForLocalBuild(project)) {
ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeCommand(BlazeCommandName.BUILD, configuration, buildResultHelper, BlazePyDebugHelper.getAllBlazeDebugFlags(configuration.getProject(), target), ImmutableList.of(), BlazeInvocationContext.runConfigContext(ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), true), "Building debug binary");
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 one to debug", target));
}
LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
return new PyExecutionInfo(file, args);
}
}
Aggregations