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