From daad7e74d3f428f440172453632b3cb56649f7fb Mon Sep 17 00:00:00 2001 From: Carmi Grushko Date: Fri, 29 Jul 2016 22:05:02 +0000 Subject: -- MOS_MIGRATED_REVID=128851189 --- src/main/java/com/google/devtools/build/lib/BUILD | 14 ++++++++ .../rules/java/proto/BazelJavaProtoAspect.java | 36 ++++++++++++++++++++- .../lib/rules/java/proto/JavaProtoAspect.java | 22 +++++++++++-- .../build/lib/rules/java/proto/RpcSupport.java | 37 ++++++++++++++++++++++ 4 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/java/proto/RpcSupport.java (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 5354a34a28..7178895243 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -523,6 +523,7 @@ java_library( ], ), deps = [ + ":RpcSupport", ":android-rules", ":bazel", ":bazel-repository", @@ -742,6 +743,7 @@ java_library( "rules/java/proto/StrictDepsUtils.java", ], deps = [ + ":RpcSupport", ":build-base", ":collect", ":concurrent", @@ -765,6 +767,18 @@ java_library( ], ) +java_library( + name = "RpcSupport", + srcs = ["rules/java/proto/RpcSupport.java"], + deps = [ + ":build-base", + ":java-compilation", + ":packages-internal", + ":proto-rules", + "//src/main/java/com/google/devtools/build/lib/actions", + ], +) + java_library( name = "java-compilation", srcs = [ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java index e18b810673..3392ce1823 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java @@ -15,8 +15,15 @@ package com.google.devtools.build.lib.bazel.rules.java.proto; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; +import com.google.devtools.build.lib.packages.AspectDefinition; +import com.google.devtools.build.lib.packages.AspectParameters; +import com.google.devtools.build.lib.rules.java.JavaLibraryHelper; import com.google.devtools.build.lib.rules.java.proto.JavaProtoAspect; +import com.google.devtools.build.lib.rules.java.proto.RpcSupport; +import com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder; /** An Aspect which BazelJavaProtoLibrary injects to build Java SPEED protos. */ public class BazelJavaProtoAspect extends JavaProtoAspect { @@ -31,6 +38,33 @@ public class BazelJavaProtoAspect extends JavaProtoAspect { SPEED_PROTO_RUNTIME_LABEL, ImmutableList.of(), null, /* jacocoAttr */ - ImmutableList.of("shared", "immutable")); + ImmutableList.of("shared", "immutable"), + new NoopRpcSupport()); + } + + private static class NoopRpcSupport + implements RpcSupport { + @Override + public void mutateProtoCompileAction( + RuleContext ruleContext, Artifact sourceJar, ProtoCompileActionBuilder actionBuilder) { + // Intentionally left empty. + } + + @Override + public void mutateJavaCompileAction(RuleContext ruleContext, JavaLibraryHelper helper) { + // Intentionally left empty. + } + + @Override + public void mutateAspectDefinition( + AspectDefinition.Builder def, AspectParameters aspectParameters) { + // Intentionally left empty. + } + + @Override + public boolean checkAttributes(RuleContext ruleContext, AspectParameters aspectParameters) { + // Intentionally left empty. + return true; + } } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java index 54ccb03f19..6d683f7794 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java @@ -84,6 +84,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe @Nullable private final String jacocoLabel; private final ImmutableList protoCompilerPluginOptions; + private final RpcSupport rpcSupport; protected JavaProtoAspect( JavaSemantics javaSemantics, @@ -91,13 +92,15 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe String protoRuntimeLabel, ImmutableList protoSourceFileBlacklistLabels, @Nullable String jacocoLabel, - ImmutableList protoCompilerPluginOptions) { + ImmutableList protoCompilerPluginOptions, + RpcSupport rpcSupport) { this.javaSemantics = javaSemantics; this.protoRuntimeAttr = protoRuntimeAttr; this.protoRuntimeLabel = protoRuntimeLabel; this.protoSourceFileBlacklistLabels = protoSourceFileBlacklistLabels; this.jacocoLabel = jacocoLabel; this.protoCompilerPluginOptions = protoCompilerPluginOptions; + this.rpcSupport = rpcSupport; } @Override @@ -107,6 +110,10 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe ConfiguredAspect.Builder aspect = new ConfiguredAspect.Builder(getClass().getSimpleName(), ruleContext); + if (!rpcSupport.checkAttributes(ruleContext, parameters)) { + return aspect.build(); + } + // Get SupportData, which is provided by the proto_library rule we attach to. SupportData supportData = checkNotNull(base.getProvider(ProtoSupportDataProvider.class)).getSupportData(); @@ -117,7 +124,8 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe supportData, protoRuntimeAttr, protoCompilerPluginOptions, - javaSemantics) + javaSemantics, + rpcSupport) .createProviders()); return aspect.build(); @@ -145,6 +153,8 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe .allowedRuleClasses("java_toolchain") .value(JavaSemantics.JAVA_TOOLCHAIN)); + rpcSupport.mutateAspectDefinition(result, aspectParameters); + Attribute.Builder