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/java/JavaConfiguration.java | 8 + .../devtools/build/lib/rules/java/JavaOptions.java | 10 ++ .../lib/rules/java/proto/JavaLiteProtoAspect.java | 32 +++- .../lib/rules/java/proto/JavaProtoAspect.java | 35 +++- .../build/lib/rules/proto/BazelProtoLibrary.java | 4 +- .../build/lib/rules/proto/ProtoCommon.java | 43 ++++- .../lib/rules/proto/ProtoCompileActionBuilder.java | 59 ++++++- .../build/lib/rules/proto/ProtoConfiguration.java | 15 ++ .../build/lib/rules/proto/SupportData.java | 18 ++- .../rules/proto/ProtoCompileActionBuilderTest.java | 178 ++++++++++++--------- 10 files changed, 314 insertions(+), 88 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java index 6bc1ed10d7..97cb73987f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java @@ -154,6 +154,7 @@ public final class JavaConfiguration extends Fragment implements JavaConfigurati private final boolean generateJavaDeps; private final boolean strictDepsJavaProtos; private final boolean protoGeneratedStrictDeps; + private final boolean isJavaProtoExportsEnabled; private final OneVersionEnforcementLevel enforceOneVersion; private final boolean enforceOneVersionOnJavaTests; private final ImportDepsCheckingLevel importDepsCheckingLevel; @@ -204,6 +205,7 @@ public final class JavaConfiguration extends Fragment implements JavaConfigurati this.useLegacyBazelJavaTest = javaOptions.legacyBazelJavaTest; this.strictDepsJavaProtos = javaOptions.strictDepsJavaProtos; this.protoGeneratedStrictDeps = javaOptions.protoGeneratedStrictDeps; + this.isJavaProtoExportsEnabled = javaOptions.isJavaProtoExportsEnabled; this.enforceOneVersion = javaOptions.enforceOneVersion; this.enforceOneVersionOnJavaTests = javaOptions.enforceOneVersionOnJavaTests; this.importDepsCheckingLevel = javaOptions.importDepsCheckingLevel; @@ -246,6 +248,7 @@ public final class JavaConfiguration extends Fragment implements JavaConfigurati boolean generateJavaDeps, boolean strictDepsJavaProtos, boolean protoGeneratedStrictDeps, + boolean isJavaProtoExportsEnabled, OneVersionEnforcementLevel enforceOneVersion, boolean enforceOneVersionOnJavaTests, ImportDepsCheckingLevel importDepsCheckingLevel, @@ -276,6 +279,7 @@ public final class JavaConfiguration extends Fragment implements JavaConfigurati this.generateJavaDeps = generateJavaDeps; this.strictDepsJavaProtos = strictDepsJavaProtos; this.protoGeneratedStrictDeps = protoGeneratedStrictDeps; + this.isJavaProtoExportsEnabled = isJavaProtoExportsEnabled; this.enforceOneVersion = enforceOneVersion; this.enforceOneVersionOnJavaTests = enforceOneVersionOnJavaTests; this.importDepsCheckingLevel = importDepsCheckingLevel; @@ -512,6 +516,10 @@ public final class JavaConfiguration extends Fragment implements JavaConfigurati return protoGeneratedStrictDeps; } + public boolean isJavaProtoExportsEnabled() { + return isJavaProtoExportsEnabled; + } + public boolean jplPropagateCcLinkParamsStore() { return jplPropagateCcLinkParamsStore; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java index 5bb7e08106..2b9cbecf05 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java @@ -466,6 +466,16 @@ public class JavaOptions extends FragmentOptions { help = "Enables strict deps mode for the java compilation of proto generated Java code.") public boolean protoGeneratedStrictDeps; + @Option( + name = "experimental_enable_java_proto_exports", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS, OptionEffectTag.EAGERNESS_TO_EXIT}, + help = + "Enables exports forwarding for proto_library targets depended on by " + + "java_proto_library targets.") + public boolean isJavaProtoExportsEnabled; + @Option( name = "experimental_java_header_compilation_disable_javac_fallback", defaultValue = "false", diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java index 09cf02d0d1..a2649622d5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java @@ -113,6 +113,7 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured AspectDefinition.Builder result = new AspectDefinition.Builder(this) .propagateAlongAttribute("deps") + .propagateAlongAttribute("exports") .requiresConfigurationFragments(JavaConfiguration.class, ProtoConfiguration.class) .requireProviders(ProtoSourcesProvider.class) .advertiseProvider(JavaProtoLibraryAspectProvider.class) @@ -154,9 +155,14 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured */ private final JavaCompilationArgsProvider dependencyCompilationArgs; + // Compilation-args from all exports, merged together. + private final JavaCompilationArgsProvider exportsCompilationArgs; + private final JavaProtoAspectCommon aspectCommon; private final Iterable javaProtoLibraryAspectProviders; + private final boolean isJavaProtoExportsEnabled; + Impl( RuleContext ruleContext, SupportData supportData, @@ -172,6 +178,22 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured JavaCompilationArgsProvider.merge( WrappingProvider.Helper.unwrapProviders( javaProtoLibraryAspectProviders, JavaCompilationArgsProvider.class)); + + this.isJavaProtoExportsEnabled = + ruleContext.getFragment(JavaConfiguration.class).isJavaProtoExportsEnabled(); + + if (this.isJavaProtoExportsEnabled) { + this.exportsCompilationArgs = + JavaCompilationArgsProvider.merge( + WrappingProvider.Helper.unwrapProviders( + ruleContext.getPrerequisites( + "exports", + RuleConfiguredTarget.Mode.TARGET, + JavaProtoLibraryAspectProvider.class), + JavaCompilationArgsProvider.class)); + } else { + this.exportsCompilationArgs = null; + } } void addProviders(ConfiguredAspect.Builder aspect) { @@ -225,6 +247,12 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured javaProvidersBuilder.add(JavaRuleOutputJarsProvider.EMPTY); } + if (isJavaProtoExportsEnabled) { + generatedCompilationArgsProvider = + JavaCompilationArgsProvider.merge( + ImmutableList.of(generatedCompilationArgsProvider, exportsCompilationArgs)); + } + javaProvidersBuilder.add(generatedCompilationArgsProvider); javaProvidersBuilder.add(createCcLinkParamsStore( ruleContext, aspectCommon.getProtoRuntimeDeps())); @@ -260,7 +288,9 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured ruleContext.getLabel(), ImmutableList.of(sourceJar), "JavaLite", - /* allowServices= */ true); + /* allowServices= */ true, + supportData.getProtosInExports(), + supportData.getExportedProtoSourceRoots()); } } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java index a86f703e9b..131c617650 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java @@ -121,6 +121,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe AspectDefinition.Builder result = new AspectDefinition.Builder(this) .propagateAlongAttribute("deps") + .propagateAlongAttribute("exports") .requiresConfigurationFragments(JavaConfiguration.class, ProtoConfiguration.class) .requireProviders(ProtoSourcesProvider.class) .advertiseProvider(JavaProtoLibraryAspectProvider.class) @@ -163,8 +164,13 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe */ private final JavaCompilationArgsProvider dependencyCompilationArgs; + // Compilation-args from all exports, merged together. + private final JavaCompilationArgsProvider exportsCompilationArgs; + private final Iterable javaProtoLibraryAspectProviders; + private final boolean isJavaProtoExportsEnabled; + Impl( RuleContext ruleContext, SupportData supportData, @@ -178,10 +184,27 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe ruleContext.getPrerequisites( "deps", RuleConfiguredTarget.Mode.TARGET, JavaProtoLibraryAspectProvider.class); - dependencyCompilationArgs = + this.dependencyCompilationArgs = JavaCompilationArgsProvider.merge( WrappingProvider.Helper.unwrapProviders( javaProtoLibraryAspectProviders, JavaCompilationArgsProvider.class)); + + this.isJavaProtoExportsEnabled = + ruleContext.getFragment(JavaConfiguration.class).isJavaProtoExportsEnabled(); + + if (this.isJavaProtoExportsEnabled) { + this.exportsCompilationArgs = + JavaCompilationArgsProvider.merge( + WrappingProvider.Helper.unwrapProviders( + ruleContext.getPrerequisites( + "exports", + RuleConfiguredTarget.Mode.TARGET, + JavaProtoLibraryAspectProvider.class), + JavaCompilationArgsProvider.class)); + } else { + this.exportsCompilationArgs = null; + } + } void addProviders(ConfiguredAspect.Builder aspect) { @@ -235,6 +258,12 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe javaProvidersBuilder.add(JavaRuleOutputJarsProvider.EMPTY); } + if (isJavaProtoExportsEnabled) { + generatedCompilationArgsProvider = + JavaCompilationArgsProvider.merge( + ImmutableList.of(generatedCompilationArgsProvider, exportsCompilationArgs)); + } + javaProvidersBuilder.add(generatedCompilationArgsProvider); javaProvidersBuilder.add(createCcLinkParamsStore( ruleContext, aspectCommon.getProtoRuntimeDeps())); @@ -289,7 +318,9 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe ruleContext.getLabel(), ImmutableList.of(sourceJar), "Java (Immutable)", - rpcSupport.allowServices(ruleContext)); + rpcSupport.allowServices(ruleContext), + supportData.getProtosInExports(), + supportData.getExportedProtoSourceRoots()); } } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java index 000aa5ec53..ac8fcc8a85 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java @@ -62,7 +62,9 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory { protoPathFlags, protoSourceRoot, directProtoSourceRoots, - !protoSources.isEmpty()); + !protoSources.isEmpty(), + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); Artifact descriptorSetOutput = ruleContext.getGenfilesArtifact( 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. * 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()); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java index 3d19e8c7e7..8731315b51 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java @@ -146,6 +146,15 @@ public class ProtoConfiguration extends Fragment implements ProtoConfigurationAp ) public List ccProtoLibrarySourceSuffixes; + @Option( + name = "experimental_java_proto_add_allowed_public_imports", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.INPUT_STRICTNESS, + effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.LOADING_AND_ANALYSIS}, + metadataTags = {OptionMetadataTag.EXPERIMENTAL}, + help = "If true, add --allowed_public_imports to the java compile actions.") + public boolean experimentalJavaProtoAddAllowedPublicImports; + @Override public FragmentOptions getHost() { Options host = (Options) super.getHost(); @@ -160,6 +169,8 @@ public class ProtoConfiguration extends Fragment implements ProtoConfigurationAp host.strictProtoDeps = strictProtoDeps; host.ccProtoLibraryHeaderSuffixes = ccProtoLibraryHeaderSuffixes; host.ccProtoLibrarySourceSuffixes = ccProtoLibrarySourceSuffixes; + host.experimentalJavaProtoAddAllowedPublicImports = + experimentalJavaProtoAddAllowedPublicImports; return host; } } @@ -242,4 +253,8 @@ public class ProtoConfiguration extends Fragment implements ProtoConfigurationAp public List ccProtoLibrarySourceSuffixes() { return ccProtoLibrarySourceSuffixes; } + + public boolean strictPublicImports() { + return options.experimentalJavaProtoAddAllowedPublicImports; + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java b/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java index b3644d4c17..35c0cee485 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import javax.annotation.Nullable; /** A helper class for the *Support classes containing some data from ProtoLibrary. */ @AutoCodec @@ -37,7 +38,9 @@ public abstract class SupportData { NestedSet transitiveProtoPathFlags, String protoSourceRoot, NestedSet directProtoSourceRoots, - boolean hasProtoSources) { + boolean hasProtoSources, + @Nullable NestedSet protosInExports, + @Nullable NestedSet exportedProtoSourceRoots) { return new AutoValue_SupportData( nonWeakDepsPredicate, directProtoSources, @@ -46,7 +49,9 @@ public abstract class SupportData { transitiveProtoPathFlags, protoSourceRoot, directProtoSourceRoots, - hasProtoSources); + hasProtoSources, + protosInExports, + exportedProtoSourceRoots); } public abstract Predicate getNonWeakDepsPredicate(); @@ -76,5 +81,14 @@ public abstract class SupportData { public abstract boolean hasProtoSources(); + /** .proto files in the exported dependencies of this proto_library. */ + public abstract @Nullable NestedSet getProtosInExports(); + + /** + * The {@code proto_source_root}'s collected from the current library and the exported + * dependencies. + */ + public abstract @Nullable NestedSet getExportedProtoSourceRoots(); + SupportData() {} } diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java index 2044f279ad..e992960a72 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java @@ -55,7 +55,7 @@ public class ProtoCompileActionBuilderTest { public void commandLine_basic() throws Exception { FilesToRunProvider plugin = new FilesToRunProvider( - NestedSetBuilder.emptySet(Order.STABLE_ORDER), + NestedSetBuilder.emptySet(Order.STABLE_ORDER), null /* runfilesSupport */, artifact("//:dont-care", "protoc-gen-javalite.exe")); @@ -64,28 +64,30 @@ public class ProtoCompileActionBuilderTest { "--java_out=param1,param2:$(OUT)", /* pluginExecutable= */ null, /* runtime= */ mock(TransitiveInfoCollection.class), - /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); + /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); ProtoLangToolchainProvider toolchainWithPlugin = ProtoLangToolchainProvider.create( "--$(PLUGIN_OUT)=param3,param4:$(OUT)", plugin, /* runtime= */ mock(TransitiveInfoCollection.class), - /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); + /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); SupportData supportData = SupportData.create( - Predicates.alwaysFalse(), + Predicates.alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), - /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), NestedSetBuilder.create( STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*protoSourceRoot=*/ "", - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - /* hasProtoSources= */ true); + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protoSourceRoot= */ "", + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* hasProtoSources= */ true, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); CustomCommandLine cmdLine = createCommandLineFromToolchains( @@ -95,12 +97,14 @@ public class ProtoCompileActionBuilderTest { new ToolchainInvocation("pluginName", toolchainWithPlugin, "bar.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.stableOrder().build(), - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - null /* protosInDirectDeps */, + /* transitiveProtoPathFlags= */ NestedSetBuilder.stableOrder().build(), + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* exportedProtoSourceRoots= */ null, + /* protosInDirectDeps= */ null, + /* protosInExports= */ null, Label.parseAbsoluteUnchecked("//foo:bar"), - true /* allowServices */, - ImmutableList.of() /* protocOpts */); + /* allowServices= */ true, + /* protocOpts= */ ImmutableList.of()); assertThat(cmdLine.arguments()) .containsExactly( @@ -118,26 +122,30 @@ public class ProtoCompileActionBuilderTest { // Verify that the command line contains the correct path to a generated protocol buffers. SupportData supportData = SupportData.create( - Predicates.alwaysFalse(), + Predicates.alwaysFalse(), ImmutableList.of(derivedArtifact("//:dont-care", "source_file.proto")), - /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), - /* transitiveImports= */ NestedSetBuilder.emptySet(STABLE_ORDER), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*protoSourceRoot=*/ "", - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - /* hasProtoSources= */ true); + /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveImports= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protoSourceRoot= */ "", + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* hasProtoSources= */ true, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); CustomCommandLine cmdLine = createCommandLineFromToolchains( - ImmutableList.of() /* toolchainInvocations */, + /* toolchainInvocations= */ ImmutableList.of(), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*directProtoSourceRoots=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - null /* protosInDirectDeps */, + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* directProtoSourceRoots= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* exportedProtoSourceRoots= */ null, + /* protosInDirectDeps= */ null, + /* protosInExports= */ null, Label.parseAbsoluteUnchecked("//foo:bar"), - true /* allowServices */, - ImmutableList.of() /* protocOpts */); + /* allowServices= */ true, + /* protocOpts= */ ImmutableList.of()); assertThat(cmdLine.arguments()).containsExactly("out/source_file.proto"); } @@ -149,33 +157,37 @@ public class ProtoCompileActionBuilderTest { "--java_out=param1,param2:$(OUT)", /* pluginExecutable= */ null, /* runtime= */ mock(TransitiveInfoCollection.class), - /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); + /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); SupportData supportData = SupportData.create( - Predicates.alwaysFalse(), + Predicates.alwaysFalse(), ImmutableList.of(artifact("//:dont-care", "source_file.proto")), NestedSetBuilder.create(STABLE_ORDER, artifact("//:dont-care", "import1.proto")), NestedSetBuilder.create( STABLE_ORDER, artifact("//:dont-care", "import1.proto"), artifact("//:dont-care", "import2.proto")), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*protoSourceRoot=*/ "", - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - /* hasProtoSources= */ true); + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protoSourceRoot= */ "", + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* hasProtoSources= */ true, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); CustomCommandLine cmdLine = createCommandLineFromToolchains( ImmutableList.of(new ToolchainInvocation("dontcare", toolchain, "foo.srcjar")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*directProtoSourceRoots=*/ NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* directProtoSourceRoots= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* exportedProtoSourceRoots= */ null, supportData.getProtosInDirectDeps(), + /* protosInExports= */ null, Label.parseAbsoluteUnchecked("//foo:bar"), - true /* allowServices */, - ImmutableList.of() /* protocOpts */); + /* allowServices= */ true, + /* protocOpts= */ ImmutableList.of()); assertThat(cmdLine.arguments()) .containsExactly( @@ -193,26 +205,30 @@ public class ProtoCompileActionBuilderTest { public void otherParameters() throws Exception { SupportData supportData = SupportData.create( - Predicates.alwaysFalse(), - ImmutableList.of(), - /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), - NestedSetBuilder.emptySet(STABLE_ORDER), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*protoSourceRoot=*/ "", - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - /* hasProtoSources= */ true); + Predicates.alwaysFalse(), + ImmutableList.of(), + /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), + NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protoSourceRoot= */ "", + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* hasProtoSources= */ true, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); CustomCommandLine cmdLine = createCommandLineFromToolchains( - ImmutableList.of(), + ImmutableList.of(), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*directProtoSourceRoots=*/ NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* directProtoSourceRoots= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* exportedProtoSourceRoots= */ null, supportData.getProtosInDirectDeps(), + /* protosInExports= */ null, Label.parseAbsoluteUnchecked("//foo:bar"), - false /* allowServices */, - ImmutableList.of("--foo", "--bar") /* protocOpts */); + /* allowServices= */ false, + /* protocOpts= */ ImmutableList.of("--foo", "--bar")); assertThat(cmdLine.arguments()).containsAllOf("--disallow_services", "--foo", "--bar"); } @@ -236,30 +252,34 @@ public class ProtoCompileActionBuilderTest { "--java_out=param1,param2:$(OUT)", /* pluginExecutable= */ null, /* runtime= */ mock(TransitiveInfoCollection.class), - /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); + /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); SupportData supportData = SupportData.create( - Predicates.alwaysFalse(), - ImmutableList.of(), - /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), - NestedSetBuilder.emptySet(STABLE_ORDER), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*protoSourceRoot=*/ "", - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - /* hasProtoSources= */ true); + Predicates.alwaysFalse(), + ImmutableList.of(), + /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), + NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protoSourceRoot= */ "", + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* hasProtoSources= */ true, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); CustomCommandLine cmdLine = createCommandLineFromToolchains( ImmutableList.of(new ToolchainInvocation("pluginName", toolchain, outReplacement)), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*directProtoSourceRoots=*/ NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* directProtoSourceRoots= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* exportedProtoSourceRoots= */ null, supportData.getProtosInDirectDeps(), + /* protosInExports= */ null, Label.parseAbsoluteUnchecked("//foo:bar"), - true /* allowServices */, - ImmutableList.of() /* protocOpts */); + /* allowServices= */ true, + /* protocOpts= */ ImmutableList.of()); assertThat(hasBeenCalled[0]).isFalse(); cmdLine.arguments(); @@ -274,28 +294,30 @@ public class ProtoCompileActionBuilderTest { public void exceptionIfSameName() throws Exception { SupportData supportData = SupportData.create( - Predicates.alwaysFalse(), - ImmutableList.of(), - /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), - NestedSetBuilder.emptySet(STABLE_ORDER), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*protoSourceRoot=*/ "", - /*directProtoSourceRoots=*/ NestedSetBuilder.stableOrder().build(), - /* hasProtoSources= */ true); + Predicates.alwaysFalse(), + ImmutableList.of(), + /* protosInDirectDeps= */ NestedSetBuilder.emptySet(STABLE_ORDER), + NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* protoSourceRoot= */ "", + /* directProtoSourceRoots= */ NestedSetBuilder.stableOrder().build(), + /* hasProtoSources= */ true, + /* protosInExports= */ null, + /* exportedProtoSourceRoots= */ null); ProtoLangToolchainProvider toolchain1 = ProtoLangToolchainProvider.create( "dontcare", /* pluginExecutable= */ null, /* runtime= */ mock(TransitiveInfoCollection.class), - /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); + /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); ProtoLangToolchainProvider toolchain2 = ProtoLangToolchainProvider.create( "dontcare", /* pluginExecutable= */ null, /* runtime= */ mock(TransitiveInfoCollection.class), - /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); + /* blacklistedProtos= */ NestedSetBuilder.emptySet(STABLE_ORDER)); try { createCommandLineFromToolchains( @@ -304,12 +326,14 @@ public class ProtoCompileActionBuilderTest { new ToolchainInvocation("pluginName", toolchain2, "outReplacement")), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), - /*transitiveProtoPathFlags=*/ NestedSetBuilder.emptySet(STABLE_ORDER), - /*directProtoSourceRoots=*/ NestedSetBuilder.emptySet(STABLE_ORDER), + /* transitiveProtoPathFlags= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* directProtoSourceRoots= */ NestedSetBuilder.emptySet(STABLE_ORDER), + /* exportedProtoSourceRoots= */ null, supportData.getProtosInDirectDeps(), + /* protosInExports= */ null, Label.parseAbsoluteUnchecked("//foo:bar"), - true /* allowServices */, - ImmutableList.of() /* protocOpts */); + /* allowServices= */ true, + /* protocOpts= */ ImmutableList.of()); fail("Expected an exception"); } catch (IllegalStateException e) { assertThat(e) -- cgit v1.2.3