diff options
author | 2016-11-22 20:26:32 +0000 | |
---|---|---|
committer | 2016-11-23 08:50:59 +0000 | |
commit | c944c4d9fc5cbad830b69383a76ffff463088c7e (patch) | |
tree | f82e66e9b269272e53bd8ade0f75f3f19ec7db16 /src/main/java/com/google/devtools/build | |
parent | 0aac8f7d4f2cea1834df4aaf4cad35d3425d874b (diff) |
Alias proto_library's produce a descriptor set that contains all srcs of its dependencies.
(alias proto_library's are those with a deps attribute but no srcs attribute)
RELNOTES: Alias proto_library's produce a descriptor set that contains all srcs of its dependencies.
--
MOS_MIGRATED_REVID=139940475
Diffstat (limited to 'src/main/java/com/google/devtools/build')
5 files changed, 59 insertions, 34 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java index 536a555697..5760cbd0fc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java @@ -202,7 +202,9 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured ImmutableList.of( new ProtoCompileActionBuilder.ToolchainInvocation( "javalite", getProtoToolchainProvider(), sourceJar.getExecPathString())), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), ImmutableList.of(sourceJar), "JavaLite", true /* allowServices */); 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 c00d924648..721648f90a 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 @@ -304,7 +304,9 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe ProtoCompileActionBuilder.registerActions( ruleContext, invocations.build(), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), ImmutableList.of(sourceJar), "Java (Immutable)", rpcSupport.allowServices(ruleContext)); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java index f1cf7d3092..87a659fd87 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.rules.SkylarkRuleContext; import com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder; import com.google.devtools.build.lib.rules.proto.ProtoLangToolchainProvider; import com.google.devtools.build.lib.rules.proto.ProtoSupportDataProvider; +import com.google.devtools.build.lib.rules.proto.SupportData; import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; @@ -58,6 +59,8 @@ public class JavaProtoSkylarkCommon { ConfiguredTarget target, Artifact sourceJar, String protoToolchainAttr) { + SupportData supportData = + checkNotNull(target.getProvider(ProtoSupportDataProvider.class).getSupportData()); ProtoCompileActionBuilder.registerActions( skylarkRuleContext.getRuleContext(), ImmutableList.of( @@ -65,7 +68,9 @@ public class JavaProtoSkylarkCommon { "javalite", getProtoToolchainProvider(skylarkRuleContext, protoToolchainAttr), sourceJar.getExecPathString())), - checkNotNull(target.getProvider(ProtoSupportDataProvider.class).getSupportData()), + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), ImmutableList.of(sourceJar), "JavaLite", true /* allowServices */); diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java index 7819f13d22..6b107fe655 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java @@ -58,27 +58,36 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory { transitiveImports, !protoSources.isEmpty()); - Artifact descriptorSetOutput = - ruleContext.getGenfilesArtifact( - ruleContext.getLabel().getName() + "-descriptor-set.proto.bin"); - ProtoCompileActionBuilder.writeDescriptorSet( - ruleContext, - descriptorSetOutput.getExecPathString(), - supportData, - ImmutableList.of(descriptorSetOutput), - true /* allowServices */); + Runfiles.Builder dataRunfiles = + ProtoCommon.createDataRunfilesProvider(transitiveImports, ruleContext); - Runfiles dataRunfiles = - ProtoCommon.createDataRunfilesProvider(transitiveImports, ruleContext) - .addArtifact(descriptorSetOutput) - .build(); + RuleConfiguredTargetBuilder result = new RuleConfiguredTargetBuilder(ruleContext); - return new RuleConfiguredTargetBuilder(ruleContext) - .setFilesToBuild(NestedSetBuilder.create(STABLE_ORDER, descriptorSetOutput)) - .addProvider(RunfilesProvider.withData(Runfiles.EMPTY, dataRunfiles)) + if (checkDepsProtoSources.isEmpty()) { + result.setFilesToBuild(NestedSetBuilder.<Artifact>create(STABLE_ORDER)); + } else { + Artifact descriptorSetOutput = + ruleContext.getGenfilesArtifact( + ruleContext.getLabel().getName() + "-descriptor-set.proto.bin"); + ProtoCompileActionBuilder.writeDescriptorSet( + ruleContext, + descriptorSetOutput.getExecPathString(), + checkDepsProtoSources, + transitiveImports, + null /* protosInDirectDeps */, + ImmutableList.of(descriptorSetOutput), + true /* allowServices */); + + dataRunfiles.addArtifact(descriptorSetOutput); + + result.setFilesToBuild(NestedSetBuilder.create(STABLE_ORDER, descriptorSetOutput)); + result.addProvider(DescriptorSetProvider.create(descriptorSetOutput)); + } + + return result + .addProvider(RunfilesProvider.withData(Runfiles.EMPTY, dataRunfiles.build())) .addProvider(ProtoSourcesProvider.class, sourcesProvider) .addProvider(ProtoSupportDataProvider.class, new ProtoSupportDataProvider(supportData)) - .addProvider(DescriptorSetProvider.create(descriptorSetOutput)) .addSkylarkTransitiveInfo(ProtoSourcesProvider.SKYLARK_NAME, sourcesProvider) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java index 51d86fe7d9..233a28d1b4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java @@ -35,6 +35,7 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.analysis.actions.SpawnAction; +import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.util.LazyString; import java.util.ArrayList; @@ -345,13 +346,17 @@ public class ProtoCompileActionBuilder { public static void writeDescriptorSet( RuleContext ruleContext, final CharSequence outReplacement, - SupportData supportData, + Iterable<Artifact> protosToCompile, + NestedSet<Artifact> transitiveSources, + NestedSet<Artifact> protosInDirectDeps, Iterable<Artifact> outputs, boolean allowServices) { registerActions( ruleContext, ImmutableList.of(createDescriptorSetToolchain(outReplacement)), - supportData, + protosToCompile, + transitiveSources, + protosInDirectDeps, outputs, "Descriptor Set", allowServices); @@ -378,12 +383,13 @@ public class ProtoCompileActionBuilder { * @param outputs The artifacts that the resulting action must create. * @param flavorName e.g., "Java (Immutable)" * @param allowServices If false, the compilation will break if any .proto file has service - * definitions. */ public static void registerActions( RuleContext ruleContext, List<ToolchainInvocation> toolchainInvocations, - SupportData supportData, + Iterable<Artifact> protosToCompile, + NestedSet<Artifact> transitiveSources, + NestedSet<Artifact> protosInDirectDeps, Iterable<Artifact> outputs, String flavorName, boolean allowServices) { @@ -391,8 +397,7 @@ public class ProtoCompileActionBuilder { return; } - SpawnAction.Builder result = - new SpawnAction.Builder().addTransitiveInputs(supportData.getTransitiveImports()); + SpawnAction.Builder result = new SpawnAction.Builder().addTransitiveInputs(transitiveSources); for (ToolchainInvocation invocation : toolchainInvocations) { ProtoLangToolchainProvider toolchain = invocation.toolchain; @@ -416,7 +421,9 @@ public class ProtoCompileActionBuilder { .setCommandLine( createCommandLineFromToolchains( toolchainInvocations, - supportData, + protosToCompile, + transitiveSources, + protosInDirectDeps, allowServices, ruleContext.getFragment(ProtoConfiguration.class).protocOpts())) .setProgressMessage("Generating " + flavorName + " proto_library " + ruleContext.getLabel()) @@ -441,13 +448,15 @@ public class ProtoCompileActionBuilder { * called. As some plugins rely on output from other plugins, their order matters. * * @param toolchainInvocations See {@link #createCommandLineFromToolchains}. - * @param allowServices If false, the compilation will break if any .proto file has service - * @return a command-line to pass to proto-compiler. + * @param allowServices If false, the compilation will break if any .proto file has + * service @return a command-line to pass to proto-compiler. */ @VisibleForTesting static CustomCommandLine createCommandLineFromToolchains( List<ToolchainInvocation> toolchainInvocations, - SupportData supportData, + Iterable<Artifact> protosToCompile, + NestedSet<Artifact> transitiveSources, + NestedSet<Artifact> protosInDirectDeps, boolean allowServices, ImmutableList<String> protocOpts) { CustomCommandLine.Builder cmdLine = CustomCommandLine.builder(); @@ -487,11 +496,9 @@ public class ProtoCompileActionBuilder { cmdLine.add(protocOpts); // Add include maps - cmdLine.add( - new ProtoCommandLineArgv( - supportData.getProtosInDirectDeps(), supportData.getTransitiveImports())); + cmdLine.add(new ProtoCommandLineArgv(protosInDirectDeps, transitiveSources)); - for (Artifact src : supportData.getDirectProtoSources()) { + for (Artifact src : protosToCompile) { cmdLine.addPath(src.getRootRelativePath()); } |