blob: 6ba893fe679aa191a024bac5bdc9bd99dd3bdcde [file] [log] [blame]
import org.gradle.internal.os.OperatingSystem
apply plugin: 'java'
apply plugin: 'net.ltgt.errorprone'
repositories {
mavenCentral()
}
configurations.errorprone {
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9'
}
def generatedJNIHeaderLoc = "${buildDir}/include"
sourceSets {
user {
java {
srcDirs = [userJavaSrc]
}
}
main {
java {
srcDirs = [javaSrc]
}
}
}
dependencies {
compile sourceSets.user.output
runtime sourceSets.user.output
compile wpilibjDep
runtime wpilibjDep
compile javaNetTablesDep
runtime javaNetTablesDep
compile fileTree(dir: javaLibraryLoc, include: ['*.jar'])
runtime fileTree(dir: javaLibraryLoc, include: ['*.jar'])
}
jar {
description = 'Generates jar'
baseName = libraryName
duplicatesStrategy = 'exclude'
dependsOn { classes }
if (embedJavaLibraries) {
def tree = fileTree(dir: javaLibraryLoc, include: ['*.jar'])
tree.each {
from zipTree(it.path)
}
}
if (embedJavaLibraries) {
from sourceSets.user.output
}
}
/**
* Generates the JNI headers
*/
task jniHeaders {
description = 'Generates JNI headers'
group = 'WPILib'
def outputFolder = file(generatedJNIHeaderLoc)
inputs.files sourceSets.main.output
outputs.file outputFolder
doLast {
outputFolder.mkdirs()
exec {
ignoreExitValue = true
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-d', outputFolder
args '-classpath', sourceSets.main.runtimeClasspath.asPath
args jniDefinitions
}
}
}
ext.getNativeJNISymbols = {
def symbolsList = []
jniHeaders.outputs.files.each {
FileTree tree = fileTree(dir: it)
tree.each { File file ->
file.eachLine { line ->
if (line.trim()) {
if (line.startsWith("JNIEXPORT ") && line.contains('JNICALL')) {
def (p1, p2) = line.split('JNICALL').collect { it.trim() }
// p2 is our JNI call
symbolsList << p2
}
}
}
}
}
return symbolsList
}
clean {
delete generatedJNIHeaderLoc
}
compileJava {
options.compilerArgs << '-Xlint:unchecked' << "-Werror"
}
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}
// This creates a lambda that the main build.gradle can access, which sets up the JNI includes for the
// target build platform. This lambda is exposed as a property in the main build.gradle.
ext.setupJniIncludes = { binaries ->
def platformSpecificIncludeFlag = { loc, cppCompiler ->
if (OperatingSystem.current().isWindows()) {
cppCompiler.args "/I$loc"
} else {
cppCompiler.args '-I', loc
}
}
binaries.all {
tasks.withType(CppCompile) {
cppCompiler.args '-I', file("${rootDir}/java/arm-linux").absolutePath
cppCompiler.args '-I', file("${rootDir}/java/arm-linux/linux").absolutePath
jniHeaders.outputs.files.each { file ->
cppCompiler.args '-I', file.getPath()
}
dependsOn jniHeaders
}
}
}