aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-03-21 20:23:49 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-03-22 08:09:17 +0000
commitccdbce6585e86aecb5887bb6be17406a0ae61acc (patch)
treef92b48cb787fb713b8a59a4fb6d63a6812eee1fd /src/main/java/com/google/devtools/build/lib/rules
parent1fec40d89c3a3af2ce602d734f19700a4a6121e3 (diff)
Filter Well Known Type protos from being generated by the objc_proto_library rule, as these protos have already been generated and linked in the released static library.
-- MOS_MIGRATED_REVID=117747156
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ProtoSupport.java22
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