Describe failed action sources in more detail.

Specifically, some actions are registered by aspects, so mention the aspects when `--verbose_failures` is mentioned.

PiperOrigin-RevId: 684530757
Change-Id: I7b74fcfccc92ce686fd9e078592d1ce31d799c41
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java
index 02ecff7..030a725 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java
@@ -24,7 +24,6 @@
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
 import com.google.devtools.build.lib.bugreport.BugReporter;
 import com.google.devtools.build.lib.clock.Clock;
-import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventKind;
@@ -463,7 +462,7 @@
     if (owner == null) {
       reason.append(spawn.getResourceOwner().prettyPrint());
     } else {
-      reason.append(Label.print(owner.getLabel()));
+      reason.append(owner.getDescription());
       reason.append(" [");
       reason.append(spawn.getResourceOwner().prettyPrint());
       reason.append(", configuration: ");
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionOwner.java b/src/main/java/com/google/devtools/build/lib/actions/ActionOwner.java
index 566be00..21b2cd9 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionOwner.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionOwner.java
@@ -13,6 +13,8 @@
 // limitations under the License.
 package com.google.devtools.build.lib.actions;
 
+import static java.util.stream.Collectors.joining;
+
 import com.google.auto.value.AutoValue;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
@@ -99,6 +101,27 @@
         execProperties);
   }
 
+  @Nullable
+  public String getDescription() {
+    Label label = getLabel();
+    if (label == null) {
+      return null;
+    }
+    String targetDescription = "target " + label;
+
+    ImmutableList<AspectDescriptor> aspectDescriptors = getAspectDescriptors();
+    if (aspectDescriptors.isEmpty()) {
+      return targetDescription;
+    }
+
+    String aspectNames =
+        aspectDescriptors.stream().map(AspectDescriptor::getDescription).collect(joining(", "));
+
+    return String.format(
+        "aspect%s [%s] on %s",
+        aspectDescriptors.size() >= 1 ? "s" : "", aspectNames, targetDescription);
+  }
+
   /**
    * Returns the label for this {@link ActionOwner}, or null if the {@link #SYSTEM_ACTION_OWNER}.
    */
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Spawn.java b/src/main/java/com/google/devtools/build/lib/actions/Spawn.java
index 5bec063..08f85bd 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Spawn.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Spawn.java
@@ -180,6 +180,11 @@
 
   @Override
   @Nullable
+  default String getTargetDescription() {
+    return getResourceOwner().getOwner().getDescription();
+  }
+
+  @Nullable
   default Label getTargetLabel() {
     return getResourceOwner().getOwner().getLabel();
   }
diff --git a/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java b/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java
index c516007..d765380 100644
--- a/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java
@@ -151,7 +151,7 @@
       Map<String, String> env,
       @Nullable String cwd,
       @Nullable String configurationChecksum,
-      @Nullable Label targetLabel,
+      @Nullable String targetDescription,
       @Nullable Label executionPlatformLabel) {
 
     String commandName = commandLineElements.iterator().next();
@@ -166,8 +166,8 @@
     output.append("error executing ");
     output.append(mnemonic);
     output.append(" command ");
-    if (targetLabel != null) {
-      output.append("(from target ").append(targetLabel).append(") ");
+    if (targetDescription != null) {
+      output.append("(from ").append(targetDescription).append(") ");
     }
     if (verbose) {
       output.append("\n  ");
@@ -194,7 +194,7 @@
         command.getEnvironment(),
         cwd,
         command.getConfigurationChecksum(),
-        command.getTargetLabel(),
+        command.getTargetDescription(),
         command.getExecutionPlatformLabel());
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/util/DescribableExecutionUnit.java b/src/main/java/com/google/devtools/build/lib/util/DescribableExecutionUnit.java
index 6ccc9a3..c0aece5 100644
--- a/src/main/java/com/google/devtools/build/lib/util/DescribableExecutionUnit.java
+++ b/src/main/java/com/google/devtools/build/lib/util/DescribableExecutionUnit.java
@@ -24,7 +24,7 @@
 public interface DescribableExecutionUnit {
 
   @Nullable
-  default Label getTargetLabel() {
+  default String getTargetDescription() {
     return null;
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java b/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java
index d4949df..5c4f7eb 100644
--- a/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java
@@ -50,7 +50,7 @@
             env,
             cwd,
             "cfg12345",
-            target,
+            "target " + target,
             executionPlatform.label());
     assertThat(message)
         .isEqualTo(
@@ -79,7 +79,7 @@
             env,
             cwd,
             "cfg12345",
-            target,
+            "target " + target,
             executionPlatform.label());
     assertThat(message)
         .isEqualTo(
@@ -116,7 +116,7 @@
             env,
             cwd,
             "cfg12345",
-            target,
+            "target " + target,
             executionPlatform.label());
     assertThat(message)
         .isEqualTo(
@@ -152,7 +152,7 @@
             env,
             cwd,
             "cfg12345",
-            target,
+            "target " + target,
             executionPlatform.label());
     assertThat(message)
         .isEqualTo(
@@ -190,7 +190,7 @@
             env,
             cwd,
             "cfg12345",
-            target,
+            "target " + target,
             executionPlatform.label());
     assertThat(message)
         .isEqualTo(