From f9a93fd5b0ab9f5a3ed1ad6273e1d63bfebc2af5 Mon Sep 17 00:00:00 2001 From: ilist Date: Mon, 1 Mar 2021 04:54:41 -0800 Subject: [PATCH] Do not fail if .so artifacts are present in Java target dependencies (undoing a previous cl). Failing in such cases was a mistake. There are a couple of cases, where .so are valid, should not be collected and should not throw an error. Examples are: - Bazel blackbox test, where whole JDK is put into data attribute. There are .so libraries, but there is no need to specify their path using -Djava.library.path - any Java that loads JNI using (System.load with a full path) instead of System.loadLibrary (with just a name of the library) PiperOrigin-RevId: 360160153 --- .../rules/java/NativeLibraryNestedSetBuilder.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java index 7705ae853f8932..474180a55046e8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.rules.cpp.CppFileTypes; import com.google.devtools.build.lib.rules.cpp.LibraryToLink; import com.google.devtools.build.lib.util.FileType; -import java.util.List; /** A builder that helps construct nested sets of native libraries. */ public final class NativeLibraryNestedSetBuilder { @@ -97,16 +96,13 @@ private void addCcTarget(TransitiveInfoCollection dep) { /** Include files and genrule artifacts. */ private void addTarget(TransitiveInfoCollection dep) { - List soLibraries = + if (ruleContext.getFragment(JavaConfiguration.class).dontCollectSoArtifacts()) { + return; + } + for (Artifact artifact : FileType.filterList( dep.getProvider(FileProvider.class).getFilesToBuild().toList(), - CppFileTypes.SHARED_LIBRARY); - if (!soLibraries.isEmpty() - && ruleContext.getFragment(JavaConfiguration.class).dontCollectSoArtifacts()) { - ruleContext.ruleError( - ".so libraries as artifact (from filegroup or genrule) are present in the dependencies"); - } - for (Artifact artifact : soLibraries) { + CppFileTypes.SHARED_LIBRARY)) { builder.add( LibraryToLink.builder() .setLibraryIdentifier(CcLinkingOutputs.libraryIdentifierOf(artifact))