aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2015-10-28 20:49:22 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-10-29 07:47:10 +0000
commit4a10251278872f8f00228da8a6a0e0d98f10bdc4 (patch)
tree414cf9a6223f3516ca629403bb2ba75de355b2ac /src/main/java/com/google/devtools/build
parent0446c95d4e2f5e4a084744a10c87d631a92b3be0 (diff)
Provide a way to explicitly constraint-enforce
attributes that would otherwise be skipped by default policy. This is the simplistic start to a user-controllable enforcement policy API. -- MOS_MIGRATED_REVID=106530210
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java22
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/Attribute.java24
2 files changed, 36 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
index 8355f1d322..9997de4cb2 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
@@ -523,16 +523,18 @@ public class ConstraintSemantics {
Type<?> attrType = attributes.getAttributeType(attr);
// TODO(bazel-team): support a user-definable API for choosing which attributes are checked
- if ((attrType != BuildType.LABEL && attrType != BuildType.LABEL_LIST)
- || RuleClass.isConstraintAttribute(attr)
- || attr.equals("visibility")
- // Use the same implicit deps check that query uses. This facilitates running queries to
- // determine exactly which rules need to be constraint-annotated for depot migrations.
- || !Rule.NO_IMPLICIT_DEPS.apply(ruleContext.getRule(), attrDef)
- // We can't identify host deps by calling BuildConfiguration.isHostConfiguration()
- // because --nodistinct_host_configuration subverts that call.
- || attrDef.getConfigurationTransition() == Attribute.ConfigurationTransition.HOST) {
- continue;
+ if (!attrDef.checkConstraintsOverride()) {
+ if ((attrType != BuildType.LABEL && attrType != BuildType.LABEL_LIST)
+ || RuleClass.isConstraintAttribute(attr)
+ || attr.equals("visibility")
+ // Use the same implicit deps check that query uses. This facilitates running queries to
+ // determine exactly which rules need to be constraint-annotated for depot migrations.
+ || !Rule.NO_IMPLICIT_DEPS.apply(ruleContext.getRule(), attrDef)
+ // We can't identify host deps by calling BuildConfiguration.isHostConfiguration()
+ // because --nodistinct_host_configuration subverts that call.
+ || attrDef.getConfigurationTransition() == Attribute.ConfigurationTransition.HOST) {
+ continue;
+ }
}
for (TransitiveInfoCollection dep :
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
index a987570736..63a1a3c517 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
@@ -207,6 +207,13 @@ public final class Attribute implements Comparable<Attribute> {
* (for visibility, etc.).
*/
SKIP_PREREQ_VALIDATOR_CHECKS,
+
+ /**
+ * Whether we should check constraints on dependencies under this attribute
+ * (see {@link com.google.devtools.build.lib.analysis.constraints.ConstraintSemantics}). If set,
+ * the attribute is constraint-enforced even if default enforcement policy would skip it.
+ */
+ CHECK_CONSTRAINTS,
}
// TODO(bazel-team): modify this interface to extend Predicate and have an extra error
@@ -536,6 +543,19 @@ public final class Attribute implements Comparable<Attribute> {
}
/**
+ * Enforces constraint checking on dependencies under this attribute. Not calling this method
+ * does <i>not</i> mean the attribute won't be enforced. This method simply overrides default
+ * enforcement policy, so it's useful for special-case attributes that would otherwise be
+ * skipped.
+ *
+ * <p>See {@link com.google.devtools.build.lib.analysis.constraints.ConstraintSemantics#getConstraintCheckedDependencies}
+ * for default enforcement policy.
+ */
+ public Builder<TYPE> checkConstraints() {
+ return setPropertyFlag(PropertyFlag.CHECK_CONSTRAINTS, "check_constraints");
+ }
+
+ /**
* If this is a label or label-list attribute, then this sets the allowed
* rule types for the labels occurring in the attribute. If the attribute
* contains Labels of any other rule type, then an error is produced during
@@ -1257,6 +1277,10 @@ public final class Attribute implements Comparable<Attribute> {
return !getPropertyFlag(PropertyFlag.SKIP_PREREQ_VALIDATOR_CHECKS);
}
+ public boolean checkConstraintsOverride() {
+ return getPropertyFlag(PropertyFlag.CHECK_CONSTRAINTS);
+ }
+
/**
* Returns true if this attribute's value can be influenced by the build configuration.
*/