Correctly flag loading errors in the interleaved case.

In the interleaved case, loading errors can now also be discovered during the
analysis phase. Add a boolean flag to the SkyframeAnalysisResult to indicate
that such an error happened, and pass it through in BuildView.

Also refactor BuildView to simplify the code a bit - simply pass the
SkyframeAnalysisResult to the createResult method.

There is already an integration test for this - I'm adding a faster unit test
in BuildViewTest, as this is part of the BuildView contract.

--
MOS_MIGRATED_REVID=113716870
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index 35d3c12..3712e54 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -451,7 +451,6 @@
 
     List<AspectValueKey> aspectKeys = new ArrayList<>();
     for (String aspect : aspects) {
-
       // Syntax: label%aspect
       int delimiterPosition = aspect.indexOf('%');
       if (delimiterPosition >= 0) {
@@ -514,18 +513,13 @@
       LOG.info(msg);
     }
 
-    boolean analysisSuccessful = !skyframeAnalysisResult.hasError();
     AnalysisResult result =
         createResult(
             eventHandler,
             loadingResult,
             topLevelOptions,
             viewOptions,
-            skyframeAnalysisResult.getConfiguredTargets(),
-            skyframeAnalysisResult.getAspects(),
-            skyframeAnalysisResult.getWalkableGraph(),
-            skyframeAnalysisResult.getPackageRoots(),
-            analysisSuccessful);
+            skyframeAnalysisResult);
     LOG.info("Finished analysis");
     return result;
   }
@@ -535,13 +529,10 @@
       LoadingResult loadingResult,
       TopLevelArtifactContext topLevelOptions,
       BuildView.Options viewOptions,
-      Collection<ConfiguredTarget> configuredTargets,
-      Collection<AspectValue> aspects,
-      final WalkableGraph graph,
-      ImmutableMap<PackageIdentifier, Path> packageRoots,
-      boolean analysisSuccessful)
-      throws InterruptedException {
+      SkyframeAnalysisResult skyframeAnalysisResult)
+          throws InterruptedException {
     Collection<Target> testsToRun = loadingResult.getTestsToRun();
+    Collection<ConfiguredTarget> configuredTargets = skyframeAnalysisResult.getConfiguredTargets();
     Collection<ConfiguredTarget> allTargetsToTest = null;
     if (testsToRun != null) {
       // Determine the subset of configured targets that are meant to be run as tests.
@@ -584,12 +575,13 @@
     // Tests. This must come last, so that the exclusive tests are scheduled after everything else.
     scheduleTestsIfRequested(parallelTests, exclusiveTests, topLevelOptions, allTargetsToTest);
 
-    String error = !loadingResult.hasLoadingError()
-          ? (analysisSuccessful
-            ? null
-            : "execution phase succeeded, but not all targets were analyzed")
-          : "execution phase succeeded, but there were loading phase errors";
+    String error = loadingResult.hasLoadingError() || skyframeAnalysisResult.hasLoadingError()
+          ? "execution phase succeeded, but there were loading phase errors"
+          : skyframeAnalysisResult.hasAnalysisError()
+            ? "execution phase succeeded, but not all targets were analyzed"
+            : null;
 
+    final WalkableGraph graph = skyframeAnalysisResult.getWalkableGraph();
     final ActionGraph actionGraph = new ActionGraph() {
       @Nullable
       @Override
@@ -605,7 +597,7 @@
     };
     return new AnalysisResult(
         configuredTargets,
-        aspects,
+        skyframeAnalysisResult.getAspects(),
         allTargetsToTest,
         error,
         actionGraph,
@@ -613,7 +605,7 @@
         parallelTests,
         exclusiveTests,
         topLevelOptions,
-        packageRoots);
+        skyframeAnalysisResult.getPackageRoots());
   }
 
   private static NestedSet<Artifact> getBaselineCoverageArtifacts(