blob: 7d74e80ab0e4a73dc2c94f12e4ec423ca9c3e828 [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
Austin Schuh812d0d12021-11-04 20:16:48 -070024if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxraspbian') || project.hasProperty('onlylinuxaarch64bionic')) {
25 test.enabled = false
26}
Brian Silverman8fce7482020-01-05 13:18:21 -080027
28dependencies {
29 implementation project(':wpilibj')
30
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')
34 implementation project(':ntcore')
35 implementation project(':cscore')
36 implementation project(':cameraserver')
37 implementation project(':wpilibOldCommands')
38 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 {
Austin Schuh75263e32022-02-22 18:05:32 -080046 toolVersion = "0.8.7"
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'
111 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
112 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
113 lib project: ':wpimath', library: 'wpimathJNI', linkage: 'shared'
114 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
115 lib project: ':cscore', library: 'cscore', linkage: 'shared'
116 lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared'
117 lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
118 project(':hal').addHalDependency(binary, 'shared')
119 project(':hal').addHalJniDependency(binary)
120 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
121 lib project: ':wpiutil', library: 'wpiutilJNI', linkage: 'shared'
122 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
123 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
124 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
125 } else {
126 def systemArch = getCurrentArch()
127 if (binary.targetPlatform.name == systemArch) {
128 lib project: ":simulation:halsim_gui", library: 'halsim_gui', linkage: 'shared'
129 }
130 }
131 nativeUtils.useRequiredLibrary(binary, 'opencv_shared')
132 }
133 }
134 }
135 tasks {
136 def c = $.components
137 def found = false
138 c.each {
139 if (it in NativeExecutableSpec && it.name == "wpilibjExamplesDev") {
140 it.binaries.each {
141 if (!found) {
142 def arch = it.targetPlatform.name
143 if (arch == NativePlatforms.desktop) {
144 found = true
145 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
146
147 def doFirstTask = { task ->
148 def extensions = ''
149 it.tasks.install.installDirectory.get().getAsFile().eachFileRecurse {
150 def name = it.name
151 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) {
152 return
153 }
154 def file = it
155 if (name.startsWith("halsim_gui") || name.startsWith("libhalsim_gui".toString())) {
156 extensions += file.absolutePath + File.pathSeparator
157 }
158 }
159 if (extensions != '') {
160 task.environment 'HALSIM_EXTENSIONS', extensions
161 }
162 }
163
164 project.tasks.create("runCpp", Exec) { task ->
165 dependsOn it.tasks.install
166 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
167 test.dependsOn it.tasks.install
168 test.systemProperty 'java.library.path', filePath
169 test.environment 'LD_LIBRARY_PATH', filePath
170 test.workingDir filePath
171 }
172
173 new groovy.json.JsonSlurper().parseText(exampleFile.text).each { entry ->
174 project.tasks.create("run${entry.foldername}", JavaExec) { run ->
175 mainClass = "edu.wpi.first.wpilibj.examples." + entry.foldername + ".Main"
176 classpath = sourceSets.main.runtimeClasspath
177 run.dependsOn it.tasks.install
178 run.systemProperty 'java.library.path', filePath
179 run.environment 'LD_LIBRARY_PATH', filePath
180 run.workingDir filePath
181 doFirst { doFirstTask(run) }
182
183 if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
184 run.jvmArgs = ['-XstartOnFirstThread']
185 }
186 }
187 }
188
189 found = true
190 }
191 }
192 }
193 }
194 }
195 }
196}
197
Brian Silverman8fce7482020-01-05 13:18:21 -0800198ext {
199 isCppCommands = false
200}
201apply from: "${rootDir}/shared/examplecheck.gradle"