From 28a999cff60fa5a8c9ca045ab2b202d83a0e0583 Mon Sep 17 00:00:00 2001 From: kaipi Date: Wed, 21 Mar 2018 14:49:11 -0700 Subject: Stop objc_proto_library from returning the generated sources. PiperOrigin-RevId: 189971511 --- .../build/lib/rules/objc/ProtobufSupport.java | 80 ++++++++++++---------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java index b3c6d7e93c..3ae8e83d10 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java @@ -26,7 +26,6 @@ import com.google.common.collect.Sets; import com.google.devtools.build.lib.actions.Artifact; 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.CustomCommandLine.Builder; import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; @@ -165,13 +164,18 @@ final class ProtobufSupport { public ProtobufSupport registerGenerationActions() { int actionId = 0; + boolean isLinkingTarget = isLinkingTarget(); for (ImmutableSet inputProtos : orderedInputOutputKeySet()) { Iterable outputProtos = inputsToOutputsMap.get(inputProtos); - registerGenerationAction(outputProtos, inputProtos, getUniqueBundledProtosSuffix(actionId)); + registerGenerationAction( + outputProtos, + inputProtos, + getUniqueBundledProtosSuffix(actionId), + /* includeSources */ isLinkingTarget); actionId++; } - if (!isLinkingTarget()) { + if (!isLinkingTarget) { registerModuleMapGenerationAction(); } @@ -236,24 +240,10 @@ final class ProtobufSupport { public ProtobufSupport addFilesToBuild(NestedSetBuilder filesToBuild) { for (ImmutableSet inputProtoFiles : inputsToOutputsMap.keySet()) { ImmutableSet outputProtoFiles = inputsToOutputsMap.get(inputProtoFiles); - Iterable generatedSources = getProtoSourceFilesForCompilation(outputProtoFiles); - Iterable generatedHeaders = getGeneratedProtoOutputs(outputProtoFiles, - HEADER_SUFFIX); + Iterable generatedHeaders = + getGeneratedProtoOutputs(outputProtoFiles, HEADER_SUFFIX); - filesToBuild.addAll(generatedSources).addAll(generatedHeaders); - } - - int actionId = 0; - for (ImmutableSet inputProtos : orderedInputOutputKeySet()) { - ImmutableSet outputProtos = inputsToOutputsMap.get(inputProtos); - IntermediateArtifacts intermediateArtifacts = getUniqueIntermediateArtifacts(actionId); - - CompilationArtifacts compilationArtifacts = - getCompilationArtifacts(intermediateArtifacts, inputProtos, outputProtos); - - ObjcCommon common = getCommon(intermediateArtifacts, compilationArtifacts); - filesToBuild.addAll(common.getCompiledArchive().asSet()); - actionId++; + filesToBuild.addAll(generatedHeaders); } return this; @@ -454,14 +444,17 @@ final class ProtobufSupport { } private void registerGenerationAction( - Iterable outputProtos, Iterable inputProtos, String protoFileSuffix) { + Iterable outputProtos, + Iterable inputProtos, + String protoFileSuffix, + boolean includeSources) { Artifact protoInputsFile = getProtoInputsFile(protoFileSuffix); ruleContext.registerAction( FileWriteAction.create( ruleContext, protoInputsFile, getProtoInputsFileContents(outputProtos), false)); - ruleContext.registerAction( + SpawnAction.Builder actionBuilder = new SpawnAction.Builder() .setMnemonic("GenObjcBundledProtos") .addInput(attributes.getProtoCompiler()) @@ -470,10 +463,14 @@ final class ProtobufSupport { .addInput(protoInputsFile) .addInputs(inputProtos) .addOutputs(getGeneratedProtoOutputs(outputProtos, HEADER_SUFFIX)) - .addOutputs(getProtoSourceFilesForCompilation(outputProtos)) .setExecutable(attributes.getProtoCompiler().getExecPath()) - .addCommandLine(getGenerationCommandLine(protoInputsFile)) - .build(ruleContext)); + .addCommandLine(getGenerationCommandLine(protoInputsFile, includeSources)); + + if (includeSources) { + actionBuilder.addOutputs(getProtoSourceFilesForCompilation(outputProtos)); + } + + ruleContext.registerAction(actionBuilder.build(ruleContext)); } private Artifact getProtoInputsFile(String suffix) { @@ -490,19 +487,26 @@ final class ProtobufSupport { return Artifact.joinRootRelativePaths("\n", sorted); } - private CustomCommandLine getGenerationCommandLine(Artifact protoInputsFile) { - return new Builder() - .add("--input-file-list") - .addExecPath(protoInputsFile) - .add("--output-dir") - .addDynamicString(getWorkspaceRelativeOutputDir().getSafePathString()) - .add("--force") - .add("--proto-root-dir") - .addDynamicString(getGenfilesPathString()) - .add("--proto-root-dir") - .add(".") - .addExecPaths(VectorArg.addBefore("--config").each(portableProtoFilters)) - .build(); + private CustomCommandLine getGenerationCommandLine( + Artifact protoInputsFile, boolean includeSources) { + CustomCommandLine.Builder commandBuilder = + new CustomCommandLine.Builder() + .add("--input-file-list") + .addExecPath(protoInputsFile) + .add("--output-dir") + .addDynamicString(getWorkspaceRelativeOutputDir().getSafePathString()) + .add("--force") + .add("--proto-root-dir") + .addDynamicString(getGenfilesPathString()) + .add("--proto-root-dir") + .add(".") + .addExecPaths(VectorArg.addBefore("--config").each(portableProtoFilters)); + + if (!includeSources) { + commandBuilder.add("--headers-only"); + } + + return commandBuilder.build(); } private String getGenfilesPathString() { -- cgit v1.2.3