Brian Silverman | 890a32a | 2018-03-11 15:41:56 -0700 | [diff] [blame^] | 1 | import org.gradle.internal.os.OperatingSystem |
| 2 | |
| 3 | apply plugin: 'java' |
| 4 | apply plugin: 'net.ltgt.errorprone' |
| 5 | |
| 6 | repositories { |
| 7 | mavenCentral() |
| 8 | } |
| 9 | |
| 10 | configurations.errorprone { |
| 11 | resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9' |
| 12 | } |
| 13 | |
| 14 | def generatedJNIHeaderLoc = "${buildDir}/include" |
| 15 | |
| 16 | sourceSets { |
| 17 | user { |
| 18 | java { |
| 19 | srcDirs = [userJavaSrc] |
| 20 | } |
| 21 | } |
| 22 | main { |
| 23 | java { |
| 24 | srcDirs = [javaSrc] |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | dependencies { |
| 30 | compile sourceSets.user.output |
| 31 | runtime sourceSets.user.output |
| 32 | compile wpilibjDep |
| 33 | runtime wpilibjDep |
| 34 | compile javaNetTablesDep |
| 35 | runtime javaNetTablesDep |
| 36 | compile fileTree(dir: javaLibraryLoc, include: ['*.jar']) |
| 37 | runtime fileTree(dir: javaLibraryLoc, include: ['*.jar']) |
| 38 | } |
| 39 | |
| 40 | jar { |
| 41 | description = 'Generates jar' |
| 42 | baseName = libraryName |
| 43 | duplicatesStrategy = 'exclude' |
| 44 | |
| 45 | dependsOn { classes } |
| 46 | |
| 47 | if (embedJavaLibraries) { |
| 48 | def tree = fileTree(dir: javaLibraryLoc, include: ['*.jar']) |
| 49 | tree.each { |
| 50 | from zipTree(it.path) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (embedJavaLibraries) { |
| 55 | from sourceSets.user.output |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Generates the JNI headers |
| 61 | */ |
| 62 | task jniHeaders { |
| 63 | description = 'Generates JNI headers' |
| 64 | group = 'WPILib' |
| 65 | def outputFolder = file(generatedJNIHeaderLoc) |
| 66 | inputs.files sourceSets.main.output |
| 67 | outputs.file outputFolder |
| 68 | doLast { |
| 69 | outputFolder.mkdirs() |
| 70 | exec { |
| 71 | ignoreExitValue = true |
| 72 | executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah') |
| 73 | args '-d', outputFolder |
| 74 | args '-classpath', sourceSets.main.runtimeClasspath.asPath |
| 75 | args jniDefinitions |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | ext.getNativeJNISymbols = { |
| 81 | def symbolsList = [] |
| 82 | |
| 83 | jniHeaders.outputs.files.each { |
| 84 | FileTree tree = fileTree(dir: it) |
| 85 | tree.each { File file -> |
| 86 | file.eachLine { line -> |
| 87 | if (line.trim()) { |
| 88 | if (line.startsWith("JNIEXPORT ") && line.contains('JNICALL')) { |
| 89 | def (p1, p2) = line.split('JNICALL').collect { it.trim() } |
| 90 | // p2 is our JNI call |
| 91 | symbolsList << p2 |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return symbolsList |
| 99 | } |
| 100 | |
| 101 | clean { |
| 102 | delete generatedJNIHeaderLoc |
| 103 | } |
| 104 | |
| 105 | compileJava { |
| 106 | options.compilerArgs << '-Xlint:unchecked' << "-Werror" |
| 107 | } |
| 108 | |
| 109 | javadoc { |
| 110 | options.addStringOption('Xdoclint:none', '-quiet') |
| 111 | } |
| 112 | |
| 113 | // This creates a lambda that the main build.gradle can access, which sets up the JNI includes for the |
| 114 | // target build platform. This lambda is exposed as a property in the main build.gradle. |
| 115 | ext.setupJniIncludes = { binaries -> |
| 116 | def platformSpecificIncludeFlag = { loc, cppCompiler -> |
| 117 | if (OperatingSystem.current().isWindows()) { |
| 118 | cppCompiler.args "/I$loc" |
| 119 | } else { |
| 120 | cppCompiler.args '-I', loc |
| 121 | } |
| 122 | } |
| 123 | binaries.all { |
| 124 | tasks.withType(CppCompile) { |
| 125 | cppCompiler.args '-I', file("${rootDir}/java/arm-linux").absolutePath |
| 126 | cppCompiler.args '-I', file("${rootDir}/java/arm-linux/linux").absolutePath |
| 127 | |
| 128 | jniHeaders.outputs.files.each { file -> |
| 129 | cppCompiler.args '-I', file.getPath() |
| 130 | } |
| 131 | |
| 132 | dependsOn jniHeaders |
| 133 | } |
| 134 | } |
| 135 | } |