blob: deb8af104b2dee9b5975b98e467553eeab40fa5c [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001import edu.wpi.first.toolchain.NativePlatforms
2
Brian Silverman8fce7482020-01-05 13:18:21 -08003apply plugin: 'java'
Austin Schuh812d0d12021-11-04 20:16:48 -07004apply plugin: 'jacoco'
Brian Silverman8fce7482020-01-05 13:18:21 -08005
6ext {
7 useJava = true
8 useCpp = false
9 skipDev = true
10}
11
12apply from: "${rootDir}/shared/opencv.gradle"
13
Austin Schuh812d0d12021-11-04 20:16:48 -070014test {
15 useJUnitPlatform()
16 systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
17 testLogging {
18 events "failed"
19 exceptionFormat "full"
20 }
21 finalizedBy jacocoTestReport
22}
Brian Silverman8fce7482020-01-05 13:18:21 -080023
James Kuszmaulcf324122023-01-14 14:07:17 -080024if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64')) {
Austin Schuh812d0d12021-11-04 20:16:48 -070025 test.enabled = false
26}
Brian Silverman8fce7482020-01-05 13:18:21 -080027
28dependencies {
29 implementation project(':wpilibj')
James Kuszmaulcf324122023-01-14 14:07:17 -080030 implementation project(':apriltag')
Austin Schuh1e69f942020-11-14 15:06:14 -080031 implementation project(':wpimath')
Brian Silverman8fce7482020-01-05 13:18:21 -080032 implementation project(':hal')
33 implementation project(':wpiutil')
James Kuszmaulcf324122023-01-14 14:07:17 -080034 implementation project(':wpinet')
Brian Silverman8fce7482020-01-05 13:18:21 -080035 implementation project(':ntcore')
36 implementation project(':cscore')
37 implementation project(':cameraserver')
Brian Silverman8fce7482020-01-05 13:18:21 -080038 implementation project(':wpilibNewCommands')
Austin Schuh812d0d12021-11-04 20:16:48 -070039
Austin Schuh75263e32022-02-22 18:05:32 -080040 testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
41 testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
42 testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
Brian Silverman8fce7482020-01-05 13:18:21 -080043}
44
Austin Schuh812d0d12021-11-04 20:16:48 -070045jacoco {
James Kuszmaulcf324122023-01-14 14:07:17 -080046 toolVersion = "0.8.8"
Austin Schuh812d0d12021-11-04 20:16:48 -070047}
48
49jacocoTestReport {
50 reports {
51 xml.required = true
52 html.required = true
53 }
54}
55
56if (!project.hasProperty('skipJavaFormat')) {
Brian Silverman8fce7482020-01-05 13:18:21 -080057 apply plugin: 'pmd'
58
59 pmd {
60 consoleOutput = true
61 reportsDir = file("$project.buildDir/reports/pmd")
62 ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml"))
63 ruleSets = []
64 }
65}
66
67gradle.projectsEvaluated {
68 tasks.withType(JavaCompile) {
69 options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Werror"
70 }
71}
72
73tasks.register('buildDesktopJava') {
74 it.dependsOn tasks.withType(JavaCompile)
75}
76
77apply from: 'publish.gradle'
78
79ext {
80 templateDirectory = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/templates/")
81 templateFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/templates/templates.json")
82 exampleDirectory = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/examples/")
83 exampleFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/examples/examples.json")
84 commandDirectory = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/commands/")
85 commandFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/commands/commands.json")
86}
87
Austin Schuh812d0d12021-11-04 20:16:48 -070088apply plugin: 'cpp'
89apply plugin: 'edu.wpi.first.NativeUtils'
90
91apply from: '../shared/config.gradle'
92
93
94model {
95 components {
96 wpilibjExamplesDev(NativeExecutableSpec) {
97 targetBuildTypes 'debug'
98 sources {
99 cpp {
100 source {
101 srcDirs 'src/dev/native/cpp'
102 include '**/*.cpp'
103 }
104 exportedHeaders {
105 srcDirs 'src/dev/native/include'
106 }
107 }
108 }
109 binaries.all { binary ->
110 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800111 lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700112 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
113 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800114 lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared'
115 project(':ntcore').addNtcoreDependency(binary, 'shared')
116 project(':ntcore').addNtcoreJniDependency(binary)
Austin Schuh812d0d12021-11-04 20:16:48 -0700117 lib project: ':cscore', library: 'cscore', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700118 lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
119 project(':hal').addHalDependency(binary, 'shared')
120 project(':hal').addHalJniDependency(binary)
121 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800122 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
123 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
124 lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700125 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
126 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
127 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
128 } else {
129 def systemArch = getCurrentArch()
130 if (binary.targetPlatform.name == systemArch) {
131 lib project: ":simulation:halsim_gui", library: 'halsim_gui', linkage: 'shared'
132 }
133 }
134 nativeUtils.useRequiredLibrary(binary, 'opencv_shared')
135 }
136 }
137 }
138 tasks {
139 def c = $.components
140 def found = false
141 c.each {
142 if (it in NativeExecutableSpec && it.name == "wpilibjExamplesDev") {
143 it.binaries.each {
144 if (!found) {
145 def arch = it.targetPlatform.name
146 if (arch == NativePlatforms.desktop) {
147 found = true
148 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
149
150 def doFirstTask = { task ->
151 def extensions = ''
152 it.tasks.install.installDirectory.get().getAsFile().eachFileRecurse {
153 def name = it.name
154 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) {
155 return
156 }
157 def file = it
158 if (name.startsWith("halsim_gui") || name.startsWith("libhalsim_gui".toString())) {
159 extensions += file.absolutePath + File.pathSeparator
160 }
161 }
162 if (extensions != '') {
163 task.environment 'HALSIM_EXTENSIONS', extensions
164 }
165 }
166
167 project.tasks.create("runCpp", Exec) { task ->
168 dependsOn it.tasks.install
169 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
170 test.dependsOn it.tasks.install
171 test.systemProperty 'java.library.path', filePath
172 test.environment 'LD_LIBRARY_PATH', filePath
173 test.workingDir filePath
174 }
175
176 new groovy.json.JsonSlurper().parseText(exampleFile.text).each { entry ->
177 project.tasks.create("run${entry.foldername}", JavaExec) { run ->
James Kuszmaulcf324122023-01-14 14:07:17 -0800178 run.group "run examples"
179 run.mainClass = "edu.wpi.first.wpilibj.examples." + entry.foldername + "." + entry.mainclass
180 run.classpath = sourceSets.main.runtimeClasspath
Austin Schuh812d0d12021-11-04 20:16:48 -0700181 run.dependsOn it.tasks.install
182 run.systemProperty 'java.library.path', filePath
183 run.environment 'LD_LIBRARY_PATH', filePath
184 run.workingDir filePath
185 doFirst { doFirstTask(run) }
186
187 if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
188 run.jvmArgs = ['-XstartOnFirstThread']
189 }
190 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800191 project.tasks.create("test${entry.foldername}", Test) { testTask ->
192 testTask.group "verification"
193 testTask.useJUnitPlatform()
194 testTask.filter {
195 includeTestsMatching("edu.wpi.first.wpilibj.examples.${entry.foldername}.*")
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
208 testTask.workingDir filePath
209 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700210 }
211
212 found = true
213 }
214 }
215 }
216 }
217 }
218 }
219}
220
Brian Silverman8fce7482020-01-05 13:18:21 -0800221ext {
222 isCppCommands = false
223}
224apply from: "${rootDir}/shared/examplecheck.gradle"