RuleContext: support visibility check for labels
...instead of only for rules. Separating out the check allows
checking visibility against other sources than rule, e.g., the bzl
file a rule is defined in for implicit attributes.
@@ -1532,17 +1532,17 @@ public final class RuleContext extends TargetContext
}
/**
- * @return true if {@code rule} is visible from {@code prerequisite}.
+ * Returns true if {@code label} is visible from {@code prerequisite}.
*
* <p>This only computes the logic as implemented by the visibility system. The final decision
- * whether a dependency is allowed is made by
- * {@link ConfiguredRuleClassProvider.PrerequisiteValidator}.
+ * whether a dependency is allowed is made by {@link
+ * ConfiguredRuleClassProvider.PrerequisiteValidator}.
*/
- public static boolean isVisible(Rule rule, TransitiveInfoCollection prerequisite) {
+ public static boolean isVisible(Label label, TransitiveInfoCollection prerequisite) {
// Check visibility attribute
for (PackageGroupContents specification :
prerequisite.getProvider(VisibilityProvider.class).getVisibility()) {
- if (specification.containsPackage(rule.getLabel().getPackageIdentifier())) {
+ if (specification.containsPackage(label.getPackageIdentifier())) {
return true;
}
}
@@ -1550,6 +1550,17 @@ public final class RuleContext extends TargetContext
return false;
}
+ /**
+ * Returns true if {@code rule} is visible from {@code prerequisite}.
+ *
+ * <p>This only computes the logic as implemented by the visibility system. The final decision
+ * whether a dependency is allowed is made by {@link
+ * ConfiguredRuleClassProvider.PrerequisiteValidator}.
+ */
+ public static boolean isVisible(Rule rule, TransitiveInfoCollection prerequisite) {
+ return isVisible(rule.getLabel(), prerequisite);
+ }
+
/**
* @return the set of features applicable for the current rule's package.
*/
