Enable aspect invocations to be matched by output filters.

Currently aspects have no tag, i.e., they don't get checked against output
filters at all. This changes aspects to have a tag of the same form as the
rule they are attached to (i.e., the label of the target).

Since the default output filters match on ^//package[:/], this should cover
most uses of the output filter, while still allowing for finer control for
those who crave it.

--
MOS_MIGRATED_REVID=133425215
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
index 3f018d3..2037dbb 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
@@ -97,7 +97,7 @@
     public void validate(
         RuleContext.Builder contextBuilder, ConfiguredTarget prerequisite, Attribute attribute) {
       validateDirectPrerequisiteForDeprecation(
-          contextBuilder, contextBuilder.getRule(), prerequisite);
+          contextBuilder, contextBuilder.getRule(), prerequisite, contextBuilder.forAspect());
     }
 
     /**
@@ -128,18 +128,22 @@
     /** Returns whether a deprecation warning should be printed for the prerequisite described. */
     private static boolean shouldEmitDeprecationWarningFor(
         String thisDeprecation, PackageIdentifier thisPackage,
-        String prerequisiteDeprecation, PackageIdentifier prerequisitePackage) {
+        String prerequisiteDeprecation, PackageIdentifier prerequisitePackage,
+        boolean forAspect) {
       // Don't report deprecation edges from javatests to java or within a package;
       // otherwise tests of deprecated code generate nuisance warnings.
-      // Don't report deprecation if the current target is also deprecated.
-      return (prerequisiteDeprecation != null
+      // Don't report deprecation if the current target is also deprecated,
+      // or if the current context is evaluating an aspect,
+      // as the base target would have already printed the deprecation warnings.
+      return (!forAspect
+          && prerequisiteDeprecation != null
           && !isSameLogicalPackage(thisPackage, prerequisitePackage)
           && thisDeprecation == null);
     }
 
     /** Checks if the given prerequisite is deprecated and prints a warning if so. */
     public static void validateDirectPrerequisiteForDeprecation(
-        RuleErrorConsumer errors, Rule rule, ConfiguredTarget prerequisite) {
+        RuleErrorConsumer errors, Rule rule, ConfiguredTarget prerequisite, boolean forAspect) {
       Target prerequisiteTarget = prerequisite.getTarget();
       Label prerequisiteLabel = prerequisiteTarget.getLabel();
       PackageIdentifier thatPackage = prerequisiteLabel.getPackageIdentifier();
@@ -152,7 +156,7 @@
         String thatDeprecation =
             NonconfigurableAttributeMapper.of(prerequisiteRule).get("deprecation", Type.STRING);
         if (shouldEmitDeprecationWarningFor(
-            thisDeprecation, thisPackage, thatDeprecation, thatPackage)) {
+            thisDeprecation, thisPackage, thatDeprecation, thatPackage, forAspect)) {
           errors.ruleWarning("target '" + rule.getLabel() +  "' depends on deprecated target '"
               + prerequisiteLabel + "': " + thatDeprecation);
         }
@@ -165,7 +169,7 @@
         String thatDeprecation =
             NonconfigurableAttributeMapper.of(generatingRule).get("deprecation", Type.STRING);
         if (shouldEmitDeprecationWarningFor(
-            thisDeprecation, thisPackage, thatDeprecation, thatPackage)) {
+            thisDeprecation, thisPackage, thatDeprecation, thatPackage, forAspect)) {
           errors.ruleWarning("target '" + rule.getLabel() + "' depends on the output file "
               + prerequisiteLabel + " of a deprecated rule " + generatingRule.getLabel()
               + "': " + thatDeprecation);