Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | import edu.wpi.first.toolchain.NativePlatforms |
| 2 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 3 | apply plugin: 'java' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 4 | apply plugin: 'jacoco' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 5 | |
| 6 | ext { |
| 7 | useJava = true |
| 8 | useCpp = false |
| 9 | skipDev = true |
| 10 | } |
| 11 | |
| 12 | apply from: "${rootDir}/shared/opencv.gradle" |
| 13 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 14 | dependencies { |
| 15 | implementation project(':wpilibj') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 16 | implementation project(':apriltag') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 17 | implementation project(':wpimath') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 18 | implementation project(':hal') |
| 19 | implementation project(':wpiutil') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 20 | implementation project(':wpinet') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 21 | implementation project(':ntcore') |
| 22 | implementation project(':cscore') |
| 23 | implementation project(':cameraserver') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 24 | implementation project(':wpilibNewCommands') |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 25 | implementation project(':romiVendordep') |
| 26 | implementation project(':xrpVendordep') |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 27 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 28 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0' |
| 29 | testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0' |
| 30 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 31 | } |
| 32 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 33 | jacoco { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 34 | toolVersion = "0.8.10" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | jacocoTestReport { |
| 38 | reports { |
| 39 | xml.required = true |
| 40 | html.required = true |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if (!project.hasProperty('skipJavaFormat')) { |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 45 | apply plugin: 'pmd' |
| 46 | |
| 47 | pmd { |
| 48 | consoleOutput = true |
| 49 | reportsDir = file("$project.buildDir/reports/pmd") |
| 50 | ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml")) |
| 51 | ruleSets = [] |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | gradle.projectsEvaluated { |
| 56 | tasks.withType(JavaCompile) { |
| 57 | options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Werror" |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | tasks.register('buildDesktopJava') { |
| 62 | it.dependsOn tasks.withType(JavaCompile) |
| 63 | } |
| 64 | |
| 65 | apply from: 'publish.gradle' |
| 66 | |
| 67 | ext { |
| 68 | templateDirectory = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/templates/") |
| 69 | templateFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/templates/templates.json") |
| 70 | exampleDirectory = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/examples/") |
| 71 | exampleFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/examples/examples.json") |
| 72 | commandDirectory = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/commands/") |
| 73 | commandFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/commands/commands.json") |
| 74 | } |
| 75 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 76 | apply plugin: 'cpp' |
| 77 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 78 | |
| 79 | apply from: '../shared/config.gradle' |
| 80 | |
| 81 | |
| 82 | model { |
| 83 | components { |
| 84 | wpilibjExamplesDev(NativeExecutableSpec) { |
| 85 | targetBuildTypes 'debug' |
| 86 | sources { |
| 87 | cpp { |
| 88 | source { |
| 89 | srcDirs 'src/dev/native/cpp' |
| 90 | include '**/*.cpp' |
| 91 | } |
| 92 | exportedHeaders { |
| 93 | srcDirs 'src/dev/native/include' |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | binaries.all { binary -> |
| 98 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 99 | lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared' |
| 100 | lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 101 | lib project: ':apriltag', library: 'apriltag', linkage: 'shared' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 102 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 103 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 104 | lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared' |
| 105 | project(':ntcore').addNtcoreDependency(binary, 'shared') |
| 106 | project(':ntcore').addNtcoreJniDependency(binary) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 107 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 108 | lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared' |
| 109 | project(':hal').addHalDependency(binary, 'shared') |
| 110 | project(':hal').addHalJniDependency(binary) |
| 111 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 112 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
| 113 | lib project: ':wpinet', library: 'wpinet', linkage: 'shared' |
| 114 | lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 115 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 116 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 117 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
| 118 | } else { |
| 119 | def systemArch = getCurrentArch() |
| 120 | if (binary.targetPlatform.name == systemArch) { |
| 121 | lib project: ":simulation:halsim_gui", library: 'halsim_gui', linkage: 'shared' |
| 122 | } |
| 123 | } |
| 124 | nativeUtils.useRequiredLibrary(binary, 'opencv_shared') |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | tasks { |
| 129 | def c = $.components |
| 130 | def found = false |
| 131 | c.each { |
| 132 | if (it in NativeExecutableSpec && it.name == "wpilibjExamplesDev") { |
| 133 | it.binaries.each { |
| 134 | if (!found) { |
| 135 | def arch = it.targetPlatform.name |
| 136 | if (arch == NativePlatforms.desktop) { |
| 137 | found = true |
| 138 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 139 | |
| 140 | def doFirstTask = { task -> |
| 141 | def extensions = '' |
| 142 | it.tasks.install.installDirectory.get().getAsFile().eachFileRecurse { |
| 143 | def name = it.name |
| 144 | if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) { |
| 145 | return |
| 146 | } |
| 147 | def file = it |
| 148 | if (name.startsWith("halsim_gui") || name.startsWith("libhalsim_gui".toString())) { |
| 149 | extensions += file.absolutePath + File.pathSeparator |
| 150 | } |
| 151 | } |
| 152 | if (extensions != '') { |
| 153 | task.environment 'HALSIM_EXTENSIONS', extensions |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | project.tasks.create("runCpp", Exec) { task -> |
| 158 | dependsOn it.tasks.install |
| 159 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 160 | test.dependsOn it.tasks.install |
| 161 | test.systemProperty 'java.library.path', filePath |
| 162 | test.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 163 | test.environment 'DYLD_LIBRARY_PATH', filePath |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 164 | test.workingDir filePath |
| 165 | } |
| 166 | |
| 167 | new groovy.json.JsonSlurper().parseText(exampleFile.text).each { entry -> |
| 168 | project.tasks.create("run${entry.foldername}", JavaExec) { run -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 169 | run.group "run examples" |
| 170 | run.mainClass = "edu.wpi.first.wpilibj.examples." + entry.foldername + "." + entry.mainclass |
| 171 | run.classpath = sourceSets.main.runtimeClasspath |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 172 | run.dependsOn it.tasks.install |
| 173 | run.systemProperty 'java.library.path', filePath |
| 174 | run.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 175 | run.environment 'DYLD_LIBRARY_PATH', filePath |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 176 | run.workingDir filePath |
| 177 | doFirst { doFirstTask(run) } |
| 178 | |
| 179 | if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) { |
| 180 | run.jvmArgs = ['-XstartOnFirstThread'] |
| 181 | } |
| 182 | } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 183 | project.tasks.create("test${entry.foldername}", Test) { testTask -> |
| 184 | testTask.group "verification" |
| 185 | testTask.useJUnitPlatform() |
| 186 | testTask.filter { |
| 187 | includeTestsMatching("edu.wpi.first.wpilibj.examples.${entry.foldername}.*") |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 188 | // armsimulation regularly fails on CI Win64Debug |
| 189 | if (project.hasProperty('ciDebugOnly')) { |
| 190 | excludeTestsMatching("edu.wpi.first.wpilibj.examples.armsimulation.*") |
| 191 | } |
| 192 | setFailOnNoMatchingTests(false) |
| 193 | } |
| 194 | test.filter { |
| 195 | excludeTestsMatching("edu.wpi.first.wpilibj.examples.${entry.foldername}.*") |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 196 | setFailOnNoMatchingTests(false) |
| 197 | } |
| 198 | testTask.classpath = sourceSets.test.runtimeClasspath |
| 199 | testTask.dependsOn it.tasks.install |
| 200 | |
| 201 | testTask.systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true' |
| 202 | testTask.testLogging { |
| 203 | events "failed" |
| 204 | exceptionFormat "full" |
| 205 | } |
| 206 | testTask.systemProperty 'java.library.path', filePath |
| 207 | testTask.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 208 | testTask.environment 'DYLD_LIBRARY_PATH', filePath |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 209 | testTask.workingDir filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 210 | |
| 211 | if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64') || project.hasProperty('onlywindowsarm64')) { |
| 212 | testTask.enabled = false |
| 213 | } |
| 214 | test.dependsOn(testTask) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 215 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | found = true |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 227 | ext { |
| 228 | isCppCommands = false |
| 229 | } |
| 230 | apply from: "${rootDir}/shared/examplecheck.gradle" |