Implement propagation along dependencies for Skylark aspects.
--
MOS_MIGRATED_REVID=106694515
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
index a9c75d7..7c5fa83 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
@@ -22,6 +22,7 @@
import com.google.common.collect.Multimap;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.NativeAspectClass.NativeAspectFactory;
import com.google.devtools.build.lib.util.BinaryPredicate;
import java.util.LinkedHashMap;
@@ -145,14 +146,13 @@
LinkedHashMultimap<Attribute, Label> result = LinkedHashMultimap.create();
for (AspectClass candidateClass : attribute.getAspects()) {
- AspectFactory<?, ?, ?> candidate = AspectFactory.Util.create(candidateClass);
// Check if target satisfies condition for this aspect (has to provide all required
// TransitiveInfoProviders)
if (!advertisedProviders.containsAll(
- candidate.getDefinition().getRequiredProviderNames())) {
+ candidateClass.getDefinition().getRequiredProviderNames())) {
continue;
}
- addAllAttributesOfAspect((Rule) from, result, candidate.getDefinition(), Rule.ALL_DEPS);
+ addAllAttributesOfAspect((Rule) from, result, candidateClass.getDefinition(), Rule.ALL_DEPS);
}
return ImmutableMultimap.copyOf(result);
}
@@ -214,21 +214,38 @@
* by direct dependencies through attribute {@code attribute} on the target associated with this
* aspect.
*
- * <p>Note that {@code AspectFactory} instances are expected in the second argument, but we
- * cannot reference that interface here.
+ * <p>Note that {@code ConfiguredAspectFactory} instances are expected in the second argument,
+ * but we cannot reference that interface here.
*/
@SafeVarargs
public final Builder attributeAspect(
- String attribute, Class<? extends AspectFactory<?, ?, ?>>... aspectFactories) {
+ String attribute, Class<? extends NativeAspectFactory>... aspectFactories) {
Preconditions.checkNotNull(attribute);
- for (Class<? extends AspectFactory<?, ?, ?>> aspectFactory : aspectFactories) {
- this.attributeAspects.put(
- attribute, new NativeAspectClass(Preconditions.checkNotNull(aspectFactory)));
+ for (Class<? extends NativeAspectFactory> aspectFactory : aspectFactories) {
+ this
+ .attributeAspect(
+ attribute, new NativeAspectClass<>(Preconditions.checkNotNull(aspectFactory)));
}
return this;
}
/**
+ * Declares that this aspect depends on the given {@link AspectClass} provided
+ * by direct dependencies through attribute {@code attribute} on the target associated with this
+ * aspect.
+ *
+ * <p>Note that {@code ConfiguredAspectFactory} instances are expected in the second argument,
+ * but we cannot reference that interface here.
+ */
+ public final Builder attributeAspect(String attribute, AspectClass aspectClass) {
+ Preconditions.checkNotNull(attribute);
+
+ this.attributeAspects.put(attribute, Preconditions.checkNotNull(aspectClass));
+
+ return this;
+ }
+
+ /**
* Adds an attribute to the aspect.
*
* <p>Since aspects do not appear in BUILD files, the attribute must be either implicit