diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java | 12 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ProtoSupport.java | 22 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java index cf2bbcd00c..2e6f741b7f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java @@ -46,6 +46,7 @@ public class ObjcProtoLibraryRule implements RuleDefinition { static final String PROTO_COMPILER_ATTR = "$googlemac_proto_compiler"; static final String PROTO_COMPILER_SUPPORT_ATTR = "$googlemac_proto_compiler_support"; static final String PROTO_LIB_ATTR = "$lib_protobuf"; + static final String PROTOBUF_WELL_KNOWN_TYPES = "$protobuf_well_known_types"; static final String XCODE_GEN_ATTR = "$xcodegen"; @Override @@ -131,6 +132,17 @@ public class ObjcProtoLibraryRule implements RuleDefinition { } })) .add( + // The well known type proto label should resolve to the shared location of proto + // dependencies of targets in the workspace. Unless all dependencies refer to the same + // label for these proto dependencies, an artifact comparison between them is not + // possible. Ultimately, we will need to resolve this cross-repository dependency, but, + // for now, these well-known protos do not exist in a common repository, and must thus + // be present in the root workspace. + attr(PROTOBUF_WELL_KNOWN_TYPES, LABEL) + .cfg(HOST) + .exec() + .value(env.getLabel("//tools/objc:protobuf_well_known_types"))) + .add( attr(XCODE_GEN_ATTR, LABEL) .cfg(HOST) .exec() diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoSupport.java index 6d0a6a3fec..008cae937b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoSupport.java @@ -20,6 +20,7 @@ import static com.google.common.base.CaseFormat.UPPER_CAMEL; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Optional; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -262,7 +263,7 @@ final class ProtoSupport { } private String getProtoInputListFileContents() { - return Artifact.joinExecPaths("\n", attributes.getProtoFiles()); + return Artifact.joinExecPaths("\n", getFilteredProtos()); } private NestedSet<Artifact> getGenerateActionInputs() { @@ -351,7 +352,7 @@ final class ProtoSupport { private ImmutableList<Artifact> generatedOutputArtifacts(FileType newFileType) { ImmutableList.Builder<Artifact> builder = new ImmutableList.Builder<>(); - for (Artifact protoFile : attributes.getProtoFiles()) { + for (Artifact protoFile : getFilteredProtos()) { String generatedOutputName; if (attributes.outputsCpp()) { generatedOutputName = protoFile.getFilename(); @@ -378,6 +379,14 @@ final class ProtoSupport { return builder.build(); } + private Iterable<Artifact> getFilteredProtos() { + // Filter the well known types from being sent to be generated, as these protos have already + // been generated and linked in libprotobuf.a. + return Iterables.filter( + attributes.getProtoFiles(), + Predicates.not(Predicates.in(attributes.getWellKnownTypeProtos()))); + } + /** * Common rule attributes used by an Objective C proto library. */ @@ -432,6 +441,15 @@ final class ProtoSupport { } /** + * Returns the list of well known type protos. + */ + ImmutableList<Artifact> getWellKnownTypeProtos() { + return ruleContext + .getPrerequisiteArtifacts(ObjcProtoLibraryRule.PROTOBUF_WELL_KNOWN_TYPES, Mode.HOST) + .list(); + } + + /** * Returns the options file, or null if it was not specified. */ @Nullable |