From fbac524a02d083daf8425f3bebe550976f3b73a4 Mon Sep 17 00:00:00 2001 From: Ben Liblit Date: Mon, 28 May 2018 08:31:22 -0700 Subject: [PATCH] Find JVM shared library better across versions and operating systems We now use "-rpath" on both Linux and macOS. This linker flag sets the ELF RPATH on Linux, and the "@rpath" attribute on macOS, but effectively it's doing the same thing, and that same thing is exactly what we want. I think. On Linux, we also now look for the JVM shared library in three different places. The library has moved between Java 8 and 9, and even on Java 9 it goes in a different place on Fedora 28 versus Ubuntu 16.04. --- com.ibm.wala.cast/build.gradle | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/com.ibm.wala.cast/build.gradle b/com.ibm.wala.cast/build.gradle index 5cf01f6f9..9b4b52108 100644 --- a/com.ibm.wala.cast/build.gradle +++ b/com.ibm.wala.cast/build.gradle @@ -42,11 +42,9 @@ model { switch (targetPlatform.operatingSystem.name) { case 'linux': headers.srcDirs "$jniIncludeDir/linux" - switch (targetPlatform.architecture.name) { - case 'x86-64': - sharedLibraryLinkFile = file("$currentJavaHome/jre/lib/amd64/server/libjvm.so") - break - } + def subdirs = ['jre/lib/amd64/server', 'lib/amd64/server', 'lib/server'] + def candidates = subdirs.collect { file("$currentJavaHome/$it/libjvm.so") } + sharedLibraryLinkFile = candidates.find { it.exists() } break case 'osx': headers.srcDirs "$jniIncludeDir/darwin" @@ -79,17 +77,11 @@ model { buildable = false } withType(SharedLibraryBinarySpec) { - switch ("$targetPlatform.operatingSystem.name/$targetPlatform.architecture.name") { - case 'linux/x86-64': - $ - .repositories['libs'] - .resolveLibrary('jdk') - .binaries - .withType(SharedLibraryBinary) - .findResults { it.sharedLibraryLinkFile } - *.parentFile - .each { linker.args "-Wl,-rpath=$it" } - } + def libDir = $.repositories['libs'].resolveLibrary('jdk') + .binaries.withType(SharedLibraryBinary) + .find { it.targetPlatform.name == targetPlatform.name } + .sharedLibraryLinkFile.parent + linker.args "-Wl,-rpath,$libDir" } } }