BEP reports analysis failure for targets with artifact conflicts.

Artifact conflicts are detected through a non-skyframe evaluation that is not
capable of identifying a top-level target or aspect that failed as a result of the
artifact conflict. We do perform a skyframe evaluation to identify which targets
and aspects to actually evaluate however, and *this* evaluation is now used to
report artifact conflicts in BEP.

A previous implementation of this change was rolled back due to a crash that
occurred if a --keep_going build included both action conflicts and other analysis
failures. A new regression test is included for this case.

RELNOTES: None.
PiperOrigin-RevId: 368017860
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java
index 02c37bf..1e8a0ef 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java
@@ -16,8 +16,10 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.actions.ActionLookupKey;
 import com.google.devtools.build.lib.buildeventstream.BuildEvent;
 import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
 import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil;
@@ -28,6 +30,7 @@
 import com.google.devtools.build.lib.causes.Cause;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.skyframe.AspectValueKey;
 import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import java.util.Collection;
 import javax.annotation.Nullable;
@@ -37,13 +40,34 @@
  * target cannot be completed because of an error in one of its dependencies.
  */
 public class AnalysisFailureEvent implements BuildEvent {
+  @Nullable private final AspectValueKey failedAspect;
   private final ConfiguredTargetKey failedTarget;
   private final BuildEventId configuration;
   private final NestedSet<Cause> rootCauses;
 
   public AnalysisFailureEvent(
-      ConfiguredTargetKey failedTarget, BuildEventId configuration, NestedSet<Cause> rootCauses) {
-    this.failedTarget = failedTarget;
+      ActionLookupKey failedTarget, BuildEventId configuration, NestedSet<Cause> rootCauses) {
+    Preconditions.checkArgument(
+        failedTarget instanceof ConfiguredTargetKey || failedTarget instanceof AspectValueKey);
+    if (failedTarget instanceof ConfiguredTargetKey) {
+      this.failedAspect = null;
+      this.failedTarget = (ConfiguredTargetKey) failedTarget;
+    } else {
+      this.failedAspect = (AspectValueKey) failedTarget;
+      this.failedTarget = failedAspect.getBaseConfiguredTargetKey();
+    }
+    if (configuration != null) {
+      this.configuration = configuration;
+    } else {
+      this.configuration = NullConfiguration.INSTANCE.getEventId();
+    }
+    this.rootCauses = rootCauses;
+  }
+
+  public AnalysisFailureEvent(
+      AspectValueKey failedAspect, BuildEventId configuration, NestedSet<Cause> rootCauses) {
+    this.failedAspect = failedAspect;
+    this.failedTarget = failedAspect.getBaseConfiguredTargetKey();
     if (configuration != null) {
       this.configuration = configuration;
     } else {
@@ -55,6 +79,7 @@
   @Override
   public String toString() {
     return MoreObjects.toStringHelper(this)
+        .add("failedAspect", failedAspect)
         .add("failedTarget", failedTarget)
         .add("configuration", configuration)
         .add("legacyFailureReason", getLegacyFailureReason())
@@ -86,7 +111,12 @@
 
   @Override
   public BuildEventId getEventId() {
-    return BuildEventIdUtil.targetCompleted(failedTarget.getLabel(), configuration);
+    if (failedAspect == null) {
+      return BuildEventIdUtil.targetCompleted(failedTarget.getLabel(), configuration);
+    } else {
+      return BuildEventIdUtil.aspectCompleted(
+          failedTarget.getLabel(), configuration, failedAspect.getAspectName());
+    }
   }
 
   @Override