import edu.wpi.first.nativeutils.NativeUtils import org.gradle.api.file.FileCollection import org.gradle.internal.os.OperatingSystem repositories { mavenCentral() } apply plugin: 'cpp' apply plugin: 'visual-studio' apply plugin: 'edu.wpi.first.NativeUtils' apply plugin: 'java' apply plugin: 'net.ltgt.errorprone' apply plugin: 'pmd' configurations.errorprone { resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9' } apply from: '../config.gradle' sourceSets { dev } task nativeTestFilesJar(type: Jar) { destinationDir = project.buildDir classifier = "nativeTestFiles" project.model { binaries { withType(SharedLibraryBinarySpec) { binary -> if (binary.component.name == 'wpilibJNIStatic') { from(binary.sharedLibraryFile) { into NativeUtils.getPlatformPath(binary) } dependsOn binary.buildTask } } } } } task run(type: JavaExec) { classpath = sourceSets.dev.runtimeClasspath main = 'edu.wpi.first.wpilibj.DevMain' } test.dependsOn nativeTestFilesJar run.dependsOn nativeTestFilesJar def versionClass = """ package edu.wpi.first.wpilibj.util; /* * Autogenerated file! Do not manually edit this file. This version is regenerated * any time the publish task is run, or when this file is deleted. */ public final class WPILibVersion { public static final String Version = "${WPILibVersion.version}"; } """.trim() def wpilibVersionFile = file('src/main/java/edu/wpi/first/wpilibj/util/WPILibVersion.java') def willPublish = false gradle.taskGraph.addTaskExecutionGraphListener { graph -> willPublish = graph.hasTask(publish) } task generateJavaVersion() { description = 'Generates the wpilib version class.' group = 'WPILib' // We follow a simple set of checks to determine whether we should generate a new version file: // 1. If the release type is not development, we generate a new verison file // 2. If there is no generated version number, we generate a new version file // 3. If there is a generated build number, and the release type is development, then we will // only generate if the publish task is run. doLast { if (!WPILibVersion.releaseType.toString().equalsIgnoreCase('official') && !willPublish && wpilibVersionFile.exists()) { return } println "Writing version ${WPILibVersion.version} to $wpilibVersionFile" if (wpilibVersionFile.exists()) { wpilibVersionFile.delete() } wpilibVersionFile.write(versionClass) } } clean { delete wpilibVersionFile } compileJava.dependsOn generateJavaVersion pmd { sourceSets = [sourceSets.main] consoleOutput = true reportsDir = file("$project.buildDir/reports/pmd") ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml")) ruleSets = [] } dependencies { compile 'edu.wpi.first.wpiutil:wpiutil-java:3.+' compile 'edu.wpi.first.ntcore:ntcore-java:4.+' compile 'org.opencv:opencv-java:3.2.0' compile 'edu.wpi.first.cscore:cscore-java:1.+' testCompile 'org.hamcrest:hamcrest-all:1.3' testCompile 'junit:junit:4.12' testCompile 'com.google.guava:guava:19.0' testRuntime files(project.nativeTestFilesJar.archivePath) testRuntime 'edu.wpi.first.ntcore:ntcore-jni:4.+:all' testRuntime 'org.opencv:opencv-jni:3.2.0:all' testRuntime 'edu.wpi.first.cscore:cscore-jni:1.+:all' devCompile 'edu.wpi.first.wpiutil:wpiutil-java:3.+' devCompile 'edu.wpi.first.ntcore:ntcore-java:4.+' devCompile 'org.opencv:opencv-java:3.2.0' devCompile 'edu.wpi.first.cscore:cscore-java:1.+' devCompile sourceSets.main.output devRuntime files(project.nativeTestFilesJar.archivePath) devRuntime 'edu.wpi.first.ntcore:ntcore-jni:4.+:all' devRuntime 'org.opencv:opencv-jni:3.2.0:all' devRuntime 'edu.wpi.first.cscore:cscore-jni:1.+:all' } def jniClasses = [ 'edu.wpi.first.wpilibj.can.CANJNI', 'edu.wpi.first.wpilibj.hal.FRCNetComm', 'edu.wpi.first.wpilibj.hal.HAL', 'edu.wpi.first.wpilibj.hal.HALUtil', 'edu.wpi.first.wpilibj.hal.JNIWrapper', 'edu.wpi.first.wpilibj.hal.AccelerometerJNI', 'edu.wpi.first.wpilibj.hal.AnalogJNI', 'edu.wpi.first.wpilibj.hal.AnalogGyroJNI', 'edu.wpi.first.wpilibj.hal.ConstantsJNI', 'edu.wpi.first.wpilibj.hal.CounterJNI', 'edu.wpi.first.wpilibj.hal.DigitalGlitchFilterJNI', 'edu.wpi.first.wpilibj.hal.DIOJNI', 'edu.wpi.first.wpilibj.hal.EncoderJNI', 'edu.wpi.first.wpilibj.hal.I2CJNI', 'edu.wpi.first.wpilibj.hal.InterruptJNI', 'edu.wpi.first.wpilibj.hal.NotifierJNI', 'edu.wpi.first.wpilibj.hal.PortsJNI', 'edu.wpi.first.wpilibj.hal.PWMJNI', 'edu.wpi.first.wpilibj.hal.RelayJNI', 'edu.wpi.first.wpilibj.hal.SPIJNI', 'edu.wpi.first.wpilibj.hal.SolenoidJNI', 'edu.wpi.first.wpilibj.hal.CompressorJNI', 'edu.wpi.first.wpilibj.hal.PDPJNI', 'edu.wpi.first.wpilibj.hal.PowerJNI', 'edu.wpi.first.wpilibj.hal.SerialPortJNI', 'edu.wpi.first.wpilibj.hal.OSSerialPortJNI', 'edu.wpi.first.wpilibj.hal.ThreadsJNI', ] model { jniConfigs { wpilibJNIShared(JNIConfig) { jniDefinitionClasses = jniClasses jniArmHeaderLocations = [ all: file("${projectDir}/src/arm-linux-jni") ] sourceSets = [ project.sourceSets.main ] } wpilibJNIStatic(JNIConfig) { jniDefinitionClasses = jniClasses jniArmHeaderLocations = [ all: file("${projectDir}/src/arm-linux-jni") ] sourceSets = [ project.sourceSets.main ] } } exportsConfigs { wpilibJNIShared(ExportsConfig) { x86SymbolFilter = { symbols-> def retList = [] symbols.each { symbol-> if (symbol.startsWith('Java_') || symbol.startsWith('JNI_')) { retList << symbol } } return retList } x64SymbolFilter = { symbols-> def retList = [] symbols.each { symbol-> if (symbol.startsWith('Java_') || symbol.startsWith('JNI_')) { retList << symbol } } return retList } } wpilibJNIStatic(ExportsConfig) { x86SymbolFilter = { symbols-> def retList = [] symbols.each { symbol-> if (symbol.startsWith('Java_') || symbol.startsWith('JNI_')) { retList << symbol } } return retList } x64SymbolFilter = { symbols-> def retList = [] symbols.each { symbol-> if (symbol.startsWith('Java_') || symbol.startsWith('JNI_')) { retList << symbol } } return retList } } } dependencyConfigs { wpiutil(DependencyConfig) { groupId = 'edu.wpi.first.wpiutil' artifactId = 'wpiutil-cpp' headerClassifier = 'headers' ext = 'zip' version = '3.+' sharedConfigs = [ wpilibJNIShared: [] ] staticConfigs = [ wpilibJNIStatic: [] ] } } components { wpilibJNIStatic(NativeLibrarySpec) { baseName = 'wpilibJNI' binaries.withType(NativeBinarySpec) { binary -> if (binary.targetPlatform.architecture.name == 'athena') { binary.lib project: ':hal', library: 'halAthena', linkage: 'static' } else { binary.lib project: ':hal', library: 'halSim', linkage: 'static' } } sources { cpp { source { srcDirs = ['src/main/native/cpp'] includes = ['**/*.cpp'] } } } } wpilibJNIShared(NativeLibrarySpec) { baseName = 'wpilibJNI' binaries.withType(NativeBinarySpec) { binary -> if (binary.targetPlatform.architecture.name == 'athena') { binary.lib project: ':hal', library: 'halAthena', linkage: 'shared' } else { binary.lib project: ':hal', library: 'halSim', linkage: 'shared' } } sources { cpp { source { srcDirs = ['src/main/native/cpp'] includes = ['**/*.cpp'] } } } } } binaries { withType(NativeBinarySpec) { project(':hal').addHalCompilerArguments(it) project(':ni-libraries').addNiLibrariesToLinker(it) } withType(StaticLibraryBinarySpec) { it.buildable = false } } tasks { getHeaders(Task) { def list = [] $.components.each { if (it in NativeLibrarySpec && it.name == 'wpilibJNIStatic') { it.sources.each { it.exportedHeaders.srcDirs.each { list.add(it) } } it.binaries.each { it.libs.each { it.includeRoots.each { list.add(it) } } } } } // use file to normalize this dir list.add(file("$buildDir/wpilibJNIStatic/jniinclude")) list = list.unique(false) doLast { list.each { print "WPIHEADER: " println it } } } } } apply from: 'publish.gradle' apply from: 'integrationTestingFiles.gradle' test { testLogging { events "failed" exceptionFormat "full" } } if (project.hasProperty('onlyAthena')) { test.enabled = false }