aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java
diff options
context:
space:
mode:
authorGravatar Luis Fernando Pino Duque <lpino@google.com>2016-04-26 16:22:38 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-04-27 11:47:20 +0000
commite82713de767ea4f002f49ba75427698989c47edd (patch)
tree96ce693a26e062bda56e79435a655441569773fc /src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java
parent8b999982958d9b63321e6295f5a66d0d2ce7c925 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java
index c01fbda176..f89ac4bc69 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java
@@ -20,10 +20,9 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.rules.objc.J2ObjcSource.SourceType;
import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.Constants;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.ConfiguredAspect;
-import com.google.devtools.build.lib.analysis.ConfiguredNativeAspectFactory;
+import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
@@ -32,6 +31,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
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.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.AppleToolchain;
import com.google.devtools.build.lib.rules.proto.ProtoCommon;
@@ -55,12 +55,19 @@ import com.google.devtools.build.lib.vfs.PathFragment;
* by this class and provided by proto_library will be exported all the way to objc_binary for ObjC
* compilation and linking into the final application bundle.
*/
-public abstract class AbstractJ2ObjcProtoAspect implements ConfiguredNativeAspectFactory {
- public static final String NAME = "J2ObjcProtoAspect";
+public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass
+ implements ConfiguredAspectFactory {
+
private static final Iterable<Attribute> DEPENDENT_ATTRIBUTES = ImmutableList.of(
new Attribute("$protobuf_lib", Mode.TARGET),
new Attribute("deps", Mode.TARGET));
+ protected final String toolsRepository;
+
+ public AbstractJ2ObjcProtoAspect(String toolsRepository) {
+ this.toolsRepository = toolsRepository;
+ }
+
@Override
public AspectDefinition getDefinition(AspectParameters aspectParameters) {
AspectDefinition.Builder builder = new AspectDefinition.Builder("J2ObjcProtoAspect")
@@ -70,14 +77,14 @@ public abstract class AbstractJ2ObjcProtoAspect implements ConfiguredNativeAspec
J2ObjcConfiguration.class,
ObjcConfiguration.class,
ProtoConfiguration.class)
- .attributeAspect("deps", getClass())
- .attributeAspect("exports", getClass())
- .attributeAspect("runtime_deps", getClass())
+ .attributeAspect("deps", this)
+ .attributeAspect("exports", this)
+ .attributeAspect("runtime_deps", this)
.add(attr("$protobuf_lib", LABEL)
.value(Label.parseAbsoluteUnchecked("//third_party/java/j2objc:proto_runtime")))
.add(attr("$xcrunwrapper", LABEL).cfg(HOST).exec()
.value(Label.parseAbsoluteUnchecked(
- Constants.TOOLS_REPOSITORY + "//tools/objc:xcrunwrapper")))
+ toolsRepository + "//tools/objc:xcrunwrapper")))
.add(attr(":xcode_config", LABEL)
.allowedRuleClasses("xcode_config")
.checkConstraints()
@@ -97,7 +104,7 @@ public abstract class AbstractJ2ObjcProtoAspect implements ConfiguredNativeAspec
ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters)
throws InterruptedException {
if (!checkShouldCreateAspect(ruleContext)) {
- return new ConfiguredAspect.Builder(NAME, ruleContext).build();
+ return new ConfiguredAspect.Builder(getName(), ruleContext).build();
}
ProtoSourcesProvider protoSourcesProvider = base.getProvider(ProtoSourcesProvider.class);
@@ -154,7 +161,7 @@ public abstract class AbstractJ2ObjcProtoAspect implements ConfiguredNativeAspec
NestedSet<Artifact> j2ObjcTransitiveClassMappingFiles = j2ObjcTransitiveClassMappingFiles(
ruleContext, classMappingFiles);
- return new ConfiguredAspect.Builder(NAME, ruleContext)
+ return new ConfiguredAspect.Builder(getName(), ruleContext)
.addProvider(
J2ObjcMappingFileProvider.class,
new J2ObjcMappingFileProvider(