Update the sets of built targets and aspects in the ExecutionProgressReceiver with Skymeld & incremental builds.

PiperOrigin-RevId: 437997802
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index 10d064c..b2a6371 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -321,6 +321,8 @@
         "//src/main/java/com/google/devtools/build/lib/skyframe:aspect_completion_value",
         "//src/main/java/com/google/devtools/build/lib/skyframe:aspect_key_creator",
         "//src/main/java/com/google/devtools/build/lib/skyframe:build_configuration",
+        "//src/main/java/com/google/devtools/build/lib/skyframe:build_driver_key",
+        "//src/main/java/com/google/devtools/build/lib/skyframe:build_driver_value",
         "//src/main/java/com/google/devtools/build/lib/skyframe:builder",
         "//src/main/java/com/google/devtools/build/lib/skyframe:configuration_phase_started_event",
         "//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_key",
@@ -340,6 +342,7 @@
         "//src/main/java/com/google/devtools/build/lib/skyframe:target_completion_value",
         "//src/main/java/com/google/devtools/build/lib/skyframe:target_pattern_phase_value",
         "//src/main/java/com/google/devtools/build/lib/skyframe:test_analysis_complete_event",
+        "//src/main/java/com/google/devtools/build/lib/skyframe:top_level_aspects_value",
         "//src/main/java/com/google/devtools/build/lib/skyframe:workspace_info",
         "//src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2:actiongraph_v2",
         "//src/main/java/com/google/devtools/build/lib/unix",
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java
index 5b3ca13..d334aad 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionProgressReceiver.java
@@ -18,13 +18,17 @@
 import com.google.devtools.build.lib.actions.ActionExecutionStatusReporter;
 import com.google.devtools.build.lib.actions.ActionLookupData;
 import com.google.devtools.build.lib.actions.MiddlemanType;
+import com.google.devtools.build.lib.analysis.AspectValue;
 import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog;
 import com.google.devtools.build.lib.skyframe.AspectCompletionValue;
 import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey;
+import com.google.devtools.build.lib.skyframe.BuildDriverKey;
+import com.google.devtools.build.lib.skyframe.BuildDriverValue;
 import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.skyframe.SkyFunctions;
 import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor;
 import com.google.devtools.build.lib.skyframe.TargetCompletionValue;
+import com.google.devtools.build.lib.skyframe.TopLevelAspectsValue;
 import com.google.devtools.build.skyframe.ErrorInfo;
 import com.google.devtools.build.skyframe.EvaluationProgressReceiver;
 import com.google.devtools.build.skyframe.SkyFunctionName;
@@ -36,6 +40,7 @@
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Supplier;
+import java.util.stream.Collectors;
 import javax.annotation.Nullable;
 
 /**
@@ -120,6 +125,19 @@
       // Remember all completed actions, even those in error, regardless of having been cached or
       // really executed.
       actionCompleted((ActionLookupData) skyKey.argument());
+    } else if (type.equals(SkyFunctions.BUILD_DRIVER)) {
+      if (evaluationSuccessState.get().succeeded() && newValue != null) {
+        BuildDriverKey buildDriverKey = (BuildDriverKey) skyKey;
+        if (buildDriverKey.isTopLevelAspectDriver()) {
+          builtAspects.addAll(
+              ((TopLevelAspectsValue) ((BuildDriverValue) newValue).getWrappedSkyValue())
+                  .getTopLevelAspectsValues().stream()
+                      .map(x -> ((AspectValue) x).getKey())
+                      .collect(Collectors.toUnmodifiableSet()));
+        } else {
+          builtTargets.add((ConfiguredTargetKey) buildDriverKey.getActionLookupKey());
+        }
+      }
     }
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java
index 94ef0c1..ece15d6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java
@@ -29,26 +29,48 @@
   private final TestType testType;
   private final boolean strictActionConflictCheck;
 
-  public BuildDriverKey(
-      ActionLookupKey actionLookupKey,
-      TopLevelArtifactContext topLevelArtifactContext,
-      boolean strictActionConflictCheck) {
-    this(
-        actionLookupKey,
-        topLevelArtifactContext,
-        strictActionConflictCheck,
-        /*testType=*/ TestType.NOT_TEST);
+  public boolean isTopLevelAspectDriver() {
+    return isTopLevelAspectDriver;
   }
 
-  public BuildDriverKey(
+  private final boolean isTopLevelAspectDriver;
+
+  private BuildDriverKey(
       ActionLookupKey actionLookupKey,
       TopLevelArtifactContext topLevelArtifactContext,
       boolean strictActionConflictCheck,
-      TestType testType) {
+      TestType testType,
+      boolean isTopLevelAspectDriver) {
     this.actionLookupKey = actionLookupKey;
     this.topLevelArtifactContext = topLevelArtifactContext;
     this.strictActionConflictCheck = strictActionConflictCheck;
     this.testType = testType;
+    this.isTopLevelAspectDriver = isTopLevelAspectDriver;
+  }
+
+  public static BuildDriverKey ofTopLevelAspect(
+      ActionLookupKey actionLookupKey,
+      TopLevelArtifactContext topLevelArtifactContext,
+      boolean strictActionConflictCheck) {
+    return new BuildDriverKey(
+        actionLookupKey,
+        topLevelArtifactContext,
+        strictActionConflictCheck,
+        TestType.NOT_TEST,
+        /*isTopLevelAspectDriver=*/ true);
+  }
+
+  public static BuildDriverKey ofConfiguredTarget(
+      ActionLookupKey actionLookupKey,
+      TopLevelArtifactContext topLevelArtifactContext,
+      boolean strictActionConflictCheck,
+      TestType testType) {
+    return new BuildDriverKey(
+        actionLookupKey,
+        topLevelArtifactContext,
+        strictActionConflictCheck,
+        testType,
+        /*isTopLevelAspectDriver=*/ false);
   }
 
   public TopLevelArtifactContext getTopLevelArtifactContext() {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
index 323e1ce..d744b08 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
@@ -656,7 +656,7 @@
         continue;
       }
       buildDriverCTKeys.add(
-          new BuildDriverKey(
+          BuildDriverKey.ofConfiguredTarget(
               ctKey,
               topLevelArtifactContext,
               strictConflictCheck,
@@ -677,7 +677,10 @@
     }
     List<BuildDriverKey> buildDriverAspectKeys =
         topLevelAspectsKeys.stream()
-            .map(k -> new BuildDriverKey(k, topLevelArtifactContext, strictConflictCheck))
+            .map(
+                k ->
+                    BuildDriverKey.ofTopLevelAspect(
+                        k, topLevelArtifactContext, strictConflictCheck))
             .collect(Collectors.toList());
 
     try (SilentCloseable c =