blob: a513d261118e8026898e3651cfa23c3446f59f39 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001import edu.wpi.first.deployutils.deploy.target.RemoteTarget
2import edu.wpi.first.deployutils.deploy.target.location.SshDeployLocation
3import edu.wpi.first.deployutils.deploy.artifact.*
Austin Schuh1e69f942020-11-14 15:06:14 -08004import org.gradle.internal.os.OperatingSystem
Brian Silverman8fce7482020-01-05 13:18:21 -08005
6plugins {
7 id 'java'
8 id 'application'
9 id 'cpp'
10 id 'visual-studio'
11}
12
13apply plugin: 'edu.wpi.first.NativeUtils'
Austin Schuh812d0d12021-11-04 20:16:48 -070014apply plugin: 'edu.wpi.first.DeployUtils'
Brian Silverman8fce7482020-01-05 13:18:21 -080015
16apply from: '../shared/config.gradle'
17
Austin Schuh1e69f942020-11-14 15:06:14 -080018application {
19 if (OperatingSystem.current().isMacOsX()) {
20 applicationDefaultJvmArgs = ['-XstartOnFirstThread']
21 }
22}
23
Brian Silverman8fce7482020-01-05 13:18:21 -080024ext {
25 sharedCvConfigs = [myRobotCpp: []]
26 staticCvConfigs = [myRobotCppStatic: []]
27 useJava = true
28 useCpp = true
29 skipDev = true
30}
31
32apply from: "${rootDir}/shared/opencv.gradle"
33
James Kuszmaulb13e13f2023-11-22 20:44:04 -080034application {
35 mainClass = 'frc.robot.Main'
36}
Brian Silverman8fce7482020-01-05 13:18:21 -080037
38apply plugin: 'com.github.johnrengelman.shadow'
39
40repositories {
James Kuszmaulcf324122023-01-14 14:07:17 -080041 maven {
42 url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
43 }
Brian Silverman8fce7482020-01-05 13:18:21 -080044}
45
46dependencies {
47 implementation project(':wpilibj')
Austin Schuh1e69f942020-11-14 15:06:14 -080048 implementation project(':wpimath')
Brian Silverman8fce7482020-01-05 13:18:21 -080049 implementation project(':hal')
50 implementation project(':wpiutil')
James Kuszmaulcf324122023-01-14 14:07:17 -080051 implementation project(':wpinet')
Brian Silverman8fce7482020-01-05 13:18:21 -080052 implementation project(':ntcore')
53 implementation project(':cscore')
54 implementation project(':cameraserver')
Brian Silverman8fce7482020-01-05 13:18:21 -080055 implementation project(':wpilibNewCommands')
James Kuszmaulb13e13f2023-11-22 20:44:04 -080056 implementation project(':apriltag')
Brian Silverman8fce7482020-01-05 13:18:21 -080057}
58
James Kuszmaulcf324122023-01-14 14:07:17 -080059tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
60 onlyIf { false }
61}
62
Austin Schuh812d0d12021-11-04 20:16:48 -070063def simProjects = ['halsim_gui']
64
65deploy {
66 targets {
67 roborio(RemoteTarget) {
James Kuszmaulcf324122023-01-14 14:07:17 -080068 directory = '/home/lvuser'
Austin Schuh812d0d12021-11-04 20:16:48 -070069 maxChannels = 4
70 locations {
71 ssh(SshDeployLocation) {
72 address = "172.22.11.2"
73 user = 'admin'
74 password = ''
75 ipv6 = false
76 }
77 }
78
79 def remote = it
80
81 artifacts.registerFactory(WPIJREArtifact) {
82 return objects.newInstance(WPIJREArtifact, it, remote)
83 }
84
85 artifacts {
86 all {
87 predeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -080088 ctx.execute('. /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t 2> /dev/null')
89 ctx.execute("sed -i -e 's/\"exec /\"/' /usr/local/frc/bin/frcRunRobot.sh")
Austin Schuh812d0d12021-11-04 20:16:48 -070090 }
91 postdeploy << { ctx ->
92 ctx.execute("sync")
93 ctx.execute("ldconfig")
94 }
95 }
96
97 myRobotCpp(NativeExecutableArtifact) {
98 libraryDirectory = '/usr/local/frc/third-party/lib'
Austin Schuh75263e32022-02-22 18:05:32 -080099 def excludes = getLibraryFilter().getExcludes()
100 excludes.add('**/*.so.debug')
101 excludes.add('**/*.so.*.debug')
Austin Schuh812d0d12021-11-04 20:16:48 -0700102 postdeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -0800103 ctx.execute("echo '/home/lvuser/myRobotCpp' > /home/lvuser/robotCommand")
104 ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand")
105 ctx.execute("setcap cap_sys_nice+eip \"/home/lvuser/myRobotCpp\"")
Austin Schuh812d0d12021-11-04 20:16:48 -0700106 ctx.execute('chmod +x myRobotCpp')
107 }
108 }
109
110 myRobotCppStatic(NativeExecutableArtifact) {
111 libraryDirectory = '/usr/local/frc/third-party/lib'
112 postdeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -0800113 ctx.execute("echo '/home/lvuser/myRobotCppStatic' > /home/lvuser/robotCommand")
114 ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand")
115 ctx.execute("setcap cap_sys_nice+eip \"/home/lvuser/myRobotCppStatic\"")
Austin Schuh812d0d12021-11-04 20:16:48 -0700116 ctx.execute('chmod +x myRobotCppStatic')
117 }
118 }
119
James Kuszmaulcf324122023-01-14 14:07:17 -0800120 myRobotCppJava(NativeExecutableArtifact) {
121 libraryDirectory = '/usr/local/frc/third-party/lib'
122 def excludes = getLibraryFilter().getExcludes()
123 excludes.add('**/*.so.debug')
124 excludes.add('**/*.so.*.debug')
125 }
126
Austin Schuh812d0d12021-11-04 20:16:48 -0700127 jre(WPIJREArtifact) {
128 }
129
130 myRobotJava(JavaArtifact) {
131 jarTask = shadowJar
132 postdeploy << { ctx ->
Maxwell Henderson80bec322024-01-09 15:48:44 -0800133 ctx.execute("echo '/usr/local/frc/JRE/bin/java -XX:+UseSerialGC -Djava.library.path=/usr/local/frc/third-party/lib -Djava.lang.invoke.stringConcat=BC_SB -jar /home/lvuser/myRobot-all.jar' > /home/lvuser/robotCommand")
James Kuszmaulcf324122023-01-14 14:07:17 -0800134 ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand")
Austin Schuh812d0d12021-11-04 20:16:48 -0700135 }
136 }
137 }
138 }
139 }
140}
141
142tasks.register('deployJava') {
143 try {
144 dependsOn tasks.named('deployjreroborio')
145 dependsOn tasks.named('deploymyRobotJavaroborio')
James Kuszmaulcf324122023-01-14 14:07:17 -0800146 dependsOn tasks.named('deploymyRobotCppJavaroborio') // Deploying shared C++ is how to get the Java shared libraries.
Austin Schuh812d0d12021-11-04 20:16:48 -0700147 } catch (ignored) {
148 }
149}
150
151tasks.register('deployShared') {
152 try {
153 dependsOn tasks.named('deploymyRobotCpproborio')
154 } catch (ignored) {
155 }
156}
157
158tasks.register('deployStatic') {
159 try {
160 dependsOn tasks.named('deploymyRobotCppStaticroborio')
161 } catch (ignored) {
162 }
163}
Austin Schuh1e69f942020-11-14 15:06:14 -0800164
Brian Silverman8fce7482020-01-05 13:18:21 -0800165model {
166 components {
167 myRobotCpp(NativeExecutableSpec) {
168 targetBuildTypes 'debug'
169 sources {
170 cpp {
171 source {
172 srcDirs = ['src/main/native/cpp']
173 includes = ['**/*.cpp']
174 }
175 exportedHeaders {
176 srcDirs = ['src/main/native/include']
177 includes = ['**/*.h']
178 }
179 }
180 }
181 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700182 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
183 if (binary.buildType.name == 'debug') {
184 deploy.targets.roborio.artifacts.myRobotCpp.binary = binary
James Kuszmaulcf324122023-01-14 14:07:17 -0800185 deploy.targets.roborio.artifacts.myRobotCppJava.binary = binary
Austin Schuh812d0d12021-11-04 20:16:48 -0700186 }
187 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800188 lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800189 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
190 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
191 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800192 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800193 project(':ntcore').addNtcoreDependency(binary, 'shared')
194 project(':ntcore').addNtcoreJniDependency(binary)
Austin Schuh1e69f942020-11-14 15:06:14 -0800195 lib project: ':cscore', library: 'cscore', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800196 lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800197 lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800198 lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800199 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800200 project(':hal').addHalDependency(binary, 'shared')
201 project(':hal').addHalJniDependency(binary)
James Kuszmaulcf324122023-01-14 14:07:17 -0800202 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800203 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800204 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700205 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800206 } else {
207 def systemArch = getCurrentArch()
208 if (binary.targetPlatform.name == systemArch) {
209 simProjects.each {
210 lib project: ":simulation:$it", library: it, linkage: 'shared'
211 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800212 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800213 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800214 }
215 }
216 myRobotCppStatic(NativeExecutableSpec) {
217 targetBuildTypes 'debug'
218 nativeUtils.excludeBinariesFromStrip(it)
219 sources {
220 cpp {
221 source {
222 srcDirs = ['src/main/native/cpp']
223 includes = ['**/*.cpp']
224 }
225 exportedHeaders {
226 srcDirs = ['src/main/native/include']
227 includes = ['**/*.h']
228 }
229 }
230 }
231 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700232 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
233 if (binary.buildType.name == 'debug') {
234 deploy.targets.roborio.artifacts.myRobotCppStatic.binary = binary
235 }
236 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800237 lib project: ':apriltag', library: 'apriltag', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800238 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static'
239 lib project: ':wpilibc', library: 'wpilibc', linkage: 'static'
240 lib project: ':wpimath', library: 'wpimath', linkage: 'static'
Austin Schuh75263e32022-02-22 18:05:32 -0800241 lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
James Kuszmaulcf324122023-01-14 14:07:17 -0800242 project(':ntcore').addNtcoreDependency(binary, 'static')
Austin Schuh1e69f942020-11-14 15:06:14 -0800243 lib project: ':cscore', library: 'cscore', linkage: 'static'
244 project(':hal').addHalDependency(binary, 'static')
James Kuszmaulcf324122023-01-14 14:07:17 -0800245 lib project: ':wpinet', library: 'wpinet', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800246 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800247 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700248 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800249 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800250 }
251 }
252 }
253 tasks {
254 def c = $.components
255 project.tasks.create('runCpp', Exec) {
256 group = 'WPILib'
257 description = "Run the myRobotCpp executable"
258 def found = false
259 def systemArch = getCurrentArch()
Austin Schuh1e69f942020-11-14 15:06:14 -0800260 def runTask = it
Brian Silverman8fce7482020-01-05 13:18:21 -0800261 c.each {
262 if (it in NativeExecutableSpec && it.name == "myRobotCpp") {
263 it.binaries.each {
264 if (!found) {
265 def arch = it.targetPlatform.name
266 if (arch == systemArch) {
267 dependsOn it.tasks.install
268 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
269 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
270 run.dependsOn it.tasks.install
271 run.systemProperty 'java.library.path', filePath
272 run.environment 'LD_LIBRARY_PATH', filePath
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800273 run.environment 'DYLD_LIBRARY_PATH', filePath
Austin Schuh1e69f942020-11-14 15:06:14 -0800274
275 def installTask = it.tasks.install
276
277 def doFirstTask = {
278 def extensions = '';
279 installTask.installDirectory.get().getAsFile().eachFileRecurse {
280 def name = it.name
281 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) {
282 return
283 }
284 def file = it
285 simProjects.each {
286 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
287 extensions += file.absolutePath + File.pathSeparator
288 }
289 }
290 }
291 if (extensions != '') {
292 run.environment 'HALSIM_EXTENSIONS', extensions
293 runTask.environment 'HALSIM_EXTENSIONS', extensions
294 }
295 }
296
297 runTask.doFirst doFirstTask
298 run.doFirst doFirstTask
299
Brian Silverman8fce7482020-01-05 13:18:21 -0800300 run.workingDir filePath
301
302 found = true
303 }
304 }
305 }
306 }
307 }
308 }
309 installAthena(Task) {
310 $.binaries.each {
311 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCpp') {
312 dependsOn it.tasks.install
313 }
314 }
315 }
316 installAthenaStatic(Task) {
317 $.binaries.each {
318 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCppStatic') {
319 dependsOn it.tasks.install
320 }
321 }
322 }
323 }
324}