diff options
author | 2016-05-04 17:47:59 +0000 | |
---|---|---|
committer | 2016-05-04 18:32:23 +0000 | |
commit | 178a3dfda8bf72abf22758597a90a4afb8eed181 (patch) | |
tree | 7259ea286768d14b97088a1de7ef867f829179c5 /src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java | |
parent | 87a58589d6770a6e9a0f998274bfe69f1feb6014 (diff) |
Allow modules to inject a custom AttributeContainer.
--
MOS_MIGRATED_REVID=121497233
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java index 4837b04763..3b6cf4c904 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.packages; +import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; @@ -47,11 +48,15 @@ public class RuleFactory { * Maps rule class name to the metaclass instance for that rule. */ private final ImmutableMap<String, RuleClass> ruleClassMap; + private final Function<RuleClass, AttributeContainer> attributeContainerFactory; /** * Constructs a RuleFactory instance. */ - public RuleFactory(RuleClassProvider provider) { + public RuleFactory( + RuleClassProvider provider, + Function<RuleClass, AttributeContainer> attributeContainerFactory) { + this.attributeContainerFactory = attributeContainerFactory; this.ruleClassMap = ImmutableMap.copyOf(provider.getRuleClassMap()); } @@ -69,6 +74,14 @@ public class RuleFactory { return ruleClassMap.get(ruleClassName); } + AttributeContainer getAttributeContainer(RuleClass ruleClass) { + return attributeContainerFactory.apply(ruleClass); + } + + Function<RuleClass, AttributeContainer> getAttributeContainerFactory() { + return attributeContainerFactory; + } + /** * Creates and returns a rule instance. * @@ -82,7 +95,8 @@ public class RuleFactory { EventHandler eventHandler, @Nullable FuncallExpression ast, Location location, - @Nullable Environment env) + @Nullable Environment env, + AttributeContainer attributeContainer) throws InvalidRuleException, InterruptedException { Preconditions.checkNotNull(ruleClass); String ruleClassName = ruleClass.getName(); @@ -120,7 +134,7 @@ public class RuleFactory { eventHandler, ast, generator.location, - new AttributeContainer(ruleClass)); + attributeContainer); } catch (LabelSyntaxException e) { throw new RuleFactory.InvalidRuleException(ruleClass + " " + e.getMessage()); } @@ -141,6 +155,7 @@ public class RuleFactory { * @param ast the abstract syntax tree of the rule expression (optional) * @param location the location at which this rule was declared * @param env the lexical environment of the function call which declared this rule (optional) + * @param attributeContainer the {@link AttributeContainer} the rule will contain * @throws InvalidRuleException if the rule could not be constructed for any * reason (e.g. no {@code name} attribute is defined) * @throws NameConflictException if the rule's name or output files conflict with others in this @@ -154,10 +169,19 @@ public class RuleFactory { EventHandler eventHandler, @Nullable FuncallExpression ast, Location location, - @Nullable Environment env) + @Nullable Environment env, + AttributeContainer attributeContainer) throws InvalidRuleException, NameConflictException, InterruptedException { - Rule rule = createRule( - pkgBuilder, ruleClass, attributeValues, eventHandler, ast, location, env); + Rule rule = + createRule( + pkgBuilder, + ruleClass, + attributeValues, + eventHandler, + ast, + location, + env, + attributeContainer); pkgBuilder.addRule(rule); return rule; } @@ -175,6 +199,7 @@ public class RuleFactory { * @param ast the abstract syntax tree of the rule expression (mandatory because this looks up a * {@link Location} from the {@code ast}) * @param env the lexical environment of the function call which declared this rule (optional) + * @param attributeContainer the {@link AttributeContainer} the rule will contain * @throws InvalidRuleException if the rule could not be constructed for any reason (e.g. no * {@code name} attribute is defined) * @throws NameConflictException if the rule's name or output files conflict with others in this @@ -186,7 +211,8 @@ public class RuleFactory { RuleClass ruleClass, BuildLangTypedAttributeValuesMap attributeValues, FuncallExpression ast, - @Nullable Environment env) + @Nullable Environment env, + AttributeContainer attributeContainer) throws InvalidRuleException, NameConflictException, InterruptedException { return createAndAddRule( context.pkgBuilder, @@ -195,7 +221,8 @@ public class RuleFactory { context.eventHandler, ast, ast.getLocation(), - env); + env, + attributeContainer); } /** |