Delete the interface NativeAspectFactory and make native aspects extend from NativeAspectClass.
This a large refactoring of the aspects, currently we have the following:
- AspectClasses: The interface AspectClass is a implemented by either
SkylarkAspectClass or NativeAspectClass<NativeAspectFactory>.
They are wrappers for the AspectFactories and they hold the information about
the Class<> of the factory.
- AspectFactories (FooAspect.java): Represented by the interfaces
ConfiguredAspectFactory and NativeAspectFactory, also by
the interface ConfiguredNativeAspectFactory which is the union of the two
aforementioned interfaces.
All aspects implement ConfiguredNativeAspectFactory except Skylark aspects
which implement only ConfiguredAspectFactory.
After this CL the distinction between NativeAspectFactories and NativeAspectClasses
dissappear, namely aspect that extends NativeAspectClass is considered native
and if it implements ConfiguredAspectFactory it is configured.
Therefore the interfaces NativeAspectFactory and ConfiguredNativeAspectFactory
both disappear.
With this refactoring the aspectFactoryMap in the ConfiguredRuleClassProvider
changes its type from (String -> Class<? extends NativeAspectClass>)
to (String -> NativeAspectClass) which means it is now able to have an instance
of the aspect instead of its Class only.
By doing this, it is now possible to pass parameters when creating an
aspect in the ConfiguredRuleClassProvider.
--
MOS_MIGRATED_REVID=120819647
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
index 253ac66..8a518bf 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
@@ -38,6 +38,7 @@
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.AspectDefinition;
import com.google.devtools.build.lib.packages.AspectParameters;
+import com.google.devtools.build.lib.packages.NativeAspectClass;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
@@ -234,7 +235,7 @@
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
return builder
.add(attr("foo", LABEL_LIST).legacyAllowAnyFileType()
- .aspect(AspectWithEmptyLateBoundAttribute.class))
+ .aspect(ASPECT_WITH_EMPTY_LATE_BOUND_ATTRIBUTE))
.build();
}
@@ -245,7 +246,8 @@
}
}
- public static class AspectWithEmptyLateBoundAttribute implements ConfiguredNativeAspectFactory {
+ public static class AspectWithEmptyLateBoundAttribute extends NativeAspectClass
+ implements ConfiguredAspectFactory {
@Override
public AspectDefinition getDefinition(AspectParameters params) {
return new AspectDefinition.Builder("testaspect")
@@ -266,6 +268,8 @@
.build();
}
}
+ public static final AspectWithEmptyLateBoundAttribute ASPECT_WITH_EMPTY_LATE_BOUND_ATTRIBUTE =
+ new AspectWithEmptyLateBoundAttribute();
}
/**
@@ -293,8 +297,8 @@
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
return builder
- .add(attr("foo", LABEL_LIST).legacyAllowAnyFileType().aspect(
- AspectThatRegistersAction.class))
+ .add(attr("foo", LABEL_LIST).legacyAllowAnyFileType()
+ .aspect(ASPECT_THAT_REGISTERS_ACTION))
.add(attr(":action_listener", LABEL_LIST).cfg(HOST).value(ACTION_LISTENER))
.build();
}
@@ -306,7 +310,8 @@
}
}
- public static class AspectThatRegistersAction implements ConfiguredNativeAspectFactory {
+ public static class AspectThatRegistersAction extends NativeAspectClass
+ implements ConfiguredAspectFactory {
@Override
public AspectDefinition getDefinition(AspectParameters params) {
return new AspectDefinition.Builder("testaspect").build();
@@ -320,6 +325,8 @@
return new ConfiguredAspect.Builder("testaspect", ruleContext).build();
}
}
+ private static final AspectThatRegistersAction ASPECT_THAT_REGISTERS_ACTION =
+ new AspectThatRegistersAction();
}
/**