Add a boolean to the AnalysisPhaseCompleteEvent to specify if the analysis
cache was dropped or not prior to the analysis phase starting.

PiperOrigin-RevId: 232759314
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisPhaseCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisPhaseCompleteEvent.java
index d09f8e6..99de301 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisPhaseCompleteEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisPhaseCompleteEvent.java
@@ -30,6 +30,7 @@
   private int targetsConfigured;
   private final PackageManagerStatistics pkgManagerStats;
   private final int actionsConstructed;
+  private final boolean analysisCacheDropped;
 
   /**
    * Construct the event.
@@ -42,13 +43,15 @@
       int targetsConfigured,
       long timeInMs,
       PackageManagerStatistics pkgManagerStats,
-      int actionsConstructed) {
+      int actionsConstructed,
+      boolean analysisCacheDropped) {
     this.timeInMs = timeInMs;
     this.topLevelTargets = ImmutableList.copyOf(topLevelTargets);
     this.targetsLoaded = targetsLoaded;
     this.targetsConfigured = targetsConfigured;
     this.pkgManagerStats = pkgManagerStats;
     this.actionsConstructed = actionsConstructed;
+    this.analysisCacheDropped = analysisCacheDropped;
   }
 
   /**
@@ -77,6 +80,10 @@
     return actionsConstructed;
   }
 
+  public boolean wasAnalysisCacheDropped() {
+    return analysisCacheDropped;
+  }
+
   /**
    * Returns package manager statistics.
    */
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java b/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java
index 587ed50..8cc38c0 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java
@@ -227,7 +227,8 @@
                 view.getTargetsConfigured(),
                 timer.stop().elapsed(TimeUnit.MILLISECONDS),
                 view.getAndClearPkgManagerStatistics(),
-                view.getActionsConstructed()));
+                view.getActionsConstructed(),
+                env.getSkyframeExecutor().wasAnalysisCacheDiscardedAndResetBit()));
     ImmutableSet<BuildConfigurationValue.Key> configurationKeys =
         Stream.concat(
                 analysisResult
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index f06f313..8c2bfc2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -299,6 +299,8 @@
 
   @VisibleForTesting boolean lastAnalysisDiscarded = false;
 
+  private boolean analysisCacheDiscarded = false;
+
   private final ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions;
 
   protected SkyframeIncrementalBuildMonitor incrementalBuildMonitor =
@@ -681,6 +683,12 @@
     return buildDriver;
   }
 
+  public boolean wasAnalysisCacheDiscardedAndResetBit() {
+    boolean tmp = analysisCacheDiscarded;
+    analysisCacheDiscarded = false;
+    return tmp;
+  }
+
   /**
    * This method exists only to allow a module to make a top-level Skyframe call during the
    * transition to making it fully Skyframe-compatible. Do not add additional callers!
@@ -800,6 +808,7 @@
   /** Clear any configured target data stored outside Skyframe. */
   public void handleAnalysisInvalidatingChange() {
     logger.info("Dropping configured target data");
+    analysisCacheDiscarded = true;
     skyframeBuildView.clearInvalidatedConfiguredTargets();
     skyframeBuildView.clearLegacyData();
   }