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/lib/rules/proto | |
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/lib/rules/proto')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java | 43 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java | 35 |
2 files changed, 47 insertions, 31 deletions
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()); } |