aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Michael Staib <mstaib@google.com>2016-09-16 21:06:40 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-19 07:35:12 +0000
commit2707a886681e14fc22edca4c6c4bccca12018083 (patch)
tree9cd4e2e596c26e685f474c7fb6a4fcf9291a91e6 /src/main/java/com/google/devtools/build
parent8618b9d67d20a737908113fa89357ac321a9669b (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java4
4 files changed, 19 insertions, 10 deletions
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 3f018d37eb..2037dbbb38 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 class ConfiguredRuleClassProvider implements RuleClassProvider {
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 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
/** 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 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
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 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
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);
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index b988b4d195..f160424223 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -1711,6 +1711,11 @@ public final class RuleContext extends TargetContext
}
}
+ /** Returns whether the context being constructed is for the evaluation of an aspect. */
+ public boolean forAspect() {
+ return aspectName != null;
+ }
+
public Rule getRule() {
return rule;
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
index 90b064a929..755c246f37 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
@@ -183,7 +183,7 @@ public class BazelRuleClassProvider {
ConfiguredTarget prerequisite, Attribute attribute) {
validateDirectPrerequisiteVisibility(context, prerequisite, attribute.getName());
DeprecationValidator.validateDirectPrerequisiteForDeprecation(
- context, context.getRule(), prerequisite);
+ context, context.getRule(), prerequisite, context.forAspect());
}
private void validateDirectPrerequisiteVisibility(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
index 4035242c4e..ba84c5b7fb 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
@@ -376,10 +376,10 @@ public final class AspectFunction implements SkyFunction {
transitivePackages.build());
}
- @Nullable
@Override
public String extractTag(SkyKey skyKey) {
- return null;
+ AspectKey aspectKey = (AspectKey) skyKey.argument();
+ return Label.print(aspectKey.getLabel());
}
/**