Skip to content

Commit

Permalink
Refactor: Inline the handling of aspects in BuildDriverFunction.
Browse files Browse the repository at this point in the history
This makes it more consistent with how things are done for configured targets.

PiperOrigin-RevId: 600815068
Change-Id: I86b36c1798ee24c2a788f812958d552f5de8ecca
  • Loading branch information
joeleba authored and copybara-github committed Jan 23, 2024
1 parent cf2c5fa commit 95ffb7c
Showing 1 changed file with 33 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,39 @@ public SkyValue compute(SkyKey skyKey, Environment env)
postedEventsTypes,
state.testType);
} else {
announceAspectAnalysisDoneAndRequestExecution(
buildDriverKey,
(TopLevelAspectsValue) topLevelSkyValue,
env,
topLevelArtifactContext,
postedEventsTypes);
ImmutableSet.Builder<Artifact> artifactsToBuild = ImmutableSet.builder();
List<SkyKey> aspectCompletionKeys = new ArrayList<>();

for (Map.Entry<AspectKey, AspectValue> entry :
((TopLevelAspectsValue) topLevelSkyValue).getTopLevelAspectsMap().entrySet()) {
AspectKey aspectKey = entry.getKey();
AspectValue aspectValue = entry.getValue();
addExtraActionsIfRequested(
aspectValue.getProvider(ExtraActionArtifactsProvider.class),
artifactsToBuild,
buildDriverKey.isExtraActionTopLevelOnly());

// It's possible that this code path is triggered AFTER the analysis cache clean up and the
// transitive packages for package root resolution is already cleared. In such a case, the
// symlinks should have already been planted.
if (aspectValue.getTransitivePackages() != null) {
postEventIfNecessary(
postedEventsTypes,
env,
TopLevelTargetReadyForSymlinkPlanting.create(aspectValue.getTransitivePackages()));
}
aspectCompletionKeys.add(AspectCompletionKey.create(aspectKey, topLevelArtifactContext));
}

// Send the AspectAnalyzedEvents first to make sure the BuildResultListener is up-to-date
// before signaling that the analysis of this top level aspect has concluded.
postEventIfNecessary(
postedEventsTypes, env, TopLevelEntityAnalysisConcludedEvent.success(buildDriverKey));

postEventIfNecessary(postedEventsTypes, env, SomeExecutionStartedEvent.create());
// Request the execution of the collected aspects.
declareDependenciesAndCheckValues(
env, Iterables.concat(Artifact.keys(artifactsToBuild.build()), aspectCompletionKeys));
}

if (env.valuesMissing()) {
Expand Down Expand Up @@ -544,52 +571,6 @@ private void requestConfiguredTargetExecution(
declareDependenciesAndCheckValues(env, keysToRequest.build());
}

private void announceAspectAnalysisDoneAndRequestExecution(
BuildDriverKey buildDriverKey,
TopLevelAspectsValue topLevelAspectsValue,
Environment env,
TopLevelArtifactContext topLevelArtifactContext,
Set<TopLevelStatusEvents.Type> postedEventsTypes)
throws InterruptedException {

ImmutableSet.Builder<Artifact> artifactsToBuild = ImmutableSet.builder();
List<SkyKey> aspectCompletionKeys = new ArrayList<>();

boolean symlinkPlantingEventsSent =
!postedEventsTypes.add(
TopLevelStatusEvents.Type.TOP_LEVEL_TARGET_READY_FOR_SYMLINK_PLANTING);
for (Map.Entry<AspectKey, AspectValue> entry :
topLevelAspectsValue.getTopLevelAspectsMap().entrySet()) {
AspectKey aspectKey = entry.getKey();
AspectValue aspectValue = entry.getValue();
addExtraActionsIfRequested(
aspectValue.getProvider(ExtraActionArtifactsProvider.class),
artifactsToBuild,
buildDriverKey.isExtraActionTopLevelOnly());

// It's possible that this code path is triggered AFTER the analysis cache clean up and the
// transitive packages for package root resolution is already cleared. In such a case, the
// symlinks should have already been planted.
if (aspectValue.getTransitivePackages() != null && !symlinkPlantingEventsSent) {
env.getListener()
.post(
TopLevelTargetReadyForSymlinkPlanting.create(aspectValue.getTransitivePackages()));
}

aspectCompletionKeys.add(AspectCompletionKey.create(aspectKey, topLevelArtifactContext));
}

// Send the AspectAnalyzedEvents first to make sure the BuildResultListener is up-to-date before
// signaling that the analysis of this top level aspect has concluded.
postEventIfNecessary(
postedEventsTypes, env, TopLevelEntityAnalysisConcludedEvent.success(buildDriverKey));

postEventIfNecessary(postedEventsTypes, env, SomeExecutionStartedEvent.create());
declareDependenciesAndCheckValues(
env, Iterables.concat(Artifact.keys(artifactsToBuild.build()), aspectCompletionKeys));

}

/**
* Declares dependencies and checks values for requested nodes in the graph.
*
Expand Down

0 comments on commit 95ffb7c

Please sign in to comment.