From bc83c1ff66a2abc792d25013f2988702f93355a8 Mon Sep 17 00:00:00 2001 From: Luca Di Grazia Date: Sun, 4 Sep 2022 16:20:33 +0200 Subject: [PATCH] Flip and remove incompatible_dont_collect_so_artifacts flag. Downstream tests were run https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1911#b7a47544-7f5a-440b-ab15-c64c8b264bb8 The code for those tests was modified to throw a failure on each uncollected .so library. In all cases the library did not to appear on -Djava.library.path. RELNOTES[INC]: Flip and remove incompatible_dont_collect_so_artifacts (https://github.com/bazelbuild/bazel/issues/13043). PiperOrigin-RevId: 364973576 --- .../build/lib/rules/java/JavaBinary.java | 7 +- .../build/lib/rules/java/JavaCommon.java | 105 ++++-------------- .../lib/rules/java/JavaConfiguration.java | 49 ++++++++ .../build/lib/rules/java/JavaOptions.java | 21 ++++ .../java/NativeLibraryNestedSetBuilder.java | 74 ++++-------- 5 files changed, 114 insertions(+), 142 deletions(-) diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java index 57ae2448f21..cc7a91024c3 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java @@ -52,7 +52,6 @@ import com.google.devtools.build.lib.rules.cpp.LibraryToLink; import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType; import com.google.devtools.build.lib.rules.java.JavaConfiguration.OneVersionEnforcementLevel; -import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar; import com.google.devtools.build.lib.rules.java.proto.GeneratedExtensionRegistryProvider; import com.google.devtools.build.lib.util.OS; import com.google.devtools.build.lib.util.Pair; @@ -205,7 +204,10 @@ public ConfiguredTarget create(RuleContext ruleContext) JavaRuleOutputJarsProvider.Builder ruleOutputJarsProviderBuilder = JavaRuleOutputJarsProvider.builder() .addOutputJar( - OutputJar.builder().fromJavaCompileOutputs(outputs).addSourceJar(srcJar).build()); + /* classJar= */ classJar, + /* iJar= */ null, + /* manifestProto= */ outputs.manifestProto(), + /* sourceJars= */ ImmutableList.of(srcJar)); JavaTargetAttributes attributes = attributesBuilder.build(); List nativeLibraries = attributes.getNativeLibraries(); @@ -236,6 +238,7 @@ public ConfiguredTarget create(RuleContext ruleContext) ruleOutputJarsProviderBuilder, javaSourceJarsProviderBuilder); javaArtifactsBuilder.setCompileTimeDependencies(outputs.depsProto()); + ruleOutputJarsProviderBuilder.setJdeps(outputs.depsProto()); JavaCompilationArtifacts javaArtifacts = javaArtifactsBuilder.build(); common.setJavaCompilationArtifacts(javaArtifacts); diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index 087d0413240..4d6a9ff0a2d 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -13,16 +13,12 @@ // limitations under the License. package com.google.devtools.build.lib.rules.java; -import static com.google.common.collect.ImmutableList.toImmutableList; - import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Streams; import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.AnalysisUtils; import com.google.devtools.build.lib.analysis.FileProvider; import com.google.devtools.build.lib.analysis.OutputGroupInfo; import com.google.devtools.build.lib.analysis.PrerequisiteArtifacts; @@ -44,11 +40,9 @@ import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.packages.Type; -import com.google.devtools.build.lib.rules.cpp.CcInfo; -import com.google.devtools.build.lib.rules.cpp.CcNativeLibraryInfo; import com.google.devtools.build.lib.rules.cpp.LibraryToLink; import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType; -import com.google.devtools.build.lib.rules.java.JavaPluginInfo.JavaPluginData; +import com.google.devtools.build.lib.rules.java.JavaPluginInfoProvider.JavaPluginInfo; import com.google.devtools.build.lib.util.FileTypeSet; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.FileSystemUtils; @@ -59,7 +53,6 @@ import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.stream.Stream; import javax.annotation.Nullable; /** A helper class to create configured targets for Java rules. */ @@ -79,7 +72,7 @@ public class JavaCommon { targetsTreatedAsDeps; private final ImmutableList sources; - private JavaPluginInfo activePlugins = JavaPluginInfo.empty(); + private JavaPluginInfoProvider activePlugins = JavaPluginInfoProvider.empty(); private final RuleContext ruleContext; private final JavaSemantics semantics; @@ -696,62 +689,6 @@ public void addTransitiveInfoProviders( javaInfoBuilder.addProvider(JavaExportsProvider.class, exportsProvider); javaInfoBuilder.addProvider(JavaCompilationInfoProvider.class, compilationInfoProvider); - - addCcRelatedProviders(builder, javaInfoBuilder); - } - - /** Adds Cc related providers to a Java target. */ - private void addCcRelatedProviders( - RuleConfiguredTargetBuilder ruleBuilder, JavaInfo.Builder javaInfoBuilder) { - Iterable deps = targetsTreatedAsDeps(ClasspathType.BOTH); - - - ImmutableList ccInfos = - Streams.concat( - AnalysisUtils.getProviders(deps, CcInfo.PROVIDER).stream(), - AnalysisUtils.getProviders(deps, JavaCcLinkParamsProvider.PROVIDER).stream() - .map(JavaCcLinkParamsProvider::getCcInfo), - JavaInfo.getProvidersFromListOfTargets(JavaCcInfoProvider.class, deps).stream() - .map(JavaCcInfoProvider::getCcInfo)) - .collect(toImmutableList()); - - CcInfo mergedCcInfo = CcInfo.merge(ccInfos); - - // Collect library paths from all attributes (including data) - Iterable data; - if (ruleContext.getRule().isAttrDefined("data", BuildType.LABEL_LIST)) { - data = ruleContext.getPrerequisites("data"); - } else { - data = ImmutableList.of(); - } - CcNativeLibraryInfo mergedCcNativeLibraryInfo = - CcNativeLibraryInfo.merge( - Streams.concat( - Stream.of(mergedCcInfo.getCcNativeLibraryInfo()), - AnalysisUtils.getProviders( - Iterables.concat(deps, data), JavaNativeLibraryInfo.PROVIDER) - .stream() - .map(JavaNativeLibraryInfo::getTransitiveJavaNativeLibraries) - .map(CcNativeLibraryInfo::new), - JavaInfo.getProvidersFromListOfTargets(JavaCcInfoProvider.class, data).stream() - .map(JavaCcInfoProvider::getCcInfo) - .map(CcInfo::getCcNativeLibraryInfo), - AnalysisUtils.getProviders(data, CcInfo.PROVIDER).stream() - .map(CcInfo::getCcNativeLibraryInfo)) - .collect(toImmutableList())); - - CcInfo filteredCcInfo = - CcInfo.builder() - .setCcLinkingContext(mergedCcInfo.getCcLinkingContext()) - .setCcNativeLibraryInfo(mergedCcNativeLibraryInfo) - .build(); - - if (ruleContext - .getFragment(JavaConfiguration.class) - .experimentalPublishJavaCcLinkParamsInfo()) { - ruleBuilder.addNativeDeclaredProvider(new JavaCcLinkParamsProvider(filteredCcInfo)); - } - javaInfoBuilder.addProvider(JavaCcInfoProvider.class, new JavaCcInfoProvider(filteredCcInfo)); } private InstrumentedFilesInfo getInstrumentationFilesProvider( @@ -826,32 +763,28 @@ private void addPlugins(JavaTargetAttributes.Builder attributes) { * added to the given attributes. Plugins having repetitive names/paths will be added only once. */ public static void addPlugins( - JavaTargetAttributes.Builder attributes, JavaPluginInfo activePlugins) { + JavaTargetAttributes.Builder attributes, JavaPluginInfoProvider activePlugins) { attributes.addPlugin(activePlugins); } - private JavaPluginInfo collectPlugins() { - List result = new ArrayList<>(); - Iterables.addAll(result, getJavaPluginInfoForAttribute(ruleContext, ":java_plugins")); - Iterables.addAll(result, getJavaPluginInfoForAttribute(ruleContext, "plugins")); - Iterables.addAll(result, getJavaPluginInfoForAttribute(ruleContext, "deps")); - return JavaPluginInfo.merge(result); + private JavaPluginInfoProvider collectPlugins() { + List result = new ArrayList<>(); + Iterables.addAll(result, getPluginInfoProvidersForAttribute(ruleContext, ":java_plugins")); + Iterables.addAll(result, getPluginInfoProvidersForAttribute(ruleContext, "plugins")); + Iterables.addAll(result, getPluginInfoProvidersForAttribute(ruleContext, "deps")); + return JavaPluginInfoProvider.merge(result); } - private static Iterable getJavaPluginInfoForAttribute( + private static Iterable getPluginInfoProvidersForAttribute( RuleContext ruleContext, String attribute) { if (ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) { - return ruleContext.getPrerequisites(attribute).stream() - .map(JavaInfo::getJavaInfo) - .filter(Objects::nonNull) - .map(JavaInfo::getJavaPluginInfo) - .filter(Objects::nonNull) - .collect(toImmutableList()); + return JavaInfo.getProvidersFromListOfTargets( + JavaPluginInfoProvider.class, ruleContext.getPrerequisites(attribute)); } return ImmutableList.of(); } - JavaPluginInfo createJavaPluginInfo(RuleContext ruleContext) { + JavaPluginInfoProvider getJavaPluginInfoProvider(RuleContext ruleContext) { NestedSet processorClasses = NestedSetBuilder.wrap(Order.NAIVE_LINK_ORDER, getProcessorClasses(ruleContext)); NestedSet processorClasspath = getRuntimeClasspath(); @@ -860,8 +793,8 @@ JavaPluginInfo createJavaPluginInfo(RuleContext ruleContext) { dataProvider != null ? dataProvider.getFilesToBuild() : NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER); - return JavaPluginInfo.create( - JavaPluginData.create(processorClasses, processorClasspath, data), + return JavaPluginInfoProvider.create( + JavaPluginInfo.create(processorClasses, processorClasspath, data), ruleContext.attributes().get("generates_api", Type.BOOLEAN)); } @@ -875,11 +808,11 @@ private static ImmutableSet getProcessorClasses(RuleContext ruleContext) : ImmutableSet.of(); } - public static JavaPluginInfo getTransitivePlugins(RuleContext ruleContext) { - return JavaPluginInfo.merge( + public static JavaPluginInfoProvider getTransitivePlugins(RuleContext ruleContext) { + return JavaPluginInfoProvider.merge( Iterables.concat( - getJavaPluginInfoForAttribute(ruleContext, "exported_plugins"), - getJavaPluginInfoForAttribute(ruleContext, "exports"))); + getPluginInfoProvidersForAttribute(ruleContext, "exported_plugins"), + getPluginInfoProvidersForAttribute(ruleContext, "exports"))); } public static Runfiles getRunfiles( diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java index 618f33d5f58..a1e8c6b373b 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java @@ -17,6 +17,7 @@ import com.google.common.base.Ascii; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.analysis.PlatformOptions; import com.google.devtools.build.lib.analysis.config.BuildOptions; @@ -26,8 +27,12 @@ import com.google.devtools.build.lib.analysis.config.RequiresOptions; import com.google.devtools.build.lib.analysis.starlark.annotations.StarlarkConfigurationField; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.starlarkbuildapi.java.JavaConfigurationApi; +import com.google.devtools.common.options.TriState; import java.util.Map; import java.util.Objects; import javax.annotation.Nullable; @@ -91,6 +96,8 @@ public enum ImportDepsCheckingLevel { private final String fixDepsTool; private final Label proguardBinary; private final ImmutableList