From e5719662a91a7eb310eb0ea528992c49090784c9 Mon Sep 17 00:00:00 2001 From: twerth Date: Tue, 14 Aug 2018 00:00:02 -0700 Subject: Add exports attribute to proto_library. Note that it is currently only used by the java_proto_library family of rules (if enabled per flag). RELNOTES: None PiperOrigin-RevId: 208601730 --- .../build/lib/rules/proto/ProtoCommon.java | 43 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java index f3cc3d6751..cb9dbb6818 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java @@ -140,19 +140,19 @@ public class ProtoCommon { /** * Returns a set of the {@code proto_source_root} collected from the current library and the - * direct dependencies. + * specified attribute. * *

Assumes {@code currentProtoSourceRoot} is the same as the package name. */ - public static NestedSet getProtoSourceRootsOfDirectDependencies( - RuleContext ruleContext, String currentProtoSourceRoot) { + private static NestedSet getProtoSourceRootsOfAttribute( + RuleContext ruleContext, String currentProtoSourceRoot, String attributeName) { NestedSetBuilder protoSourceRoots = NestedSetBuilder.stableOrder(); if (currentProtoSourceRoot != null && !currentProtoSourceRoot.isEmpty()) { protoSourceRoots.add(currentProtoSourceRoot); } for (ProtoSourcesProvider provider : - ruleContext.getPrerequisites("deps", Mode.TARGET, ProtoSourcesProvider.class)) { + ruleContext.getPrerequisites(attributeName, Mode.TARGET, ProtoSourcesProvider.class)) { String protoSourceRoot = provider.getProtoSourceRoot(); if (protoSourceRoot != null && !protoSourceRoot.isEmpty()) { protoSourceRoots.add(provider.getProtoSourceRoot()); @@ -162,6 +162,28 @@ public class ProtoCommon { return protoSourceRoots.build(); } + /** + * Returns a set of the {@code proto_source_root} collected from the current library and the + * direct dependencies. + * + *

Assumes {@code currentProtoSourceRoot} is the same as the package name. + */ + public static NestedSet getProtoSourceRootsOfDirectDependencies( + RuleContext ruleContext, String currentProtoSourceRoot) { + return getProtoSourceRootsOfAttribute(ruleContext, currentProtoSourceRoot, "deps"); + } + + /** + * Returns a set of the {@code proto_source_root} collected from the current library and the + * exported dependencies. + * + *

Assumes {@code currentProtoSourceRoot} is the same as the package name. + */ + public static NestedSet getProtoSourceRootsOfExportedDependencies( + RuleContext ruleContext, String currentProtoSourceRoot) { + return getProtoSourceRootsOfAttribute(ruleContext, currentProtoSourceRoot, "exports"); + } + private static void checkProtoSourceRootIsTheSameAsPackage( String protoSourceRoot, RuleContext ruleContext) { if (!ruleContext.getLabel().getPackageName().equals(protoSourceRoot)) { @@ -271,6 +293,19 @@ public class ProtoCommon { return result.build(); } + /** + * Returns the .proto files that are the direct srcs of the exported dependencies of this rule. + */ + @Nullable + public static NestedSet computeProtosInExportedDeps(RuleContext ruleContext) { + NestedSetBuilder result = NestedSetBuilder.stableOrder(); + for (ProtoSupportDataProvider provider : + ruleContext.getPrerequisites("exports", TARGET, ProtoSupportDataProvider.class)) { + result.addTransitive(provider.getSupportData().getProtosInDirectDeps()); + } + return result.build(); + } + /** * Decides whether this proto_library should check for strict proto deps. * -- cgit v1.2.3