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 --- .../lib/rules/proto/ProtoCompileActionBuilder.java | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java index da43b6a2a4..9f2217cd62 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java @@ -351,8 +351,10 @@ public class ProtoCompileActionBuilder { protosToCompile, transitiveSources, protosInDirectDeps, + /* protosInExports= */ null, protoSourceRoots, directProtoSourceRoots, + /* exportedProtoSourceRoots= */ null, ruleContext.getLabel(), ImmutableList.of(output), "Descriptor Set", @@ -381,6 +383,34 @@ public class ProtoCompileActionBuilder { outReplacement); } + public static void registerActions( + RuleContext ruleContext, + List toolchainInvocations, + Iterable protosToCompile, + NestedSet transitiveSources, + NestedSet protosInDirectDeps, + NestedSet protoSourceRoots, + NestedSet directProtoSourceRoots, + Label ruleLabel, + Iterable outputs, + String flavorName, + boolean allowServices) { + registerActions( + ruleContext, + toolchainInvocations, + protosToCompile, + transitiveSources, + protosInDirectDeps, + protoSourceRoots, + directProtoSourceRoots, + ruleLabel, + outputs, + flavorName, + allowServices, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); + } + /** * Registers actions to generate code from .proto files. * @@ -404,7 +434,9 @@ public class ProtoCompileActionBuilder { Label ruleLabel, Iterable outputs, String flavorName, - boolean allowServices) { + boolean allowServices, + NestedSet protosInExports, + NestedSet exportedProtoSourceRoots) { SpawnAction.Builder actions = createActions( ruleContext, @@ -412,8 +444,10 @@ public class ProtoCompileActionBuilder { protosToCompile, transitiveSources, protosInDirectDeps, + protosInExports, protoSourceRoots, directProtoSourceRoots, + exportedProtoSourceRoots, ruleLabel, outputs, flavorName, @@ -430,8 +464,10 @@ public class ProtoCompileActionBuilder { Iterable protosToCompile, NestedSet transitiveSources, @Nullable NestedSet protosInDirectDeps, + @Nullable NestedSet protosInExports, NestedSet protoSourceRoots, NestedSet directProtoSourceRoots, + @Nullable NestedSet exportedProtoSourceRoots, Label ruleLabel, Iterable outputs, String flavorName, @@ -468,7 +504,9 @@ public class ProtoCompileActionBuilder { transitiveSources, protoSourceRoots, directProtoSourceRoots, + exportedProtoSourceRoots, areDepsStrict(ruleContext) ? protosInDirectDeps : null, + arePublicImportsStrict(ruleContext) ? protosInExports : null, ruleLabel, allowServices, ruleContext.getFragment(ProtoConfiguration.class).protocOpts()), @@ -479,6 +517,10 @@ public class ProtoCompileActionBuilder { return result; } + public static boolean arePublicImportsStrict(RuleContext ruleContext) { + return ruleContext.getFragment(ProtoConfiguration.class).strictPublicImports(); + } + /** * Constructs command-line arguments to execute proto-compiler. * @@ -506,7 +548,9 @@ public class ProtoCompileActionBuilder { NestedSet transitiveSources, NestedSet transitiveProtoPathFlags, NestedSet directProtoSourceRoots, + NestedSet exportedProtoSourceRoots, @Nullable NestedSet protosInDirectDeps, + @Nullable NestedSet protosInExports, Label ruleLabel, boolean allowServices, ImmutableList protocOpts) { @@ -554,6 +598,19 @@ public class ProtoCompileActionBuilder { cmdLine.addFormatted(STRICT_DEPS_FLAG_TEMPLATE, ruleLabel); } + if (protosInExports != null) { + if (protosInExports.isEmpty()) { + // This line is necessary to trigger the check. + cmdLine.add("--allowed_public_imports="); + } else { + cmdLine.addAll( + "--allowed_public_imports", + VectorArg.join(":") + .each(protosInExports) + .mapped(new ExpandToPathFn(exportedProtoSourceRoots))); + } + } + for (Artifact src : protosToCompile) { cmdLine.addPath(src.getExecPath()); } -- cgit v1.2.3