diff options
author | 2017-07-26 23:48:56 +0200 | |
---|---|---|
committer | 2017-07-27 09:05:18 +0200 | |
commit | 64c36e1a02a664c604fcff59bd55a0073e38a422 (patch) | |
tree | 618a52757d8c16957cf0deec02b946abe0bddd7a /src/main/java/com/google/devtools/build/lib/packages | |
parent | ab39f78d88bd0bfcf0664d95b06125416dd04033 (diff) |
Define an outgoing rule transition interface.
This lets a parent choose a transition for its dep based
on the dep's rule class.
Implement (experimental) dynamic Android resource filtering
trimming with this.
PiperOrigin-RevId: 163259052
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/RuleClass.java | 47 |
1 files changed, 42 insertions, 5 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 29a7fd9ec0..ae9ec0369e 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 @@ -491,6 +491,7 @@ public class RuleClass { private ImplicitOutputsFunction implicitOutputsFunction = ImplicitOutputsFunction.NONE; private Configurator<?, ?> configurator = NO_CHANGE; private RuleTransitionFactory transitionFactory; + private RuleTransitionFactory outgoingTransitionFactory; private ConfiguredTargetFactory<?, ?> configuredTargetFactory = null; private PredicateWithMessage<Rule> validityPredicate = PredicatesWithMessage.<Rule>alwaysTrue(); @@ -515,7 +516,7 @@ public class RuleClass { * Constructs a new {@code RuleClassBuilder} using all attributes from all * parent rule classes. An attribute cannot exist in more than one parent. * - * <p>The rule type affects the the allowed names and the required + * <p>The rule type affects the allowed names and the required * attributes (see {@link RuleClassType}). * * @throws IllegalArgumentException if an attribute with the same name exists @@ -609,6 +610,7 @@ public class RuleClass { isConfigMatcher, configurator, transitionFactory, + outgoingTransitionFactory, configuredTargetFactory, validityPredicate, preferredDependencyPredicate, @@ -752,11 +754,13 @@ public class RuleClass { } /** - * Applies the given transition to all incoming edges for this rule class. Does not work with - * static configurations. + * Applies the given transition to all incoming edges for this rule class. * - * <p>Note that the given transition must be a PatchTransition instance. We use the more - * general Transtion here because PatchTransition is not available in this package. + * <p>The given transition must be a PatchTransition. We use the more general Transition + * here because PatchTransition is not available in this package. + * + * <p>If you need the transition to depend on the rule it's being applied to, use + * {@link #cfg(RuleTransitionFactory)}. */ public Builder cfg(Transition transition) { Preconditions.checkState(type != RuleClassType.ABSTRACT, @@ -768,6 +772,12 @@ public class RuleClass { return this; } + /** + * Applies the given transition factory to all incoming edges for this rule class. + * + * <p>Unlike{@link #cfg(Transition)}, the factory can examine the rule when deciding what + * transition to use. + */ public Builder cfg(RuleTransitionFactory transitionFactory) { Preconditions.checkState(type != RuleClassType.ABSTRACT, "Setting not inherited property (cfg) of abstract rule class '%s'", name); @@ -778,6 +788,22 @@ public class RuleClass { return this; } + /** + * Applies the given transition factory to all deps of this rule class. + * + * <p>This means that for each dep, the factory can examine the dep's {@link Rule} to + * determine the right transition for that dep. + */ + public Builder depsCfg(RuleTransitionFactory outgoingTransitionFactory) { + Preconditions.checkState(type != RuleClassType.ABSTRACT, + "Setting not inherited property (configureDeps) of abstract rule class '%s'", name); + Preconditions.checkState(this.outgoingTransitionFactory == null, + "Property configureDeps has already been set"); + Preconditions.checkNotNull(outgoingTransitionFactory); + this.outgoingTransitionFactory = outgoingTransitionFactory; + return this; + } + public Builder factory(ConfiguredTargetFactory<?, ?> factory) { this.configuredTargetFactory = factory; return this; @@ -1073,6 +1099,11 @@ public class RuleClass { private final RuleTransitionFactory transitionFactory; /** + * A factory which will produce custom configuration transitions for each dep of this rule. + */ + private final RuleTransitionFactory outgoingTransitionFactory; + + /** * The factory that creates configured targets from this rule. */ private final ConfiguredTargetFactory<?, ?> configuredTargetFactory; @@ -1163,6 +1194,7 @@ public class RuleClass { boolean isConfigMatcher, Configurator<?, ?> configurator, RuleTransitionFactory transitionFactory, + RuleTransitionFactory outgoingRuleTransitionFactory, ConfiguredTargetFactory<?, ?> configuredTargetFactory, PredicateWithMessage<Rule> validityPredicate, Predicate<String> preferredDependencyPredicate, @@ -1188,6 +1220,7 @@ public class RuleClass { this.isConfigMatcher = isConfigMatcher; this.configurator = Preconditions.checkNotNull(configurator); this.transitionFactory = transitionFactory; + this.outgoingTransitionFactory = outgoingRuleTransitionFactory; this.configuredTargetFactory = configuredTargetFactory; this.validityPredicate = validityPredicate; this.preferredDependencyPredicate = preferredDependencyPredicate; @@ -1263,6 +1296,10 @@ public class RuleClass { return transitionFactory; } + public RuleTransitionFactory getOutgoingTransitionFactory() { + return outgoingTransitionFactory; + } + @SuppressWarnings("unchecked") public <CT, RC> ConfiguredTargetFactory<CT, RC> getConfiguredTargetFactory() { return (ConfiguredTargetFactory<CT, RC>) configuredTargetFactory; |