Make aspects work through bind().
bind() is assumed to be able to provide any provider. This is suboptimal, but beats the alternative of traversing the dependency graph to an arbitrary depth.
The reason for the removal of the iteration ability in TransitiveInfoCollection is that now aspects can be attached to BindConfiguredTarget, too, which is not a RuleConfiguredTarget. Whereas I could have implemented the iterator, it was used only in BindConfiguredTarget anyway, so there didn't seem to be much reason to.
Some work towards #952.
--
MOS_MIGRATED_REVID=120549877
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 18e69a2..7fd42dc 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
@@ -477,6 +477,7 @@
PredicatesWithMessage.<Rule>alwaysTrue();
private Predicate<String> preferredDependencyPredicate = Predicates.alwaysFalse();
private List<Class<?>> advertisedProviders = new ArrayList<>();
+ private boolean canHaveAnyProvider = false;
private BaseFunction configuredTargetFunction = null;
private Function<? super Rule, Map<String, Label>> externalBindingsFunction =
NO_EXTERNAL_BINDINGS;
@@ -571,7 +572,7 @@
return new RuleClass(name, skylark, skylarkExecutable, documented, publicByDefault,
binaryOutput, workspaceOnly, outputsDefaultExecutable, implicitOutputsFunction,
configurator, configuredTargetFactory, validityPredicate, preferredDependencyPredicate,
- ImmutableSet.copyOf(advertisedProviders), configuredTargetFunction,
+ ImmutableSet.copyOf(advertisedProviders), canHaveAnyProvider, configuredTargetFunction,
externalBindingsFunction, ruleDefinitionEnvironment, configurationFragmentPolicy.build(),
supportsConstraintChecking, attributes.values().toArray(new Attribute[0]));
}
@@ -726,10 +727,21 @@
* not be evaluated for the rule.
*/
public Builder advertiseProvider(Class<?>... providers) {
+ Preconditions.checkState(!canHaveAnyProvider);
Collections.addAll(advertisedProviders, providers);
return this;
}
+ /**
+ * Set if the rule can have any provider. This is true for "alias" rules like
+ * <code>bind</code> .
+ */
+ public Builder canHaveAnyProvider() {
+ Preconditions.checkState(advertisedProviders.isEmpty());
+ canHaveAnyProvider = true;
+ return this;
+ }
+
private void addAttribute(Attribute attribute) {
Preconditions.checkState(!attributes.containsKey(attribute.getName()),
"An attribute with the name '%s' already exists.", attribute.getName());
@@ -967,6 +979,8 @@
*/
private final ImmutableSet<Class<?>> advertisedProviders;
+ private final boolean canHaveAnyProvider;
+
/**
* The Skylark rule implementation of this RuleClass. Null for non Skylark executable RuleClasses.
*/
@@ -1012,6 +1026,7 @@
PredicateWithMessage<Rule> validityPredicate,
Predicate<String> preferredDependencyPredicate,
ImmutableSet<Class<?>> advertisedProviders,
+ boolean canHaveAnyProvider,
@Nullable BaseFunction configuredTargetFunction,
Function<? super Rule, Map<String, Label>> externalBindingsFunction,
@Nullable Environment ruleDefinitionEnvironment,
@@ -1033,6 +1048,7 @@
validityPredicate,
preferredDependencyPredicate,
advertisedProviders,
+ canHaveAnyProvider,
configuredTargetFunction,
externalBindingsFunction,
ruleDefinitionEnvironment,
@@ -1075,6 +1091,7 @@
ConfiguredTargetFactory<?, ?> configuredTargetFactory,
PredicateWithMessage<Rule> validityPredicate, Predicate<String> preferredDependencyPredicate,
ImmutableSet<Class<?>> advertisedProviders,
+ boolean canHaveAnyProvider,
@Nullable BaseFunction configuredTargetFunction,
Function<? super Rule, Map<String, Label>> externalBindingsFunction,
@Nullable Environment ruleDefinitionEnvironment,
@@ -1094,6 +1111,7 @@
this.validityPredicate = validityPredicate;
this.preferredDependencyPredicate = preferredDependencyPredicate;
this.advertisedProviders = advertisedProviders;
+ this.canHaveAnyProvider = canHaveAnyProvider;
this.configuredTargetFunction = configuredTargetFunction;
this.externalBindingsFunction = externalBindingsFunction;
this.ruleDefinitionEnvironment = ruleDefinitionEnvironment;
@@ -1269,6 +1287,14 @@
}
/**
+ * Returns true if this rule, when analyzed, can provide any provider. Used for "alias" rules,
+ * e.g. <code>bind()</code>.
+ */
+ public boolean canHaveAnyProvider() {
+ return canHaveAnyProvider;
+ }
+
+ /**
* For --compile_one_dependency: if multiple rules consume the specified target,
* should we choose this one over the "unpreferred" options?
*/