-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
485 lines (420 loc) · 14.9 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
import org.apache.tools.ant.taskdefs.condition.Os
import java.nio.file.Files
plugins {
id 'base'
id 'java-library'
// Build Scans
id 'com.gradle.build-scan' version '2.0.2'
// For JNI
id 'cpp'
id 'edu.wpi.first.GradleVsCode' version '0.12.0'
id 'edu.wpi.first.GradleJni' version '0.10.1'
id 'edu.wpi.first.GradleRIO' version '2019.3.2'
// Task Tree
id 'com.dorongold.task-tree' version '1.3.1'
// Code coverage
id 'jacoco'
// Checkstyle
id 'checkstyle'
}
// Configure properties
// Archives directory
if(!project.hasProperty('archiveDir')) {
project.ext.archiveDir = 'archives'
}
// Operating System family
if(!project.hasProperty('os')) {
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
project.ext.os = 'windows'
}
else if(Os.isFamily(Os.FAMILY_UNIX)) {
project.ext.os = 'unix'
}
else {
throw new GradleException("Unrecognized OS family")
}
}
else {
// Verify property is set to a valid value
if(os != 'windows' && os != 'unix') {
throw new GradleException("Unrecognized OS family: $os")
}
}
// Architecture
if(!project.hasProperty('arch')) {
if(System.getProperty('os.arch') == 'amd64' || System.getProperty('os.arch') == 'x86_64') {
project.ext.arch = 'amd64'
}
else {
throw new GradleException("Unrecognized architecture: " + System.getProperty('os.arch'))
}
}
else {
if(arch == 'x86_64') {
arch = 'amd64'
}
else if(arch != 'amd64') {
throw new GradleException("Unrecognized architecture: $arch")
}
}
// Build type
if(!project.hasProperty('type')) {
project.ext.type = 'release'
}
else {
if(type != 'debug' && type != 'release') {
throw new GradleException("Invalid build type: $type")
}
}
// Whether or not to skip tests
if(!project.hasProperty('skiptests')) {
project.ext.skiptests = 'false'
}
else {
if(skiptests != 'true' && skiptests != 'false') {
throw new GradleException("Invalid boolean value: $skiptests")
}
}
println "----- Build Configuration -----"
println "Archives Directory: $archiveDir"
println "OS Family: $os"
println "Computer Architecture: $arch"
println "Build Type: $type"
println "Skip Testing: $skiptests"
compileJava {
// Show deprecation warnings
options.compilerArgs << '-Xlint:deprecation'
}
compileTestJava {
// Show deprecation warnings
options.compilerArgs << '-Xlint:deprecation'
}
// Use Gradle 5.0 as GradleRIO only supports 5.0
wrapper {
gradleVersion = 5.0
}
// Build scans
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
// Needed to fix Javadoc search
// See comments below
final JAVADOC_FIX_SEARCH_STR = '\n\n' +
'/***********************************************************************\n' +
' * THE BELOW SNIPPET WAS APPENDED BY THE ROBOTPATHFINDER BUILD PROCESS *\n' +
' * This fixes the broken search functionality due to not having *\n' +
' * modules without breaking external links *\n' +
' ***********************************************************************/\n' +
'getURLPrefix = function(ui) {\n' +
' return \'\';\n' +
'};\n'
tasks.withType(Javadoc) {
// Link to external docs for all the builtin classes
options.with {
links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
}
// Only generate docs for public methods, fields and types
options.addBooleanOption('public', true)
doLast {
// Since the introduction of modules in Java 9, the Javadoc search functionality would break if the
// project was not using modules. Although --no-module-directories fixes this, it breaks external
// links in the process. Therefore, we append a short snippet of code to the end of the JavaScript
// to fix it.
def searchScript = new File(destinationDir.getAbsolutePath() + '/search.js')
searchScript.append JAVADOC_FIX_SEARCH_STR
}
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
project.version = '3.0.0-alpha.1.1-dev'
// Setup for Gradle-JNI
// Thanks to @ThadHouse
model {
components {
JniLibrary(JniNativeLibrarySpec) {
// Target both desktop (for development) and roboRIO
targetPlatform wpi.platforms.desktop
targetPlatform wpi.platforms.roborio
javaCompileTasks << compileJava // set javaCompileTasks to any java compile tasks that contain your JNI classes. It is a list of tasks
jniCrossCompileOptions << JniCrossCompileOptions(wpi.platforms.roborio)
// Include C++ sources
sources.cpp {
source {
srcDir 'src/main/cpp'
include '**/*.cpp', '**/*.cc'
}
exportedHeaders {
srcDir 'src/main/cpp/include'
}
}
binaries.all {
// Don't build static libraries
if (it instanceof StaticLibraryBinarySpec) {
it.buildable = false
}
if (it.targetPlatform.name.contains(wpi.platforms.roborio)) {
useLibrary(it, 'wpilibjni')
} else {
useLibrary(it, 'wpilibjni_common')
}
}
}
}
}
// Configure Compiler options
def gccCompilerOptions = [ '-Wall', '-Wextra', '-ffast-math', '-fno-finite-math-only' ]
def msvcCompilerOptions = [ '/W3', '/fp:fast' ]
// Windows
if(os == 'windows') {
model {
binaries {
all {
// For roborio (gcc)
if (targetPlatform.name == wpi.platforms.roborio) {
cppCompiler.args.addAll gccCompilerOptions
}
// For desktop (MSVC)
else if (targetPlatform.name == wpi.platforms.desktop) {
cppCompiler.args.addAll msvcCompilerOptions
}
}
}
}
}
// UNIX - gcc
else {
model {
binaries {
all {
// For roborio and desktop (gcc)
if (targetPlatform.name == wpi.platforms.roborio
|| targetPlatform.name == wpi.platforms.desktop) {
cppCompiler.args.addAll gccCompilerOptions
}
}
}
}
}
// Disable XML and CSV code coverage reports
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
}
}
// Checkstyle config
checkstyle {
project.ext.checkstyleVersion = '8.20'
ignoreFailures = false
configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml")
}
// Include all Java source files in checkstyleMain
checkstyleMain {
source = sourceSets.main.allSource
}
// Disable XML reports and enable HTML reports for checkstyle
tasks.withType(Checkstyle) {
reports {
xml.enabled false
html.enabled true
}
}
dependencies {
// JMathPlot is needed for the graphing
implementation 'com.github.yannrichet:JMathPlot:1.0.1'
// Gson is needed for the Trajectory Visualizer's saving
implementation 'com.google.code.gson:gson:2.8.5'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:hamcrest:2.1'
// Checkstyle dependency
assert project.hasProperty("checkstyleVersion")
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
}
task updateJNIHeaders(type: Copy, group: 'Development', description: 'Copies JNI generated headers into the JNI headers directory.') {
dependsOn compileJava
String srcDir = 'build/jniinclude/compileJava/'
from srcDir
into 'src/main/cpp/include/jni'
// For each generated file, prepend "// clang-format off" to turn off clang-format for it
eachFile { details ->
File header = new File(srcDir + details.getSourcePath())
// Create temp file
File tmp = File.createTempFile("temp", ".tmp")
tmp.deleteOnExit()
// Write to temp file
tmp.withWriter { writer ->
// Comment to turn off formatter
writer.writeLine "// clang-format off"
// Write the rest of the file
header.eachLine { line ->
writer.writeLine line
}
}
// Copy temp file
header.withWriter { writer ->
tmp.eachLine { line ->
writer.writeLine line
}
writer.writeLine "// clang-format on"
}
}
}
task copyLibLinuxx8664Debug(type: Copy, group: 'Development', description: 'Copies the dynamic library for linux x86-64 debug to the root of the project.') {
dependsOn assemble
from 'build/libs/jniLibrary/shared/linuxx86-64/debug'
into '.'
rename { String fileName ->
fileName.replace('JniLibrary', 'RobotPathfinder')
}
}
task copyLibLinuxx8664Release(type: Copy, group: 'Development', description: 'Copies the dynamic library for linux x86-64 release to the root of the project.') {
dependsOn assemble
from 'build/libs/jniLibrary/shared/linuxx86-64/release'
into '.'
rename { String fileName ->
fileName.replace('JniLibrary', 'RobotPathfinder')
}
}
task copyLibWindowsx8664Debug(type: Exec, group: 'Development', description: 'Copies the dynamic library for windows x86-64 debug to the root of the project.') {
dependsOn assemble
commandLine 'cmd', '/c', '\"copy build\\libs\\jniLibrary\\shared\\windowsx86-64\\debug\\JniLibrary.dll RobotPathfinder.dll\"'
}
task copyLibWindowsx8664Release(type: Exec, group: 'Development', description: 'Copies the dynamic library for windows x86-64 release to the root of the project.') {
dependsOn assemble
commandLine 'cmd', '/c', '\"copy build\\libs\\jniLibrary\\shared\\windowsx86-64\\release\\JniLibrary.dll RobotPathfinder.dll\"'
}
task copyLibDebug(group: 'Development', description: 'Copies the correct debug dynamic library to the root of the project.') {
if(os == 'unix') {
dependsOn copyLibLinuxx8664Debug
}
else {
dependsOn copyLibWindowsx8664Debug
}
}
task copyLibRelease(group: 'Development', description: 'Copies the correct release dynamic library to the root of the project.') {
if(os == 'unix') {
dependsOn copyLibLinuxx8664Release
}
else {
dependsOn copyLibWindowsx8664Release
}
}
task copyLib(group: 'Development', description: 'Copies the correct dynamic library to the root of the project.') {
if(type == 'release') {
dependsOn copyLibRelease
}
else {
dependsOn copyLibDebug
}
}
test {
dependsOn copyLib
onlyIf {
skiptests == 'false'
}
}
// Add sources to the jar
jar {
from sourceSets.main.allSource
archiveName 'RobotPathfinder-' + project.version + '.jar'
}
def visualizerMainClass = 'com.arctos6135.robotpathfinder.tools.TrajectoryVisualizationTool'
// This task assembles the trajectory visualizer jar
// This jar is a fat jar
task visualizerJar(type: Jar, group: 'Build', description: 'Assembles a runnable jar that runs the visualizer.') {
dependsOn build
// Include outputs
from(sourceSets.main.output) {
include '**'
exclude '**/package-info.java'
}
// Add manifest attribute to make it runnable
manifest {
attributes 'Main-Class': visualizerMainClass
}
// Set archive name
archiveName 'Trajectory-Visualizer-' + project.version + '.jar'
// Include all dependencies in this jar
classifier = 'all'
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task fatJar(type: Jar, group: 'Build', description: 'Assembles a jar of the library, including the libraries for the Grapher class.') {
dependsOn build
archiveName 'RobotPathfinder-' + project.version + '-all.jar'
// Collect all
classifier = 'all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task markVisualizerJarExecutable(type: Exec, group: 'Archive', description: 'Sets the Trajectory Visualizer jar to be executable.') {
commandLine 'chmod', '+x', "$archiveDir/Trajectory-Visualizer-" + project.version + '.jar'
}
task copyJars(type: Copy, group: 'Archive', description: 'Copies all generated jars to the archives directory.') {
dependsOn jar
dependsOn fatJar
dependsOn visualizerJar
from 'build/libs/'
include '*.jar'
into "$archiveDir"
// If the OS is part of the UNIX family, also chmod the visualizer jar to be executable
if(os == 'unix') {
finalizedBy markVisualizerJarExecutable
}
}
task copyLibs(type: Copy, group: 'Archive', description: 'Copies all compiled dynamic libraries to the archives directory.') {
dependsOn assemble
from 'build/libs/jniLibrary/shared'
into "$archiveDir/libraries"
rename { String fileName ->
fileName.replace('JniLibrary', 'RobotPathfinder')
}
}
task testJavadoc(type: Javadoc, group: 'Documentation', description: 'Generates Javadoc for the test classes.') {
source = sourceSets.test.allJava
classpath = sourceSets.test.compileClasspath
// if not changed the destinationDir, the javadoc for production code is overridden.
destinationDir = file(buildDir.getPath() + '/docs/testJavadoc')
}
task completeJavadoc(type: Javadoc, group: 'Documentation', description: 'Generates Javadoc for both the main classes and the test classes.') {
source = sourceSets.test.allJava
classpath = sourceSets.test.compileClasspath
source += sourceSets.main.allJava;
classpath += sourceSets.main.compileClasspath
destinationDir = file(buildDir.getPath() + '/docs/completeJavadoc')
}
task zipDoc(type: Zip, group: 'Archive', description: 'Zips the generated Javadoc and puts it in the archives directory.') {
dependsOn javadoc
from 'build/docs/javadoc'
destinationDir file("$archiveDir")
archiveName 'RobotPathfinder-Doc-' + project.version + '.zip'
}
task zipTestLogs(type: Zip, group: 'Archive', description: 'Zips the test log from the last test and puts it in the build directory.') {
from 'build/testLogs'
destinationDir file('build')
archiveName 'test-logs.zip'
}
task allArchives(group: 'Archive', description: 'Builds the project, generates the Javadoc and jars, zips Javadoc and copies all items to the archives directory.') {
dependsOn jar
dependsOn visualizerJar
dependsOn fatJar
dependsOn copyJars
dependsOn zipDoc
dependsOn copyLibs
}
task cleanAll(type: Exec, group: 'Clean', description: 'Removes all compiled artifacts.') {
if(os == 'unix') {
commandLine 'rm', '-rf', 'bin', 'build', "$archiveDir", 'libRobotPathfinder.so'
}
else {
commandLine 'cmd', '/c', "\"del /s /q /f bin build $archiveDir RobotPathfinder.dll \
& rd /s /q bin & rd /s /q build & rd /s /q $archiveDir\""
}
}