Files
allwpilib/wpilibj/athena.gradle
2017-01-04 19:38:17 -08:00

261 lines
8.4 KiB
Groovy

apply plugin: 'cpp'
def jniDir = 'src/athena/cpp'
def generatedJNIHeaderLoc = "$buildDir/include"
def docSource = "$buildDir/docSource"
debugStripSetup(project)
sourceSets {
athena
}
configurations.create('doc')
dependencies {
athenaCompile sourceSets.shared.output
athenaCompile ntcoreDep('java', 'arm')
athenaRuntime ntcoreDep('java', 'arm')
athenaCompile cscoreDep('java', 'arm')
athenaRuntime cscoreDep('java', 'arm')
athenaCompile 'org.opencv:opencv-java:+'
athenaRuntime 'org.opencv:opencv-java:+'
doc ntcoreDep('java', 'sources')
doc cscoreDep('java', 'sources')
}
defineWpiUtilProperties()
// Configuration for the HAL bindings
model {
components {
wpilibJavaJNI(NativeLibrarySpec) {
targetPlatform 'roborio-arm'
binaries.all {
tasks.withType(CppCompile) {
dependsOn jniHeaders
addNiLibraryLinks(linker, targetPlatform)
addWpiUtilLibraryLinks(it, linker, targetPlatform)
}
}
sources {
cpp {
source {
srcDirs = ["$jniDir/lib"]
includes = ['**/*.cpp']
}
exportedHeaders {
// JDK is included for jni.h. We also need the arm-linux specific headers. This does not need to change
// when compiling on Windows
// The JNI headers are put into the build/include directory by the jniHeaders task on wpilibJavaDevices
srcDirs = ["$jniDir/include", "$jniDir/include/linux", wpiUtilInclude]
jniHeaders.outputs.files.each { file ->
srcDirs file.getPath()
}
}
lib project: ':hal', library: 'HALAthena', linkage: 'shared'
}
}
}
}
tasks {
it.wpilibjNativeLibraries.dependsOn it.wpilibJavaJNISharedLibrary
it.checkJNISymbols.dependsOn it.wpilibJavaJNISharedLibrary
}
}
// Maven publishing configuration
publishing {
publications {
wpilibj(MavenPublication) {
artifact jar
artifact(wpilibjSources) {
classifier "sources"
}
artifact(wpilibjJavadoc) {
classifier "javadoc"
}
groupId 'edu.wpi.first.wpilibj'
artifactId 'athena'
version WPILibVersion.version
}
wpilibjjni(MavenPublication) {
artifact wpilibjNativeLibraries
groupId 'edu.wpi.first.wpilibj'
artifactId 'athena-jni'
version WPILibVersion.version
}
}
setupWpilibRepo(it)
}
jar {
dependsOn { classes }
from sourceSets.athena.output
from sourceSets.shared.output
}
pmd {
sourceSets = [sourceSets.shared, sourceSets.athena]
}
task wpilibjSources(type: Jar, dependsOn: classes) {
description = 'Creates the sources jar for the maven publishing routine'
group = 'WPILib'
classifier = 'sources'
duplicatesStrategy = 'exclude'
from sourceSets.athena.allJava
from sourceSets.shared.allJava
}
task unzipDocSources(type: Copy) {
configurations.doc.files.each {
from zipTree(it)
}
include '**/*.java'
into docSource
}
task javadoc(type: Javadoc, overwrite: true) {
source sourceSets.athena.allJava, sourceSets.shared.allJava, unzipDocSources
classpath = files([sourceSets.athena.compileClasspath, sourceSets.shared.compileClasspath])
javadoc.options.links("http://docs.oracle.com/javase/8/docs/api/")
options.addStringOption "tag", "pre:a:Pre-Condition"
// options.addStringOption('Xdoclint:accessibility,syntax,reference,html', '-quiet')
}
task wpilibjJavadoc(type: Jar, dependsOn: javadoc) {
description = 'Creates the javadoc jar for the maven publishing routine'
group = 'WPILib'
classifier = 'javadoc'
duplicatesStrategy = 'exclude'
from javadoc.destinationDir
}
task jniHeaders {
description = 'Generates JNI headers from edu.wpi.first.wpilibj.hal.*'
group = 'WPILib'
def outputFolder = file(generatedJNIHeaderLoc)
inputs.files sourceSets.athena.output
outputs.file outputFolder
doLast {
outputFolder.mkdirs()
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-d', outputFolder
args '-classpath', sourceSets.athena.output.classesDir
args 'edu.wpi.first.wpilibj.can.CANJNI'
args 'edu.wpi.first.wpilibj.hal.FRCNetComm'
args 'edu.wpi.first.wpilibj.hal.HAL'
args 'edu.wpi.first.wpilibj.hal.HALUtil'
args 'edu.wpi.first.wpilibj.hal.JNIWrapper'
args 'edu.wpi.first.wpilibj.hal.AccelerometerJNI'
args 'edu.wpi.first.wpilibj.hal.AnalogJNI'
args 'edu.wpi.first.wpilibj.hal.AnalogGyroJNI'
args 'edu.wpi.first.wpilibj.hal.ConstantsJNI'
args 'edu.wpi.first.wpilibj.hal.CounterJNI'
args 'edu.wpi.first.wpilibj.hal.DigitalGlitchFilterJNI'
args 'edu.wpi.first.wpilibj.hal.DIOJNI'
args 'edu.wpi.first.wpilibj.hal.EncoderJNI'
args 'edu.wpi.first.wpilibj.hal.I2CJNI'
args 'edu.wpi.first.wpilibj.hal.InterruptJNI'
args 'edu.wpi.first.wpilibj.hal.NotifierJNI'
args 'edu.wpi.first.wpilibj.hal.PortsJNI'
args 'edu.wpi.first.wpilibj.hal.PWMJNI'
args 'edu.wpi.first.wpilibj.hal.RelayJNI'
args 'edu.wpi.first.wpilibj.hal.SPIJNI'
args 'edu.wpi.first.wpilibj.hal.SolenoidJNI'
args 'edu.wpi.first.wpilibj.hal.CompressorJNI'
args 'edu.wpi.first.wpilibj.hal.PDPJNI'
args 'edu.wpi.first.wpilibj.hal.PowerJNI'
args 'edu.wpi.first.wpilibj.hal.SerialPortJNI'
args 'edu.wpi.first.wpilibj.hal.OSSerialPortJNI'
args 'edu.wpi.first.wpilibj.hal.ThreadsJNI'
}
}
}
task checkJNISymbols() {
description = 'Checks to make sure all native JNI symbols exist'
group = 'WPILib'
dependsOn jniHeaders
def nmOutput = new ByteArrayOutputStream()
def lib
model {
binaries {
withType(SharedLibraryBinarySpec) { spec ->
lib = new File(spec.sharedLibraryFile.absolutePath)
}
}
}
doLast {
defineCrossCompilerProperties()
exec {
commandLine binTool('nm'), lib
standardOutput = nmOutput
}
// Remove '\r' so we can check for full string contents
String nmSymbols = nmOutput.toString().replace('\r', '')
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. Add \n so we can check for the exact symbol
def found = nmSymbols.contains(p2 + '\n')
if (!found) {
throw new GradleException("Found a definition that does not have a matching symbol ${p2}")
}
}
}
}
}
}
}
}
task wpilibjNativeLibraries(type: Jar) {
description = 'Creates the native library jar for the maven publishing routine'
baseName = 'nativelibraries'
group = 'WPILib'
duplicatesStrategy = 'exclude'
dependsOn project(':wpilibj').jniHeaders
// Include the JNI library
model {
binaries {
withType(SharedLibraryBinarySpec) { spec ->
from(spec.sharedLibraryFile) {
into 'lib'
}
from(new File(spec.sharedLibraryFile.absolutePath + ".debug")) {
into 'lib'
}
}
}
}
project(':wpilibj').jniHeaders.outputs.each {
from(it) {
into 'include'
}
}
}
build.dependsOn checkJNISymbols
build.dependsOn wpilibjNativeLibraries
clean {
delete generatedJNIHeaderLoc
delete docSource
}