use of com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput in project intellij by bazelbuild.
the class FastBuildIncrementalCompilerImpl method compile.
@Override
public ListenableFuture<BuildOutput> compile(Label label, FastBuildState buildState) {
checkState(buildState.completedBuildOutput().isPresent());
BuildOutput buildOutput = buildState.completedBuildOutput().get();
checkState(buildOutput.targetMap().contains(TargetKey.forPlainTarget(label)));
return ConcurrencyUtil.getAppExecutorService().submit(() -> {
BlazeConsoleWriter writer = new BlazeConsoleWriter(blazeConsoleService);
Stopwatch stopwatch = Stopwatch.createStarted();
Set<File> pathsToCompile = getPathsToCompile(label, buildOutput.targetMap(), buildState.modifiedFiles());
writer.write("Calculated compilation paths in " + stopwatch + "\n");
if (!pathsToCompile.isEmpty()) {
compilerFactory.getCompilerFor(buildOutput.targetMap().get(TargetKey.forPlainTarget(label))).compile(CompileInstructions.builder().outputDirectory(buildState.compilerOutputDirectory()).classpath(ImmutableList.of(buildOutput.deployJar())).filesToCompile(pathsToCompile).outputWriter(writer).build());
writer.write("Compilation finished in " + stopwatch + "\n");
} else {
writer.write("No modified files to compile.\n");
}
return buildOutput;
});
}
use of com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput in project intellij by bazelbuild.
the class FastBuildServiceImpl method buildDeployJar.
private ListenableFuture<FastBuildState.BuildOutput> buildDeployJar(Label label, FastBuildParameters buildParameters) {
Label deployJarLabel = createDeployJarLabel(label);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
// TODO(plumpy): this assumes we're running this build as part of a run action. I try not to
// make that assumption anywhere else, so this should be supplied by the caller.
BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
AspectStrategy aspectStrategy = AspectStrategyProvider.findAspectStrategy(projectDataManager.getBlazeProjectData().blazeVersionData);
BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file));
ListenableFuture<BuildResult> buildResultFuture = ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {
@Override
protected BuildResult execute(BlazeContext context) {
context.push(new IssuesScope(project, /* focusProblemsViewOnIssue */
true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.blazeFlags()).addBlazeFlags(buildResultHelper.getBuildFlags());
List<String> outputGroups = new ArrayList<>();
// needed to retrieve the deploy jar
outputGroups.add("default");
outputGroups.addAll(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
aspectStrategy.addAspectAndOutputGroups(command, outputGroups);
int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
return BuildResult.fromExitCode(exitCode);
}
});
ListenableFuture<BuildOutput> buildOutputFuture = transform(buildResultFuture, result -> {
if (result.status != Status.SUCCESS) {
throw new RuntimeException("Blaze failure building deploy jar");
}
ImmutableList<File> deployJarArtifacts = buildResultHelper.getBuildArtifactsForTarget(deployJarLabel);
checkState(deployJarArtifacts.size() == 1);
File deployJar = deployJarArtifacts.get(0);
ImmutableList<File> ideInfoFiles = buildResultHelper.getArtifactsForOutputGroups(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
ImmutableMap<TargetKey, TargetIdeInfo> targetMap = ideInfoFiles.stream().map(file -> readTargetIdeInfo(aspectStrategy, file)).filter(Objects::nonNull).collect(toImmutableMap(ideInfo -> ideInfo.key, i -> i));
return BuildOutput.create(deployJar, new TargetMap(targetMap));
}, ConcurrencyUtil.getAppExecutorService());
buildOutputFuture.addListener(buildResultHelper::close, ConcurrencyUtil.getAppExecutorService());
return buildOutputFuture;
}
use of com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput in project intellij by bazelbuild.
the class FastBuildServiceImpl method updateBuild.
private FastBuildState updateBuild(Label label, FastBuildParameters buildParameters, @Nullable FastBuildState existingBuildState) {
if (existingBuildState != null && !existingBuildState.newBuildOutput().isDone()) {
// Don't start a new build if an existing one is still running.
return existingBuildState;
}
// We're adding a new entry to the map, so make sure to also mark it for cleanup.
if (existingBuildState == null) {
CleanupFastBuildData cleanup = new CleanupFastBuildData(label);
projectManager.addProjectManagerListener(project, cleanup);
Runtime.getRuntime().addShutdownHook(new Thread(() -> cleanup.projectClosed(/* project */
null)));
}
BuildOutput completedBuildOutput = getCompletedBuild(existingBuildState);
Set<File> modifiedFiles = getVcsModifiedFiles();
if (completedBuildOutput == null) {
File compileDirectory = createCompilerOutputDirectory();
return FastBuildState.create(buildDeployJar(label, buildParameters), compileDirectory, buildParameters, modifiedFiles);
} else {
existingBuildState = existingBuildState.withAdditionalModifiedFiles(modifiedFiles).withCompletedBuildOutput(completedBuildOutput);
return existingBuildState.withNewBuildOutput(incrementalCompiler.compile(label, existingBuildState));
}
}
Aggregations