From 7632928a116efc4e28a02ec9206870663bcaacf7 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Wed, 17 Nov 2021 05:42:17 -0800 Subject: [PATCH] Remove merging of java_outputs in JavaPluginInfo. JavaPluginInfo merging of java_outputs caused a significant regression when a large number of plugins is present. This value is not used by native code and it does not get exposed to Starlark. The only use case for java_outputs is IDE integrations, where the value is used from a single java_plugin target. Fixes https://github.com/bazelbuild/bazel/issues/14287 Closes #14288. PiperOrigin-RevId: 410502716 --- .../devtools/build/lib/rules/java/JavaCommon.java | 4 ++-- .../devtools/build/lib/rules/java/JavaInfo.java | 2 +- .../build/lib/rules/java/JavaInfoBuildHelper.java | 2 +- .../build/lib/rules/java/JavaPluginInfo.java | 12 ++++++------ .../lib/rules/java/JavaPluginsFlagAliasRule.java | 2 +- .../build/lib/rules/java/JavaTargetAttributes.java | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index 8eafba2303e223..a9bf9a8a234390 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -787,7 +787,7 @@ private JavaPluginInfo collectPlugins() { Iterables.addAll(result, getDirectJavaPluginInfoForAttribute(ruleContext, ":java_plugins")); Iterables.addAll(result, getDirectJavaPluginInfoForAttribute(ruleContext, "plugins")); Iterables.addAll(result, getExportedJavaPluginInfoForAttribute(ruleContext, "deps")); - return JavaPluginInfo.merge(result); + return JavaPluginInfo.mergeWithoutJavaOutputs(result); } private static Iterable getDirectJavaPluginInfoForAttribute( @@ -841,7 +841,7 @@ private static ImmutableSet getProcessorClasses(RuleContext ruleContext) } public static JavaPluginInfo getTransitivePlugins(RuleContext ruleContext) { - return JavaPluginInfo.merge( + return JavaPluginInfo.mergeWithoutJavaOutputs( Iterables.concat( getDirectJavaPluginInfoForAttribute(ruleContext, "exported_plugins"), getExportedJavaPluginInfoForAttribute(ruleContext, "exports"))); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java index 4cab4585fd2a2b..0b59ab3610e22f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java @@ -159,7 +159,7 @@ public static JavaInfo merge(List providers, boolean withExportsProvid .addProvider( JavaRuleOutputJarsProvider.class, JavaRuleOutputJarsProvider.merge(javaRuleOutputJarsProviders)) - .javaPluginInfo(JavaPluginInfo.merge(javaPluginInfos)) + .javaPluginInfo(JavaPluginInfo.mergeWithoutJavaOutputs(javaPluginInfos)) .addProvider(JavaCcInfoProvider.class, JavaCcInfoProvider.merge(javaCcInfoProviders)) // TODO(b/65618333): add merge function to JavaGenJarsProvider. See #3769 // TODO(iirina): merge or remove JavaCompilationInfoProvider diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java index 9e4d73465b7e08..feae409ebf3da4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java @@ -235,7 +235,7 @@ private JavaExportsProvider createJavaExportsProvider(Iterable exports private JavaPluginInfo mergeExportedJavaPluginInfo( Iterable plugins, Iterable javaInfos) { - return JavaPluginInfo.merge( + return JavaPluginInfo.mergeWithoutJavaOutputs( concat( plugins, stream(javaInfos) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginInfo.java index 39d4aa982b114c..043d839e9e0edf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginInfo.java @@ -162,21 +162,21 @@ private JavaPluginData disableAnnotationProcessing() { } } - public static JavaPluginInfo merge(JavaPluginInfo a, JavaPluginInfo b) { - return a.isEmpty() ? b : b.isEmpty() ? a : merge(ImmutableList.of(a, b)); + public static JavaPluginInfo mergeWithoutJavaOutputs(JavaPluginInfo a, JavaPluginInfo b) { + return a.isEmpty() ? b : b.isEmpty() ? a : mergeWithoutJavaOutputs(ImmutableList.of(a, b)); } - public static JavaPluginInfo merge(Iterable providers) { + public static JavaPluginInfo mergeWithoutJavaOutputs(Iterable providers) { List plugins = new ArrayList<>(); List apiGeneratingPlugins = new ArrayList<>(); - ImmutableList.Builder outputs = ImmutableList.builder(); for (JavaPluginInfo provider : providers) { plugins.add(provider.plugins()); apiGeneratingPlugins.add(provider.apiGeneratingPlugins()); - outputs.addAll(provider.getJavaOutputs()); } return new AutoValue_JavaPluginInfo( - outputs.build(), JavaPluginData.merge(plugins), JavaPluginData.merge(apiGeneratingPlugins)); + ImmutableList.of(), + JavaPluginData.merge(plugins), + JavaPluginData.merge(apiGeneratingPlugins)); } public static JavaPluginInfo create( diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginsFlagAliasRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginsFlagAliasRule.java index dfa65b2cb6fc9d..54dc900d56c0b4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginsFlagAliasRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaPluginsFlagAliasRule.java @@ -76,7 +76,7 @@ public ConfiguredTarget create(RuleContext ruleContext) } JavaPluginInfo javaPluginInfo = - JavaPluginInfo.merge( + JavaPluginInfo.mergeWithoutJavaOutputs( ruleContext.getPrerequisites(":java_plugins", JavaPluginInfo.PROVIDER)); return new RuleConfiguredTargetBuilder(ruleContext) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaTargetAttributes.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaTargetAttributes.java index ed2b73abf39b05..0ce29e826e1fac 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaTargetAttributes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaTargetAttributes.java @@ -298,7 +298,7 @@ public Builder addResourceJars(NestedSet resourceJars) { public Builder addPlugin(JavaPluginInfo plugins) { Preconditions.checkArgument(!built); - this.plugins = JavaPluginInfo.merge(this.plugins, plugins); + this.plugins = JavaPluginInfo.mergeWithoutJavaOutputs(this.plugins, plugins); return this; }