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

Fix test
  • Loading branch information
ittaiz authored and WixBuildServer committed Feb 16, 2022
1 parent 37fb7cb commit a1d0781
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ public static BlazeBuildParams fromProject(Project project) {
.setBlazeBinaryPath(provider.getSyncBinaryPath(project))
.setBlazeBinaryType(binaryType)
.setParallelizeBuilds(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 @@ -57,6 +62,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
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ private BlazeBuildOutputs getBlazeBuildResult(
projectState.getBlazeInfo(),
shardedTargets,
projectState.getLanguageSettings(),
ImmutableSet.of(OutputGroup.RESOLVE, OutputGroup.INFO));
syncParams.blazeBuildParams().infoOnly() ?
ImmutableSet.of(OutputGroup.INFO):
ImmutableSet.of(OutputGroup.INFO, OutputGroup.RESOLVE));
});
}
}
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 @@ -391,6 +391,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 @@ -418,6 +422,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, @Nullable ToolWindowScope syncToolWindowScope, BlazeSyncParams params) {
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ private ShardedTargetsResult expandAndShardTargets(
BlazeBuildParams.builder()
.setBlazeBinaryPath("foo")
.setBlazeBinaryType(buildBinaryType)
.setInfoOnly(false)
.build(),
ProjectViewSet.builder().add(projectView).build(),
new WorkspacePathResolverImpl(workspaceRoot),
Expand Down

0 comments on commit a1d0781

Please sign in to comment.