WALA/com.ibm.wala.cast.test/build.gradle

147 lines
4.0 KiB
Groovy
Raw Normal View History

plugins {
id 'com.github.hauner.jarTest'
id 'cpp'
id 'eclipse'
}
eclipse.project.natures 'org.eclipse.pde.PluginNature'
sourceSets.test.java.srcDirs = ['harness-src/java']
2017-11-27 08:34:48 +00:00
dependencies {
testCompile(
'junit:junit:4.12',
project(':com.ibm.wala.cast'),
project(':com.ibm.wala.core'),
project(':com.ibm.wala.util'),
project(configuration: 'testArchives', path: ':com.ibm.wala.core.tests'),
)
}
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':
case 'osx':
[
// TODO: compute path on following line from 'cast' library properties somehow
"${project(':com.ibm.wala.cast').buildDir}/libs/cast/shared",
// TODO: compute paths on following lines from 'jdk' library properties somehow
"${currentJvm.javaHome}/jre/lib/amd64/server",
"${currentJvm.javaHome}/jre/lib/server",
].each { linker.args "-Wl,-rpath,$it" }
}
}
def addCastEnvironment(task, xlatorLibrary) {
def castLibrary = xlatorLibrary.libs[0].linkFiles.singleFile
task.environment 'DYLD_LIBRARY_PATH', castLibrary.parent
}
model {
components {
xlator_test(NativeLibrarySpec) {
sources.cpp {
source {
srcDirs = ['harness-src/c']
include 'smoke.cpp'
}
generatedBy generateJniHeaders
['cast', 'jdk'].each {
lib project: ':com.ibm.wala.cast', library: it
}
}
2018-05-27 23:47:33 +00:00
binaries {
withType(StaticLibraryBinarySpec) {
buildable = false
}
withType(SharedLibraryBinarySpec) {
addCastRpath(currentJvm, targetPlatform, linker)
}
}
}
2018-05-27 23:47:33 +00:00
smoke_main(NativeExecutableSpec) {
sources.cpp {
source {
srcDirs = ['harness-src/c']
include 'smoke_main.cpp'
}
['cast', 'jdk'].each {
lib project: ':com.ibm.wala.cast', library: it
}
}
2018-05-27 23:47:33 +00:00
binaries.all {
addCastRpath(currentJvm, targetPlatform, linker)
}
}
}
tasks {
test {
def lib = linkXlator_testSharedLibrary
dependsOn lib
systemProperty 'java.library.path', lib.destinationDirectory.get().asFile
addCastEnvironment(it, $.binaries.xlator_testSharedLibrary)
}
checkSmoke_main(Exec) {
// main executable to run for test
def executableBinary = $.binaries.smoke_mainExecutable
executable executableBinary.executableFile
def pathElements = [$.binaries.test.getClassesDir()]
// implementations of native methods
def library = $.binaries.xlator_testSharedLibrary
pathElements << library.sharedLibraryFile.parent
// "primorial.txt" resource loaded during test
def coreResources = project(':com.ibm.wala.core').processResources
dependsOn coreResources
pathElements << coreResources.destinationDir
// additional supporting Java class files
['cast', 'core', 'util'].each {
def compileJava = project(":com.ibm.wala.$it").compileJava
dependsOn compileJava
pathElements << compileJava.destinationDir
}
// all combined as a colon-delimited path list
args pathElements.join(':')
addCastEnvironment(it, $.binaries.xlator_testSharedLibrary)
}
check.dependsOn checkSmoke_main
}
}