Add a new concept of failure causes

Not all possible reasons for failure are uniquely identified
by a label. Therefore, add a new data type describing possible
root causes of failures and use it.

The new type is added in causes/*.java and coresponds to Haskell's
one-line definition

  data Cause = LabelCause Label | ActionCause Path Label deriving Show

With future clean up of other failure causes inadequately described
by a label, we expect that type to be extended by new constructors
(i.e., new classes implementing Cause).

--
Change-Id: I6fec74c78cec6abb9c10e32743b05a792888fead
Reviewed-on: https://bazel-review.googlesource.com/#/c/6617
MOS_MIGRATED_REVID=137156390
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
index 81150a8..6fea59f 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.analysis;
 
 import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.causes.Cause;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
@@ -28,13 +28,12 @@
 public final class TargetCompleteEvent implements SkyValue {
 
   private final ConfiguredTarget target;
-  private final NestedSet<Label> rootCauses;
+  private final NestedSet<Cause> rootCauses;
 
-  private TargetCompleteEvent(ConfiguredTarget target, NestedSet<Label> rootCauses) {
+  private TargetCompleteEvent(ConfiguredTarget target, NestedSet<Cause> rootCauses) {
     this.target = target;
-    this.rootCauses = (rootCauses == null)
-        ? NestedSetBuilder.<Label>emptySet(Order.STABLE_ORDER)
-        : rootCauses;
+    this.rootCauses =
+        (rootCauses == null) ? NestedSetBuilder.<Cause>emptySet(Order.STABLE_ORDER) : rootCauses;
   }
 
   /**
@@ -47,7 +46,7 @@
   /**
    * Construct a target completion event for a failed target, with the given non-empty root causes.
    */
-  public static TargetCompleteEvent createFailed(ConfiguredTarget ct, NestedSet<Label> rootCauses) {
+  public static TargetCompleteEvent createFailed(ConfiguredTarget ct, NestedSet<Cause> rootCauses) {
     Preconditions.checkArgument(!Iterables.isEmpty(rootCauses));
     return new TargetCompleteEvent(ct, rootCauses);
   }
@@ -66,10 +65,8 @@
     return !rootCauses.isEmpty();
   }
 
-  /**
-   * Get the root causes of the target. May be empty.
-   */
-  public Iterable<Label> getRootCauses() {
+  /** Get the root causes of the target. May be empty. */
+  public Iterable<Cause> getRootCauses() {
     return rootCauses;
   }
 }