diff options
author | Carmi Grushko <carmi@google.com> | 2016-07-29 22:05:02 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2016-08-01 08:07:49 +0000 |
commit | daad7e74d3f428f440172453632b3cb56649f7fb (patch) | |
tree | 3628537674bdccd812dcc0e533c79e6157e36263 /src/main/java/com/google/devtools/build/lib/rules | |
parent | ad77f9722e5adb5c997859ea4a0f0f66e7f583bb (diff) |
--
MOS_MIGRATED_REVID=128851189
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java | 22 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/proto/RpcSupport.java | 37 |
2 files changed, 56 insertions, 3 deletions
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); +} |