Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not delay TargetCompleteEvents with coverage #22238

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ 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_artifacts_known_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",
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2741,16 +2741,6 @@ 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/coverage_artifacts_known_event",
srcs = ["test/CoverageArtifactsKnownEvent.java"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,32 +853,39 @@ private ImmutableSet<Artifact> memoizedGetCoverageArtifactsHelper(
EventBus eventBus,
TargetPatternPhaseValue loadingResult)
throws InterruptedException {
if (memoizedCoverageArtifacts != null) {
return memoizedCoverageArtifacts;
if (memoizedCoverageArtifacts == null) {
memoizedCoverageArtifacts =
memoizedGetCoverageArtifactsHelperInternal(
configuredTargets, allTargetsToTest, eventHandler, eventBus, loadingResult);
}
ImmutableSet.Builder<Artifact> resultBuilder = ImmutableSet.builder();
// Coverage
NestedSet<Artifact> baselineCoverageArtifacts = getBaselineCoverageArtifacts(configuredTargets);
resultBuilder.addAll(baselineCoverageArtifacts.toList());
return memoizedCoverageArtifacts;
}

if (coverageReportActionFactory != null) {
CoverageReportActionsWrapper actionsWrapper =
coverageReportActionFactory.createCoverageReportActionsWrapper(
eventHandler,
eventBus,
directories,
allTargetsToTest,
baselineCoverageArtifacts,
getArtifactFactory(),
skyframeExecutor.getActionKeyContext(),
CoverageReportValue.COVERAGE_REPORT_KEY,
loadingResult.getWorkspaceName());
if (actionsWrapper != null) {
skyframeExecutor.injectCoverageReportData(actionsWrapper.getActions());
actionsWrapper.getCoverageOutputs().forEach(resultBuilder::add);
}
private ImmutableSet<Artifact> memoizedGetCoverageArtifactsHelperInternal(
fmeum marked this conversation as resolved.
Show resolved Hide resolved
Set<ConfiguredTarget> configuredTargets,
Set<ConfiguredTarget> allTargetsToTest,
EventHandler eventHandler,
EventBus eventBus,
TargetPatternPhaseValue loadingResult)
throws InterruptedException {
if (coverageReportActionFactory == null) {
return ImmutableSet.of();
}
memoizedCoverageArtifacts = resultBuilder.build();
return memoizedCoverageArtifacts;
CoverageReportActionsWrapper actionsWrapper =
coverageReportActionFactory.createCoverageReportActionsWrapper(
eventHandler,
eventBus,
directories,
allTargetsToTest,
getBaselineCoverageArtifacts(configuredTargets),
getArtifactFactory(),
skyframeExecutor.getActionKeyContext(),
CoverageReportValue.COVERAGE_REPORT_KEY,
loadingResult.getWorkspaceName());
if (actionsWrapper == null) {
return ImmutableSet.of();
}
skyframeExecutor.injectCoverageReportData(actionsWrapper.getActions());
return ImmutableSet.copyOf(actionsWrapper.getCoverageOutputs());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ private TargetCompleteEvent(
instrumentedFilesProvider.getBaselineCoverageArtifacts();
if (!baselineCoverageArtifacts.isEmpty()) {
this.baselineCoverageArtifacts = baselineCoverageArtifacts;
postedAfterBuilder.add(BuildEventIdUtil.coverageActionsFinished());
} else {
this.baselineCoverageArtifacts = null;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ 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 @@ -248,9 +248,6 @@ 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 {}

// Identifier of an event providing the ExecRequest of a run command.
message ExecRequestId {}

fmeum marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -282,7 +279,6 @@ message BuildEventId {
WorkspaceConfigId workspace = 23;
BuildMetadataId build_metadata = 24;
ConvenienceSymlinksIdentifiedId convenience_symlinks_identified = 25;
CoverageActionsFinishedId coverage_actions_finished = 27;
ExecRequestId exec_request = 28;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
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 @@ -127,9 +126,6 @@ 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
2 changes: 1 addition & 1 deletion src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:target_configured_event",
"//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:test/coverage_artifacts_known_event",
"//src/main/java/com/google/devtools/build/lib/analysis:test/instrumented_files_info",
"//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 @@ -38,11 +38,13 @@
import com.google.devtools.build.lib.actions.TopLevelOutputException;
import com.google.devtools.build.lib.analysis.ConfiguredObjectValue;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.ConfiguredTargetValue;
import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper;
import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup;
import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsToBuild;
import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.SuccessfulArtifactFilter;
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo;
import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.causes.Cause;
import com.google.devtools.build.lib.causes.LabelCause;
Expand Down Expand Up @@ -170,8 +172,20 @@ public SkyValue compute(SkyKey skyKey, Environment env)
ValueT value = valueAndArtifactsToBuild.first;
ArtifactsToBuild artifactsToBuild = valueAndArtifactsToBuild.second;

// Ensure that coverage artifacts are built before a target is considered completed.
ImmutableList<Artifact> allArtifacts = artifactsToBuild.getAllArtifacts().toList();
SkyframeLookupResult inputDeps = env.getValuesAndExceptions(Artifact.keys(allArtifacts));
InstrumentedFilesInfo instrumentedFilesInfo =
value.getConfiguredObject().get(InstrumentedFilesInfo.STARLARK_CONSTRUCTOR);
Iterable<SkyKey> keysToRequest;
if (value.getConfiguredObject() instanceof ConfiguredTargetValue && instrumentedFilesInfo != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this was the bug. Should s/ConfiguredTargetValue/ConfiguredTarget. After that all the tests passed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix, thanks!

keysToRequest =
Iterables.concat(
Artifact.keys(allArtifacts),
Artifact.keys(instrumentedFilesInfo.getBaselineCoverageArtifacts().toList()));
} else {
keysToRequest = Artifact.keys(allArtifacts);
}
SkyframeLookupResult inputDeps = env.getValuesAndExceptions(keysToRequest);

boolean allArtifactsAreImportant = artifactsToBuild.areAllOutputGroupsImportant();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import com.google.devtools.build.lib.analysis.config.StarlarkTransitionCache;
import com.google.devtools.build.lib.analysis.starlark.StarlarkAttributeTransitionProvider;
import com.google.devtools.build.lib.analysis.test.AnalysisFailurePropagationException;
import com.google.devtools.build.lib.analysis.test.CoverageActionFinishedEvent;
import com.google.devtools.build.lib.analysis.test.CoverageArtifactsKnownEvent;
import com.google.devtools.build.lib.bugreport.BugReport;
import com.google.devtools.build.lib.bugreport.BugReporter;
Expand Down Expand Up @@ -757,18 +756,15 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
}

// Coverage report generation should only be requested after all tests have executed.
// We could generate baseline coverage artifacts earlier; it is only the timing of the
// combined report that matters.
// When --nokeep_going and there's an earlier error, we should skip this and fail fast.
if ((!mainEvaluationResult.hasError() && !hasExclusiveTestsError) || keepGoing) {
ImmutableSet<Artifact> coverageArtifacts =
coverageReportActionsWrapperSupplier.getCoverageArtifacts(
ImmutableSet<Artifact> coverageReportArtifacts =
coverageReportActionsWrapperSupplier.getCoverageReportArtifacts(
buildResultListener.getAnalyzedTargets(), buildResultListener.getAnalyzedTests());
eventBus.post(CoverageArtifactsKnownEvent.create(coverageArtifacts));
eventBus.post(CoverageArtifactsKnownEvent.create(coverageReportArtifacts));
additionalArtifactsResult =
skyframeExecutor.evaluateSkyKeys(
eventHandler, Artifact.keys(coverageArtifacts), keepGoing);
eventBus.post(new CoverageActionFinishedEvent());
eventHandler, Artifact.keys(coverageReportArtifacts), keepGoing);
if (additionalArtifactsResult.hasError()) {
detailedExitCodes.add(
SkyframeErrorProcessor.processErrors(
Expand Down Expand Up @@ -1483,7 +1479,7 @@ public void reset() {
/** Provides the list of coverage artifacts to be built. */
@FunctionalInterface
public interface CoverageReportActionsWrapperSupplier {
ImmutableSet<Artifact> getCoverageArtifacts(
ImmutableSet<Artifact> getCoverageReportArtifacts(
Set<ConfiguredTarget> configuredTargets, Set<ConfiguredTarget> allTargetsToTest)
throws InterruptedException;
}
Expand Down