diff options
author | 2016-08-11 16:52:57 +0000 | |
---|---|---|
committer | 2016-08-12 08:51:39 +0000 | |
commit | 2ce071cef975ad504808e199333155b16e987d66 (patch) | |
tree | 6c74da6d7627d0c51cd6a2e3066a5c0ac9c859cb /src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java | |
parent | c0af31d3a8039f659b86af3d2ca69a3a0ed603b8 (diff) |
Adds propagation of protobuf's headers and search paths through ObjcProtoProvider and ObjcProtoAspect.
--
MOS_MIGRATED_REVID=129997369
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java index 6692988a82..f11f8ff904 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoProvider.java @@ -19,21 +19,41 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; +import com.google.devtools.build.lib.vfs.PathFragment; /** * A provider that provides all protos and portable proto filters information in the transitive * closure of its dependencies that are needed for generating and compiling only one version of * proto files. + * + * <p>This provider also propagates the headers and search path for the protobuf runtime library. + * This solves the issue that the proto bundling behavior (gather all the protos in the top target + * and generate, compile and link only one version in the final binary) needs this data at the + * linking target but the dependency on the runtime library is defined on the objc_proto_library. + * + * <p>Ideally we should make objc_binary (and other linking targets such as ios_extension_binary) + * depend on the runtime library's ObjcProvider. Unfortunately this runs into a bug where Xcode + * project generation cannot handle the dependency if it points to a label in an external workspace + * (such as {@code @bazel_tools}). To avoid breaking Xcode project generation for all binary targets + * all the time (whether protos are used or not), the dependency is specified on objc_proto_library + * instead. */ public class ObjcProtoProvider implements TransitiveInfoProvider { private final NestedSet<Artifact> protoSources; + private final NestedSet<Artifact> protobufHeaders; + private final NestedSet<PathFragment> protobufHeaderSearchPaths; private final NestedSet<Artifact> portableProtoFilters; private ObjcProtoProvider( - NestedSet<Artifact> protoSources, NestedSet<Artifact> portableProtoFilters) { + NestedSet<Artifact> protoSources, + NestedSet<Artifact> portableProtoFilters, + NestedSet<Artifact> protobufHeaders, + NestedSet<PathFragment> protobufHeaderSearchPaths) { this.protoSources = Preconditions.checkNotNull(protoSources); this.portableProtoFilters = Preconditions.checkNotNull(portableProtoFilters); + this.protobufHeaders = Preconditions.checkNotNull(protobufHeaders); + this.protobufHeaderSearchPaths = Preconditions.checkNotNull(protobufHeaderSearchPaths); } /** @@ -43,6 +63,16 @@ public class ObjcProtoProvider implements TransitiveInfoProvider { return protoSources; } + /** Returns the header artifacts provided by the Protobuf library. */ + public NestedSet<Artifact> getProtobufHeaders() { + return protobufHeaders; + } + + /** Returns the header search paths provided by the Protobuf library. */ + public NestedSet<PathFragment> getProtobufHeaderSearchPaths() { + return protobufHeaderSearchPaths; + } + /** * Returns the set of all the associated filters to the collected protos. */ @@ -56,7 +86,10 @@ public class ObjcProtoProvider implements TransitiveInfoProvider { */ public static final class Builder { private final NestedSetBuilder<Artifact> protoSources = NestedSetBuilder.naiveLinkOrder(); - private final NestedSetBuilder<Artifact> portableProtoFilters = NestedSetBuilder.linkOrder(); + private final NestedSetBuilder<Artifact> portableProtoFilters = NestedSetBuilder.stableOrder(); + private final NestedSetBuilder<Artifact> protobufHeaders = NestedSetBuilder.stableOrder(); + private final NestedSetBuilder<PathFragment> protobufHeaderSearchPaths = + NestedSetBuilder.linkOrder(); /** * Adds all the protos to the set of dependencies. @@ -66,6 +99,18 @@ public class ObjcProtoProvider implements TransitiveInfoProvider { return this; } + /** Adds the header artifacts provided by the Protobuf library. */ + public Builder addProtobufHeaders(NestedSet<Artifact> protobufHeaders) { + this.protobufHeaders.addTransitive(protobufHeaders); + return this; + } + + /** Adds the header search paths provided by the Protobuf library. */ + public Builder addProtobufHeaderSearchPaths(NestedSet<PathFragment> protobufHeaderSearchPaths) { + this.protobufHeaderSearchPaths.addTransitive(protobufHeaderSearchPaths); + return this; + } + /** * Adds all the proto filters to the set of dependencies. */ @@ -82,6 +127,8 @@ public class ObjcProtoProvider implements TransitiveInfoProvider { for (ObjcProtoProvider provider : providers) { this.protoSources.addTransitive(provider.getProtoSources()); this.portableProtoFilters.addTransitive(provider.getPortableProtoFilters()); + this.protobufHeaders.addTransitive(provider.getProtobufHeaders()); + this.protobufHeaderSearchPaths.addTransitive(provider.getProtobufHeaderSearchPaths()); } return this; } @@ -94,7 +141,11 @@ public class ObjcProtoProvider implements TransitiveInfoProvider { } public ObjcProtoProvider build() { - return new ObjcProtoProvider(protoSources.build(), portableProtoFilters.build()); + return new ObjcProtoProvider( + protoSources.build(), + portableProtoFilters.build(), + protobufHeaders.build(), + protobufHeaderSearchPaths.build()); } } } |