Skip to content

Commit

Permalink
Add CoverageActionsFinishedId to the build_event_stream proto.
Browse files Browse the repository at this point in the history
With Skymeld, the coverage actions are run _after_ the analysis & execution
phase, since this is the earliest place where we can 1) have the list of analyzed
tests and 2) request for a Skyframe evaluation.

Unfortunately, this means that the info about the coverage artifacts would be
missing in the BEP message triggered by the `TargetCompleteEvents`, which are sent
at the end of the analysis & execution phase.

This CL fixes that by adding an empty `CoverageActionsFinishedId`, which is listed
as a `#postedAfter()` event of `TargetCompleteEvent`. This ensures that all info
regarding the coverage artifacts is availble by the time we convert the
`TargetCompleteEvent` to a BEP message.

PiperOrigin-RevId: 534809359
Change-Id: Iabde183433a8492d9f009e7b235990efe7fc7069
  • Loading branch information
joeleba authored and copybara-github committed May 24, 2023
1 parent 23f9c10 commit c2a6f0c
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:provider_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:server_directories",
"//src/main/java/com/google/devtools/build/lib/analysis:template_expansion_exception",
"//src/main/java/com/google/devtools/build/lib/analysis:test/coverage_action_finished_event",
"//src/main/java/com/google/devtools/build/lib/analysis:test/coverage_report_action_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_collection",
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,16 @@ java_library(
],
)

java_library(
name = "test/coverage_action_finished_event",
srcs = ["test/CoverageActionFinishedEvent.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"//third_party:guava",
],
)

java_library(
name = "test/execution_info",
srcs = ["test/ExecutionInfo.java"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ private TargetCompleteEvent(
postedAfterBuilder.add(cause.getIdProto());
}
detailedExitCode = mostImportantDetailedExitCode;
this.postedAfter = postedAfterBuilder.build();
this.completionContext = completionContext;
this.outputs = outputs;
this.isTest = isTest;
Expand All @@ -174,10 +173,12 @@ private TargetCompleteEvent(
instrumentedFilesProvider.getBaselineCoverageArtifacts();
if (!baselineCoverageArtifacts.isEmpty()) {
this.baselineCoverageArtifacts = baselineCoverageArtifacts;
postedAfterBuilder.add(BuildEventIdUtil.coverageActionsFinished());
} else {
this.baselineCoverageArtifacts = null;
}
}
this.postedAfter = postedAfterBuilder.build();
this.tags = targetAndData.getRuleTags();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2023 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.analysis.test;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId;
import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
import java.util.Collection;

/**
* Signal that the coverage actions are finished. Only used as a prerequisite for {@link
* com.google.devtools.build.lib.analysis.TargetCompleteEvent} in Skymeld mode.
*/
public class CoverageActionFinishedEvent implements BuildEvent {

@Override
public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext context)
throws InterruptedException {
return GenericBuildEvent.protoChaining(this).build();
}

@Override
public BuildEventId getEventId() {
return BuildEventIdUtil.coverageActionsFinished();
}

@Override
public Collection<BuildEventId> getChildrenEvents() {
return ImmutableList.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ public static BuildEventId targetConfigured(Label label) {
return BuildEventId.newBuilder().setTargetConfigured(configuredId).build();
}

public static BuildEventId coverageActionsFinished() {
return BuildEventId.newBuilder()
.setCoverageActionsFinished(BuildEventId.CoverageActionsFinishedId.getDefaultInstance())
.build();
}

public static BuildEventId aspectConfigured(Label label, String aspect) {
BuildEventId.TargetConfiguredId configuredId =
BuildEventId.TargetConfiguredId.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ message BuildEventId {
// Identifier of an event providing convenience symlinks information.
message ConvenienceSymlinksIdentifiedId {}

// Identifier of an event signalling that the coverage actions are finished.
message CoverageActionsFinishedId {}

oneof id {
UnknownBuildEventId unknown = 1;
ProgressId progress = 2;
Expand Down Expand Up @@ -250,6 +253,7 @@ message BuildEventId {
WorkspaceConfigId workspace = 23;
BuildMetadataId build_metadata = 24;
ConvenienceSymlinksIdentifiedId convenience_symlinks_identified = 25;
CoverageActionsFinishedId coverage_actions_finished = 27;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.devtools.build.lib.actions.TestExecException;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
import com.google.devtools.build.lib.analysis.test.CoverageActionFinishedEvent;
import com.google.devtools.build.lib.analysis.test.TestProvider;
import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.buildtool.buildevent.ExecutionProgressReceiverAvailableEvent;
Expand Down Expand Up @@ -119,6 +120,9 @@ public void buildArtifacts(
skyframeExecutor
.getEventBus()
.post(new ExecutionProgressReceiverAvailableEvent(executionProgressReceiver));
// When not in Skymeld mode, TargetCompleteEvents don't need to be held back.
// See {@link CoverageActionFinishedEvent}.
skyframeExecutor.getEventBus().post(new CoverageActionFinishedEvent());

List<DetailedExitCode> detailedExitCodes = new ArrayList<>();
EvaluationResult<?> result;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:target_and_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:template_expansion_exception",
"//src/main/java/com/google/devtools/build/lib/analysis:test/analysis_failure_propagation_exception",
"//src/main/java/com/google/devtools/build/lib/analysis:test/coverage_action_finished_event",
"//src/main/java/com/google/devtools/build/lib/analysis:toolchain_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:toolchain_context",
"//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.google.devtools.build.lib.analysis.config.ConfigConditions;
import com.google.devtools.build.lib.analysis.config.StarlarkTransitionCache;
import com.google.devtools.build.lib.analysis.test.AnalysisFailurePropagationException;
import com.google.devtools.build.lib.analysis.test.CoverageActionFinishedEvent;
import com.google.devtools.build.lib.bugreport.BugReport;
import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildMetrics.BuildGraphMetrics;
Expand Down Expand Up @@ -660,6 +661,7 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
buildResultListener.getAnalyzedTargets(),
buildResultListener.getAnalyzedTests())),
keepGoing);
eventBus.post(new CoverageActionFinishedEvent());
if (additionalArtifactsResult.hasError()) {
detailedExitCodes.add(
SkyframeErrorProcessor.processErrors(
Expand Down

0 comments on commit c2a6f0c

Please sign in to comment.