diff options
author | 2015-10-05 14:06:12 +0000 | |
---|---|---|
committer | 2015-10-05 15:16:48 +0000 | |
commit | e2b7223e219ae71bf0e1dfe8eb47278ef3510a9f (patch) | |
tree | e10017492aa46a2b23facd985940275e46d4e9f1 /src/main/java/com/google/devtools/build | |
parent | 78ef8c9534f1f18b7033f0e09bf5e575f8b600df (diff) |
Move the special rule creation method for deserialization to the only usage (PackageDeserialization).
--
MOS_MIGRATED_REVID=104654412
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java | 55 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/RuleClass.java | 66 |
2 files changed, 54 insertions, 67 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java index ab58edd603..18da84aafd 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.events.StoredEventHandler; @@ -34,7 +35,6 @@ import com.google.devtools.build.lib.packages.License.DistributionType; import com.google.devtools.build.lib.packages.License.LicenseParsingException; import com.google.devtools.build.lib.packages.Package.Builder.GeneratedLabelConflict; import com.google.devtools.build.lib.packages.Package.NameConflictException; -import com.google.devtools.build.lib.packages.RuleClass.ParsedAttributeValue; import com.google.devtools.build.lib.query2.proto.proto2api.Build; import com.google.devtools.build.lib.query2.proto.proto2api.Build.StringDictUnaryEntry; import com.google.devtools.build.lib.syntax.GlobCriteria; @@ -176,7 +176,7 @@ public class PackageDeserializer { Label ruleLabel = deserializeLabel(rulePb.getName()); try { - Rule rule = ruleClass.createRuleWithParsedAttributeValues( + Rule rule = createRuleWithParsedAttributeValues(ruleClass, ruleLabel, context.packageBuilder, ruleLocation, attributeValues, NullEventHandler.INSTANCE, new AttributeContainerWithoutLocation(ruleClass)); context.packageBuilder.addRule(rule); @@ -644,4 +644,55 @@ public class PackageDeserializer { } } + /** + * Creates a rule with the attribute values that are already parsed. + * + * <p><b>WARNING:</b> This assumes that the attribute values here have the right type and + * bypasses some sanity checks. If they are of the wrong type, everything will come down burning. + */ + @SuppressWarnings("unchecked") + private static Rule createRuleWithParsedAttributeValues(RuleClass ruleClass, Label label, + Package.Builder pkgBuilder, Location ruleLocation, + Map<String, ParsedAttributeValue> attributeValues, EventHandler eventHandler, + AttributeContainer attributeContainer) + throws LabelSyntaxException, InterruptedException { + Rule rule = pkgBuilder.newRuleWithLabelAndAttrContainer(label, ruleClass, null, ruleLocation, + attributeContainer); + rule.checkValidityPredicate(eventHandler); + + for (Attribute attribute : rule.getRuleClassObject().getAttributes()) { + ParsedAttributeValue value = attributeValues.get(attribute.getName()); + if (attribute.isMandatory()) { + Preconditions.checkState(value != null); + } + + if (value == null) { + continue; + } + + rule.setAttributeValue(attribute, value.value, value.explicitlySpecified); + ruleClass.checkAllowedValues(rule, attribute, eventHandler); + + if (attribute.getName().equals("visibility")) { + // TODO(bazel-team): Verify that this cast works + rule.setVisibility(PackageFactory.getVisibility((List<Label>) value.value)); + } + } + + rule.populateOutputFiles(eventHandler, pkgBuilder); + Preconditions.checkState(!rule.containsErrors()); + return rule; + } + + private static class ParsedAttributeValue { + private final boolean explicitlySpecified; + private final Object value; + private final Location location; + + private ParsedAttributeValue(boolean explicitlySpecified, Object value, Location location) { + this.explicitlySpecified = explicitlySpecified; + this.value = value; + this.location = location; + } + } } 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 663498860f..f356f25d16 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 @@ -1244,70 +1244,6 @@ public final class RuleClass { rule.checkValidityPredicate(eventHandler); } - static class ParsedAttributeValue { - private final boolean explicitlySpecified; - private final Object value; - private final Location location; - - ParsedAttributeValue(boolean explicitlySpecified, Object value, Location location) { - this.explicitlySpecified = explicitlySpecified; - this.value = value; - this.location = location; - } - - public boolean getExplicitlySpecified() { - return explicitlySpecified; - } - - public Object getValue() { - return value; - } - - public Location getLocation() { - return location; - } - } - - /** - * Creates a rule with the attribute values that are already parsed. - * - * <p><b>WARNING:</b> This assumes that the attribute values here have the right type and - * bypasses some sanity checks. If they are of the wrong type, everything will come down burning. - */ - @SuppressWarnings("unchecked") - Rule createRuleWithParsedAttributeValues(Label label, - Package.Builder pkgBuilder, Location ruleLocation, - Map<String, ParsedAttributeValue> attributeValues, EventHandler eventHandler, - AttributeContainer attributeContainer) - throws LabelSyntaxException, InterruptedException { - Rule rule = pkgBuilder.newRuleWithLabelAndAttrContainer(label, this, null, ruleLocation, - attributeContainer); - rule.checkValidityPredicate(eventHandler); - - for (Attribute attribute : rule.getRuleClassObject().getAttributes()) { - ParsedAttributeValue value = attributeValues.get(attribute.getName()); - if (attribute.isMandatory()) { - Preconditions.checkState(value != null); - } - - if (value == null) { - continue; - } - - rule.setAttributeValue(attribute, value.getValue(), value.getExplicitlySpecified()); - checkAllowedValues(rule, attribute, eventHandler); - - if (attribute.getName().equals("visibility")) { - // TODO(bazel-team): Verify that this cast works - rule.setVisibility(PackageFactory.getVisibility((List<Label>) value.getValue())); - } - } - - rule.populateOutputFiles(eventHandler, pkgBuilder); - Preconditions.checkState(!rule.containsErrors()); - return rule; - } - /** * Populates the attributes table of new rule "rule" from the * "attributeValues" mapping from attribute names to values in the build @@ -1597,7 +1533,7 @@ public final class RuleClass { * <p>If the rule is configurable, all of its potential values are evaluated, and errors for each * of the invalid values are reported. */ - private void checkAllowedValues(Rule rule, Attribute attribute, EventHandler eventHandler) { + void checkAllowedValues(Rule rule, Attribute attribute, EventHandler eventHandler) { if (attribute.checkAllowedValues()) { PredicateWithMessage<Object> allowedValues = attribute.getAllowedValues(); Iterable<?> values = |