diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java | 33 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java | 51 |
2 files changed, 30 insertions, 54 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 3289a34b0c..0c80f2779a 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 @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTran import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredAspect; @@ -35,9 +36,12 @@ 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.objc.J2ObjcSource.SourceType; import com.google.devtools.build.lib.rules.proto.ProtoCommon; +import com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder; import com.google.devtools.build.lib.rules.proto.ProtoConfiguration; import com.google.devtools.build.lib.rules.proto.ProtoSourceFileBlacklist; import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider; +import com.google.devtools.build.lib.rules.proto.ProtoSupportDataProvider; +import com.google.devtools.build.lib.rules.proto.SupportData; import com.google.devtools.build.lib.vfs.PathFragment; /** @@ -113,6 +117,8 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass protected abstract boolean checkShouldCreateAspect(RuleContext ruleContext); + protected abstract boolean allowServices(RuleContext ruleContext); + @Override public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) @@ -123,7 +129,6 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass ProtoSourcesProvider protoSourcesProvider = base.getProvider(ProtoSourcesProvider.class); ImmutableList<Artifact> protoSources = protoSourcesProvider.getDirectProtoSources(); - NestedSet<Artifact> transitiveImports = protoSourcesProvider.getTransitiveImports(); // Avoid pulling in any generated files from blacklisted protos. ProtoSourceFileBlacklist protoBlacklist = @@ -156,8 +161,7 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass headerMappingFiles = headerMappingFiles(ruleContext, filteredProtoSources); classMappingFiles = classMappingFiles(ruleContext, filteredProtoSources); - createActions(base, ruleContext, filteredProtoSources, transitiveImports, - headerMappingFiles, classMappingFiles, j2ObjcSource); + createActions(base, ruleContext, headerMappingFiles, classMappingFiles, j2ObjcSource); common = J2ObjcAspect.common( ruleContext, j2ObjcSource.getObjcSrcs(), @@ -194,10 +198,27 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass .build(); } - protected abstract void createActions(ConfiguredTarget base, RuleContext ruleContext, - Iterable<Artifact> protoSources, NestedSet<Artifact> transitiveProtoSources, + private void createActions(ConfiguredTarget base, RuleContext ruleContext, Iterable<Artifact> headerMappingFiles, Iterable<Artifact> classMappingFiles, - J2ObjcSource j2ObjcSource); + J2ObjcSource j2ObjcSource) { + SupportData supportData = base.getProvider(ProtoSupportDataProvider.class).getSupportData(); + ImmutableList<Artifact> outputs = ImmutableList.<Artifact>builder() + .addAll(j2ObjcSource.getObjcSrcs()) + .addAll(j2ObjcSource.getObjcHdrs()) + .addAll(headerMappingFiles) + .addAll(classMappingFiles) + .build(); + String langPluginParameter = String.format( + "%s:%s", + Joiner.on(',').join(J2OBJC_PLUGIN_PARAMS), + ruleContext.getConfiguration().getGenfilesFragment().getPathString()); + ProtoCompileActionBuilder actionBuilder = + new ProtoCompileActionBuilder(ruleContext, supportData, "J2ObjC", "j2objc", outputs) + .setLangPluginName("$j2objc_plugin") + .setLangPluginParameter(langPluginParameter) + .allowServices(allowServices(ruleContext)); + ruleContext.registerAction(actionBuilder.build()); + } private J2ObjcSource j2ObjcSource(RuleContext ruleContext, ImmutableList<Artifact> protoSources) { PathFragment objcFileRootExecPath = ruleContext.getConfiguration() diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java index b7c028fa12..13d8761df8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java @@ -18,13 +18,8 @@ import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTran import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; -import com.google.common.base.Joiner; -import com.google.devtools.build.lib.actions.Artifact; -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; import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.packages.AspectDefinition; /** @@ -41,14 +36,7 @@ public class BazelJ2ObjcProtoAspect extends AbstractJ2ObjcProtoAspect { @Override protected AspectDefinition.Builder addAdditionalAttributes(AspectDefinition.Builder builder) { - return builder - .add(attr("$protoc", LABEL) - .cfg(HOST) - .exec() - .singleArtifact() - .value(Label.parseAbsoluteUnchecked( - toolsRepository + "//tools/objc:standalone_protoc"))) - .add(attr("$j2objc_plugin", LABEL) + return builder.add(attr("$j2objc_plugin", LABEL) .cfg(HOST) .exec() .value(Label.parseAbsoluteUnchecked( @@ -61,40 +49,7 @@ public class BazelJ2ObjcProtoAspect extends AbstractJ2ObjcProtoAspect { } @Override - protected void createActions( - ConfiguredTarget base, - RuleContext ruleContext, - Iterable<Artifact> protoSources, - NestedSet<Artifact> transitiveProtoSources, - Iterable<Artifact> headerMappingFiles, - Iterable<Artifact> classMappingFiles, - J2ObjcSource j2ObjcSource) { - String genDir = ruleContext.getConfiguration().getGenfilesDirectory( - ruleContext.getRule().getRepository()).getExecPathString(); - Artifact compiler = ruleContext.getPrerequisiteArtifact("$protoc", Mode.HOST); - Artifact j2objcPlugin = ruleContext.getPrerequisiteArtifact("$j2objc_plugin", Mode.HOST); - - String langPluginParameter = Joiner.on(',').join(J2OBJC_PLUGIN_PARAMS) + ":" + genDir; - String command = String.format( - "%s --plugin=protoc-gen-j2objc=%s --j2objc_out=%s --proto_path=%s --proto_path=. " - + "--absolute_paths %s", - compiler.getExecPathString(), - j2objcPlugin.getExecPathString(), - langPluginParameter, - genDir, - Joiner.on(" ").join(Artifact.toExecPaths(protoSources))); - - ruleContext.registerAction( - ObjcRuleClasses.spawnBashOnDarwinActionBuilder(command) - .setMnemonic("GeneratingJ2ObjcProtos") - .addInput(compiler) - .addInput(j2objcPlugin) - .addInputs(protoSources) - .addTransitiveInputs(transitiveProtoSources) - .addOutputs(j2ObjcSource.getObjcSrcs()) - .addOutputs(j2ObjcSource.getObjcHdrs()) - .addOutputs(headerMappingFiles) - .addOutputs(classMappingFiles) - .build(ruleContext)); + protected boolean allowServices(RuleContext ruleContext) { + return true; } } |