diff options
author | Nathan Harmata <nharmata@google.com> | 2016-04-13 16:56:58 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-04-14 07:37:49 +0000 |
commit | fcb17112bfbb598954306ee197a842ec8f4e8e64 (patch) | |
tree | 6836080bdfb79683aa099f1fe445a7721bf820e8 /src/main/java/com/google/devtools/build/lib/packages/RuleClass.java | |
parent | f5700b661838d4e22ffeea7b224c38b936d5e14d (diff) |
Roll-foward of commit 351475627b9e94e5afdf472cbf465f49c433a25e which was rolled back in commit 1250fdac4c7769cfa200af8b4f9b061024356fea. There was nothing wrong with that change.
--
MOS_MIGRATED_REVID=119756383
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.java | 41 |
1 files changed, 20 insertions, 21 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 9accac3899..ed2ad3064c 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,7 +1401,6 @@ 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; } @@ -1457,7 +1456,6 @@ 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); } @@ -1500,26 +1498,27 @@ public final class RuleClass { /*explicit=*/false); } - private void checkAttrValNonEmpty( - Rule rule, EventHandler eventHandler, Object attributeValue, Attribute attr) { - if (!attr.isNonEmpty()) { - return; - } - - 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(); - } + 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(); + } - if (isEmpty) { - rule.reportError(rule.getLabel() + ": non empty attribute '" + attr.getName() - + "' in '" + name + "' rule '" + rule.getLabel() + "' has to have at least one value", - eventHandler); + if (isEmpty) { + ruleErrorConsumer.attributeError(attr.getName(), "attribute must be non empty"); + } } } |