Skip to content

Commit

Permalink
Do not fail if .so artifacts are present in Java target dependencies …
Browse files Browse the repository at this point in the history
…(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
  • Loading branch information
comius authored and copybara-github committed Mar 1, 2021
1 parent 6e2bba6 commit f9a93fd
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -97,16 +96,13 @@ private void addCcTarget(TransitiveInfoCollection dep) {

/** Include files and genrule artifacts. */
private void addTarget(TransitiveInfoCollection dep) {
List<Artifact> 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))
Expand Down

0 comments on commit f9a93fd

Please sign in to comment.