diff options
Diffstat (limited to 'src/main')
4 files changed, 105 insertions, 4 deletions
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", @@ -766,6 +768,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 = [ "rules/java/BaseJavaCompilationHelper.java", 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.<String>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<String> protoCompilerPluginOptions; + private final RpcSupport rpcSupport; protected JavaProtoAspect( JavaSemantics javaSemantics, @@ -91,13 +92,15 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe String protoRuntimeLabel, ImmutableList<String> protoSourceFileBlacklistLabels, @Nullable String jacocoLabel, - ImmutableList<String> protoCompilerPluginOptions) { + ImmutableList<String> 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<Label> jacocoAttr = attr("$jacoco_instrumentation", LABEL).cfg(HOST); if (jacocoLabel != null) { @@ -174,6 +184,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe private final RuleContext ruleContext; private final SupportData supportData; + private final RpcSupport rpcSupport; private final String protoRuntimeAttr; private final JavaSemantics javaSemantics; @@ -189,12 +200,14 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe final SupportData supportData, String protoRuntimeAttr, ImmutableList<String> protoCompilerPluginOptions, - JavaSemantics javaSemantics) { + JavaSemantics javaSemantics, + RpcSupport rpcSupport) { this.ruleContext = ruleContext; this.supportData = supportData; this.protoRuntimeAttr = protoRuntimeAttr; this.protoCompilerPluginOptions = protoCompilerPluginOptions; this.javaSemantics = javaSemantics; + this.rpcSupport = rpcSupport; dependencyCompilationArgs = JavaCompilationArgsProvider.merge( @@ -298,6 +311,8 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe .setLangParameter( ProtoCompileActionBuilder.buildProtoArg( "java_out", sourceJar.getExecPathString(), protoCompilerPluginOptions)); + rpcSupport.mutateProtoCompileAction( + ruleContext, sourceJar, actionBuilder); ruleContext.registerAction(actionBuilder.build()); } @@ -314,6 +329,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe ruleContext.getPrerequisite( protoRuntimeAttr, Mode.TARGET, JavaCompilationArgsProvider.class)) .setCompilationStrictDepsMode(StrictDepsMode.OFF); + rpcSupport.mutateJavaCompileAction(ruleContext, helper); return helper.buildCompilationArgsProvider( helper.build(javaSemantics), true /* isReportedAsStrict */); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/RpcSupport.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/RpcSupport.java new file mode 100644 index 0000000000..0840311155 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/RpcSupport.java @@ -0,0 +1,37 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.java.proto; + +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.RuleContext; +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.proto.ProtoCompileActionBuilder; + +/** + * Used by java_proto_library to support Google-specific features. + */ +public interface RpcSupport { + void mutateProtoCompileAction( + RuleContext ruleContext, Artifact sourceJar, ProtoCompileActionBuilder actionBuilder); + + void mutateJavaCompileAction(RuleContext ruleContext, JavaLibraryHelper helper); + + void mutateAspectDefinition(AspectDefinition.Builder def, AspectParameters aspectParameters); + + /** Returns false if the attributes of the rule are invalid */ + boolean checkAttributes(RuleContext ruleContext, AspectParameters aspectParameters); +} |