Skip to content

Commit

Permalink
if partial success (compilation issue) we issue another bazel build w…
Browse files Browse the repository at this point in the history
…ith info only

This is to make sure we have the needed metadata even if build broke
Relates to:
bazelbuild#1167
bazelbuild/bazel#9413
  • Loading branch information
ittaiz authored and Vaidas Pilkauskas committed Nov 28, 2019
1 parent 07cb3a2 commit 7d665c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ public static BlazeBuildParams fromProject(Project project) {
.setBlazeBinaryPath(provider.getSyncBinaryPath(project))
.setBlazeBinaryType(binaryType)
.setParallelizeBuilds(parallelizeRemoteSyncs.getValue() && binaryType.isRemote)
.setInfoOnly(false)
.build();
}

public abstract String blazeBinaryPath();

public abstract BuildBinaryType blazeBinaryType();

public abstract boolean infoOnly();

public abstract Builder toBuilder();

/**
* Whether batched build invocations are run in parallel, when possible (only when building
* remotely).
Expand All @@ -61,6 +66,8 @@ public abstract static class Builder {

public abstract Builder setBlazeBinaryType(BuildBinaryType value);

public abstract Builder setInfoOnly(boolean value);

// not public; derived from BuildBinaryType
abstract Builder setParallelizeBuilds(boolean parallelizeBuilds);

Expand Down
23 changes: 23 additions & 0 deletions base/src/com/google/idea/blaze/base/sync/SyncPhaseCoordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ void runSync(BlazeSyncParams params, boolean singleThreaded, BlazeContext contex
projectState != null
? BuildPhaseSyncTask.runBuildPhase(project, params, projectState, buildId, context)
: BlazeSyncBuildResult.builder().build();
//If we have partial success we'll run the build again this time only with intellij-info-java
if (projectState != null && syncResultFromBuildPhase(buildResult, context) == SyncResult.PARTIAL_SUCCESS) {
buildResult = syncInfoOnly(params, context, buildId, projectState, buildResult);
}
UpdatePhaseTask task =
UpdatePhaseTask.builder()
.setStartTime(startTime)
Expand Down Expand Up @@ -392,6 +396,25 @@ void runSync(BlazeSyncParams params, boolean singleThreaded, BlazeContext contex
}
}

private BlazeSyncBuildResult syncInfoOnly(BlazeSyncParams params, BlazeContext context,
int buildId, SyncProjectState projectState, BlazeSyncBuildResult buildResult) {
final BlazeSyncParams infoOnlySyncParams = params.toBuilder().setBlazeBuildParams(
params.blazeBuildParams().toBuilder().setInfoOnly(true).build()
).build();
final BlazeSyncBuildResult infoOnlySyncResult = BuildPhaseSyncTask
.runBuildPhase(project, infoOnlySyncParams, projectState, buildId, context);
/*
* updateResult should be used the other way around [ olderRun.updateResult(newerRun) ]
* since that is used to remove stale/old artifacts from targets which boths runs "saw"
* In our case both runs are sequential without artifacts changing.
* The second run only has IDE-INFO files
* For every target the first run was able to process it has all the data (first run does IDE-INFO and Resolve)
* What happens when we updateResult as below is that we basically just add the IDE-INFO files
* of the broken targets from the second run into the first run
*/
return infoOnlySyncResult.updateResult(buildResult);
}

private void queueUpdateTask(UpdatePhaseTask task) {
synchronized (this) {
if (pendingUpdateTask != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ private static BlazeBuildOutputs runBuildForTargets(

aspectStrategy.addAspectAndOutputGroups(
builder,
ImmutableList.of(OutputGroup.INFO, OutputGroup.RESOLVE),
buildParams.infoOnly() ?
ImmutableList.of(OutputGroup.INFO):
ImmutableList.of(OutputGroup.INFO, OutputGroup.RESOLVE),
activeLanguages,
onlyDirectDeps);

Expand Down

0 comments on commit 7d665c0

Please sign in to comment.