Stop using deprecated "javah" to generate JNI headers
"javah" was deprecated in Java 9, and has been removed entirely in Java 10. The right way to generate headers now is by using the "-h" flag to "javac". When "javac" is run in this way, it still generates bytecode too. So ideally, we'd run "javac" just once to generate bytecode and headers simultaneously. Fortunately, the Gradle JNI plugin at <https://github.com/wpilibsuite/gradle-jni> help us do this cleanly. Nice!
This commit is contained in:
parent
85651608e9
commit
5cf8b7efe3
|
@ -2,6 +2,7 @@ plugins {
|
|||
id 'com.github.hauner.jarTest'
|
||||
id 'cpp'
|
||||
id 'eclipse'
|
||||
id 'edu.wpi.first.GradleJni' version '0.2.1'
|
||||
}
|
||||
|
||||
eclipse.project.natures 'org.eclipse.pde.PluginNature'
|
||||
|
@ -20,30 +21,6 @@ dependencies {
|
|||
|
||||
def currentJvm = org.gradle.internal.jvm.Jvm.current()
|
||||
|
||||
task generateJniHeaders(type: Exec, dependsOn: [testClasses, ':com.ibm.wala.cast:classes']) {
|
||||
// classes for which we need headers
|
||||
def nativePackage = 'com.ibm.wala.cast.test'
|
||||
def nativeClasses = ['TestNativeTranslator']
|
||||
def qualifiedClasses = nativeClasses.collect { "$nativePackage.$it" }
|
||||
|
||||
// inputs and outputs, suitable for use with rule-based model configuration
|
||||
ext {
|
||||
sourceDir = null
|
||||
headerDir = "$buildDir/include"
|
||||
}
|
||||
inputs.files files(qualifiedClasses.collect { "$buildDir/${it.replace('.', '/')}.class" })
|
||||
outputs.dir headerDir
|
||||
outputs.cacheIf { true }
|
||||
|
||||
// javah command to generate headers
|
||||
def sourceSets = [sourceSets.test, project(':com.ibm.wala.cast').sourceSets.main]
|
||||
def classesDirs = sourceSets.inject(files()) { acc, val -> acc.plus(val.output.classesDirs) }
|
||||
def classpath = classesDirs.asPath
|
||||
def javah = currentJvm.getExecutable('javah')
|
||||
commandLine(javah, '-d', "$headerDir", '-classpath', classpath)
|
||||
args(qualifiedClasses)
|
||||
}
|
||||
|
||||
def addCastRpath(currentJvm, targetPlatform, linker) {
|
||||
switch (targetPlatform.operatingSystem.name) {
|
||||
case 'linux':
|
||||
|
@ -59,19 +36,22 @@ def addCastRpath(currentJvm, targetPlatform, linker) {
|
|||
}
|
||||
|
||||
def addCastEnvironment(task, xlatorLibrary) {
|
||||
def castLibrary = xlatorLibrary.libs[0].linkFiles.singleFile
|
||||
def castLibrary = xlatorLibrary.libs[2].linkFiles.singleFile
|
||||
def castLibraryDirectory = castLibrary.parent
|
||||
assert castLibraryDirectory.endsWith('/com.ibm.wala.cast/build/libs/cast/shared')
|
||||
task.environment 'DYLD_LIBRARY_PATH', castLibrary.parent
|
||||
}
|
||||
|
||||
model {
|
||||
components {
|
||||
xlator_test(NativeLibrarySpec) {
|
||||
xlator_test(JniNativeLibrarySpec) {
|
||||
javaCompileTasks << compileTestJava
|
||||
|
||||
sources.cpp {
|
||||
source {
|
||||
srcDirs = ['harness-src/c']
|
||||
include 'smoke.cpp'
|
||||
}
|
||||
generatedBy generateJniHeaders
|
||||
['cast', 'jdk'].each {
|
||||
lib project: ':com.ibm.wala.cast', library: it
|
||||
}
|
||||
|
@ -117,10 +97,12 @@ model {
|
|||
// main executable to run for test
|
||||
def executableBinary = $.binaries.smoke_mainExecutable
|
||||
executable executableBinary.executableFile
|
||||
dependsOn executableBinary
|
||||
def pathElements = [$.binaries.test.getClassesDir()]
|
||||
|
||||
// implementations of native methods
|
||||
def library = $.binaries.xlator_testSharedLibrary
|
||||
dependsOn library
|
||||
pathElements << library.sharedLibraryFile.parent
|
||||
|
||||
// "primorial.txt" resource loaded during test
|
||||
|
|
Loading…
Reference in New Issue