blob: d2e98e6eafb30021b593413c9242742c3cd35380 [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
Austin Schuh1e69f942020-11-14 15:06:14 -080034mainClassName = 'frc.robot.Main'
Brian Silverman8fce7482020-01-05 13:18:21 -080035
36apply plugin: 'com.github.johnrengelman.shadow'
37
38repositories {
James Kuszmaulcf324122023-01-14 14:07:17 -080039 maven {
40 url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
41 }
Brian Silverman8fce7482020-01-05 13:18:21 -080042}
43
44dependencies {
45 implementation project(':wpilibj')
Austin Schuh1e69f942020-11-14 15:06:14 -080046 implementation project(':wpimath')
Brian Silverman8fce7482020-01-05 13:18:21 -080047 implementation project(':hal')
48 implementation project(':wpiutil')
James Kuszmaulcf324122023-01-14 14:07:17 -080049 implementation project(':wpinet')
Brian Silverman8fce7482020-01-05 13:18:21 -080050 implementation project(':ntcore')
51 implementation project(':cscore')
52 implementation project(':cameraserver')
Brian Silverman8fce7482020-01-05 13:18:21 -080053 implementation project(':wpilibNewCommands')
54}
55
James Kuszmaulcf324122023-01-14 14:07:17 -080056tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
57 onlyIf { false }
58}
59
Austin Schuh812d0d12021-11-04 20:16:48 -070060def simProjects = ['halsim_gui']
61
62deploy {
63 targets {
64 roborio(RemoteTarget) {
James Kuszmaulcf324122023-01-14 14:07:17 -080065 directory = '/home/lvuser'
Austin Schuh812d0d12021-11-04 20:16:48 -070066 maxChannels = 4
67 locations {
68 ssh(SshDeployLocation) {
69 address = "172.22.11.2"
70 user = 'admin'
71 password = ''
72 ipv6 = false
73 }
74 }
75
76 def remote = it
77
78 artifacts.registerFactory(WPIJREArtifact) {
79 return objects.newInstance(WPIJREArtifact, it, remote)
80 }
81
82 artifacts {
83 all {
84 predeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -080085 ctx.execute('. /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t 2> /dev/null')
86 ctx.execute("sed -i -e 's/\"exec /\"/' /usr/local/frc/bin/frcRunRobot.sh")
Austin Schuh812d0d12021-11-04 20:16:48 -070087 }
88 postdeploy << { ctx ->
89 ctx.execute("sync")
90 ctx.execute("ldconfig")
91 }
92 }
93
94 myRobotCpp(NativeExecutableArtifact) {
95 libraryDirectory = '/usr/local/frc/third-party/lib'
Austin Schuh75263e32022-02-22 18:05:32 -080096 def excludes = getLibraryFilter().getExcludes()
97 excludes.add('**/*.so.debug')
98 excludes.add('**/*.so.*.debug')
Austin Schuh812d0d12021-11-04 20:16:48 -070099 postdeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -0800100 ctx.execute("echo '/home/lvuser/myRobotCpp' > /home/lvuser/robotCommand")
101 ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand")
102 ctx.execute("setcap cap_sys_nice+eip \"/home/lvuser/myRobotCpp\"")
Austin Schuh812d0d12021-11-04 20:16:48 -0700103 ctx.execute('chmod +x myRobotCpp')
104 }
105 }
106
107 myRobotCppStatic(NativeExecutableArtifact) {
108 libraryDirectory = '/usr/local/frc/third-party/lib'
109 postdeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -0800110 ctx.execute("echo '/home/lvuser/myRobotCppStatic' > /home/lvuser/robotCommand")
111 ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand")
112 ctx.execute("setcap cap_sys_nice+eip \"/home/lvuser/myRobotCppStatic\"")
Austin Schuh812d0d12021-11-04 20:16:48 -0700113 ctx.execute('chmod +x myRobotCppStatic')
114 }
115 }
116
James Kuszmaulcf324122023-01-14 14:07:17 -0800117 myRobotCppJava(NativeExecutableArtifact) {
118 libraryDirectory = '/usr/local/frc/third-party/lib'
119 def excludes = getLibraryFilter().getExcludes()
120 excludes.add('**/*.so.debug')
121 excludes.add('**/*.so.*.debug')
122 }
123
Austin Schuh812d0d12021-11-04 20:16:48 -0700124 jre(WPIJREArtifact) {
125 }
126
127 myRobotJava(JavaArtifact) {
128 jarTask = shadowJar
129 postdeploy << { ctx ->
James Kuszmaulcf324122023-01-14 14:07:17 -0800130 ctx.execute("echo '/usr/local/frc/JRE/bin/java -XX:+UseG1GC -XX:MaxGCPauseMillis=1 -XX:GCTimeRatio=1 -Djava.library.path=/usr/local/frc/third-party/lib -Djava.lang.invoke.stringConcat=BC_SB -jar /home/lvuser/myRobot-all.jar' > /home/lvuser/robotCommand")
131 ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand")
Austin Schuh812d0d12021-11-04 20:16:48 -0700132 }
133 }
134 }
135 }
136 }
137}
138
139tasks.register('deployJava') {
140 try {
141 dependsOn tasks.named('deployjreroborio')
142 dependsOn tasks.named('deploymyRobotJavaroborio')
James Kuszmaulcf324122023-01-14 14:07:17 -0800143 dependsOn tasks.named('deploymyRobotCppJavaroborio') // Deploying shared C++ is how to get the Java shared libraries.
Austin Schuh812d0d12021-11-04 20:16:48 -0700144 } catch (ignored) {
145 }
146}
147
148tasks.register('deployShared') {
149 try {
150 dependsOn tasks.named('deploymyRobotCpproborio')
151 } catch (ignored) {
152 }
153}
154
155tasks.register('deployStatic') {
156 try {
157 dependsOn tasks.named('deploymyRobotCppStaticroborio')
158 } catch (ignored) {
159 }
160}
Austin Schuh1e69f942020-11-14 15:06:14 -0800161
Brian Silverman8fce7482020-01-05 13:18:21 -0800162model {
163 components {
164 myRobotCpp(NativeExecutableSpec) {
165 targetBuildTypes 'debug'
166 sources {
167 cpp {
168 source {
169 srcDirs = ['src/main/native/cpp']
170 includes = ['**/*.cpp']
171 }
172 exportedHeaders {
173 srcDirs = ['src/main/native/include']
174 includes = ['**/*.h']
175 }
176 }
177 }
178 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700179 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
180 if (binary.buildType.name == 'debug') {
181 deploy.targets.roborio.artifacts.myRobotCpp.binary = binary
James Kuszmaulcf324122023-01-14 14:07:17 -0800182 deploy.targets.roborio.artifacts.myRobotCppJava.binary = binary
Austin Schuh812d0d12021-11-04 20:16:48 -0700183 }
184 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800185 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
186 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
187 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800188 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800189 project(':ntcore').addNtcoreDependency(binary, 'shared')
190 project(':ntcore').addNtcoreJniDependency(binary)
Austin Schuh1e69f942020-11-14 15:06:14 -0800191 lib project: ':cscore', library: 'cscore', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800192 lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800193 lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800194 lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800195 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800196 project(':hal').addHalDependency(binary, 'shared')
197 project(':hal').addHalJniDependency(binary)
James Kuszmaulcf324122023-01-14 14:07:17 -0800198 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800199 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800200 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700201 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800202 } else {
203 def systemArch = getCurrentArch()
204 if (binary.targetPlatform.name == systemArch) {
205 simProjects.each {
206 lib project: ":simulation:$it", library: it, linkage: 'shared'
207 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800208 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800209 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800210 }
211 }
212 myRobotCppStatic(NativeExecutableSpec) {
213 targetBuildTypes 'debug'
214 nativeUtils.excludeBinariesFromStrip(it)
215 sources {
216 cpp {
217 source {
218 srcDirs = ['src/main/native/cpp']
219 includes = ['**/*.cpp']
220 }
221 exportedHeaders {
222 srcDirs = ['src/main/native/include']
223 includes = ['**/*.h']
224 }
225 }
226 }
227 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700228 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
229 if (binary.buildType.name == 'debug') {
230 deploy.targets.roborio.artifacts.myRobotCppStatic.binary = binary
231 }
232 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800233 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static'
234 lib project: ':wpilibc', library: 'wpilibc', linkage: 'static'
235 lib project: ':wpimath', library: 'wpimath', linkage: 'static'
Austin Schuh75263e32022-02-22 18:05:32 -0800236 lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
James Kuszmaulcf324122023-01-14 14:07:17 -0800237 project(':ntcore').addNtcoreDependency(binary, 'static')
Austin Schuh1e69f942020-11-14 15:06:14 -0800238 lib project: ':cscore', library: 'cscore', linkage: 'static'
239 project(':hal').addHalDependency(binary, 'static')
James Kuszmaulcf324122023-01-14 14:07:17 -0800240 lib project: ':wpinet', library: 'wpinet', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800241 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800242 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700243 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800244 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800245 }
246 }
247 }
248 tasks {
249 def c = $.components
250 project.tasks.create('runCpp', Exec) {
251 group = 'WPILib'
252 description = "Run the myRobotCpp executable"
253 def found = false
254 def systemArch = getCurrentArch()
Austin Schuh1e69f942020-11-14 15:06:14 -0800255 def runTask = it
Brian Silverman8fce7482020-01-05 13:18:21 -0800256 c.each {
257 if (it in NativeExecutableSpec && it.name == "myRobotCpp") {
258 it.binaries.each {
259 if (!found) {
260 def arch = it.targetPlatform.name
261 if (arch == systemArch) {
262 dependsOn it.tasks.install
263 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
264 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
265 run.dependsOn it.tasks.install
266 run.systemProperty 'java.library.path', filePath
267 run.environment 'LD_LIBRARY_PATH', filePath
Austin Schuh1e69f942020-11-14 15:06:14 -0800268
269 def installTask = it.tasks.install
270
271 def doFirstTask = {
272 def extensions = '';
273 installTask.installDirectory.get().getAsFile().eachFileRecurse {
274 def name = it.name
275 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) {
276 return
277 }
278 def file = it
279 simProjects.each {
280 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
281 extensions += file.absolutePath + File.pathSeparator
282 }
283 }
284 }
285 if (extensions != '') {
286 run.environment 'HALSIM_EXTENSIONS', extensions
287 runTask.environment 'HALSIM_EXTENSIONS', extensions
288 }
289 }
290
291 runTask.doFirst doFirstTask
292 run.doFirst doFirstTask
293
Brian Silverman8fce7482020-01-05 13:18:21 -0800294 run.workingDir filePath
295
296 found = true
297 }
298 }
299 }
300 }
301 }
302 }
303 installAthena(Task) {
304 $.binaries.each {
305 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCpp') {
306 dependsOn it.tasks.install
307 }
308 }
309 }
310 installAthenaStatic(Task) {
311 $.binaries.each {
312 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCppStatic') {
313 dependsOn it.tasks.install
314 }
315 }
316 }
317 }
318}