aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/RuleClass.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/RuleClass.java41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index ed2ad3064c..9accac3899 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -1401,6 +1401,7 @@ public final class RuleClass {
boolean explicit = attributeValues.isAttributeExplicitlySpecified(attributeName);
setRuleAttributeValue(rule, eventHandler, attr, nativeAttributeValue, explicit);
definedAttrIndices.set(attrIndex);
+ checkAttrValNonEmpty(rule, eventHandler, attributeValue, attr);
}
return definedAttrIndices;
}
@@ -1456,6 +1457,7 @@ public final class RuleClass {
attrsWithComputedDefaults.add(attr);
} else {
Object defaultValue = getAttributeNoncomputedDefaultValue(attr, pkgBuilder);
+ checkAttrValNonEmpty(rule, eventHandler, defaultValue, attr);
rule.setAttributeValue(attr, defaultValue, /*explicit=*/ false);
checkAllowedValues(rule, attr, eventHandler);
}
@@ -1498,27 +1500,26 @@ public final class RuleClass {
/*explicit=*/false);
}
- public void checkAttributesNonEmpty(
- Rule rule, RuleErrorConsumer ruleErrorConsumer, AttributeMap attributes) {
- for (String attributeName : attributes.getAttributeNames()) {
- Attribute attr = attributes.getAttributeDefinition(attributeName);
- if (!attr.isNonEmpty()) {
- continue;
- }
- Object attributeValue = attributes.get(attributeName, attr.getType());
-
- boolean isEmpty = false;
- if (attributeValue instanceof SkylarkList) {
- isEmpty = ((SkylarkList) attributeValue).isEmpty();
- } else if (attributeValue instanceof List<?>) {
- isEmpty = ((List<?>) attributeValue).isEmpty();
- } else if (attributeValue instanceof Map<?, ?>) {
- isEmpty = ((Map<?, ?>) attributeValue).isEmpty();
- }
+ private void checkAttrValNonEmpty(
+ Rule rule, EventHandler eventHandler, Object attributeValue, Attribute attr) {
+ if (!attr.isNonEmpty()) {
+ return;
+ }
- if (isEmpty) {
- ruleErrorConsumer.attributeError(attr.getName(), "attribute must be non empty");
- }
+ boolean isEmpty = false;
+
+ if (attributeValue instanceof SkylarkList) {
+ isEmpty = ((SkylarkList) attributeValue).isEmpty();
+ } else if (attributeValue instanceof List<?>) {
+ isEmpty = ((List<?>) attributeValue).isEmpty();
+ } else if (attributeValue instanceof Map<?, ?>) {
+ isEmpty = ((Map<?, ?>) attributeValue).isEmpty();
+ }
+
+ if (isEmpty) {
+ rule.reportError(rule.getLabel() + ": non empty attribute '" + attr.getName()
+ + "' in '" + name + "' rule '" + rule.getLabel() + "' has to have at least one value",
+ eventHandler);
}
}