blob: d531161780864e2ea0b2bca6b90571543107573e [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 {
39 mavenCentral()
40}
41
42dependencies {
43 implementation project(':wpilibj')
Austin Schuh1e69f942020-11-14 15:06:14 -080044 implementation project(':wpimath')
Brian Silverman8fce7482020-01-05 13:18:21 -080045 implementation project(':hal')
46 implementation project(':wpiutil')
47 implementation project(':ntcore')
48 implementation project(':cscore')
49 implementation project(':cameraserver')
50 implementation project(':wpilibOldCommands')
51 implementation project(':wpilibNewCommands')
52}
53
Austin Schuh812d0d12021-11-04 20:16:48 -070054def simProjects = ['halsim_gui']
55
56deploy {
57 targets {
58 roborio(RemoteTarget) {
59 directory = '/home/admin'
60 maxChannels = 4
61 locations {
62 ssh(SshDeployLocation) {
63 address = "172.22.11.2"
64 user = 'admin'
65 password = ''
66 ipv6 = false
67 }
68 }
69
70 def remote = it
71
72 artifacts.registerFactory(WPIJREArtifact) {
73 return objects.newInstance(WPIJREArtifact, it, remote)
74 }
75
76 artifacts {
77 all {
78 predeploy << { ctx ->
79 ctx.execute('/usr/local/frc/bin/frcKillRobot.sh -t')
80 }
81 postdeploy << { ctx ->
82 ctx.execute("sync")
83 ctx.execute("ldconfig")
84 }
85 }
86
87 myRobotCpp(NativeExecutableArtifact) {
88 libraryDirectory = '/usr/local/frc/third-party/lib'
Austin Schuh75263e32022-02-22 18:05:32 -080089 def excludes = getLibraryFilter().getExcludes()
90 excludes.add('**/*.so.debug')
91 excludes.add('**/*.so.*.debug')
Austin Schuh812d0d12021-11-04 20:16:48 -070092 postdeploy << { ctx ->
93 ctx.execute('chmod +x myRobotCpp')
94 }
95 }
96
97 myRobotCppStatic(NativeExecutableArtifact) {
98 libraryDirectory = '/usr/local/frc/third-party/lib'
99 postdeploy << { ctx ->
100 ctx.execute('chmod +x myRobotCppStatic')
101 }
102 }
103
104 jre(WPIJREArtifact) {
105 }
106
107 myRobotJava(JavaArtifact) {
108 jarTask = shadowJar
109 postdeploy << { ctx ->
110 ctx.execute("echo '/usr/local/frc/JRE/bin/java -XX:+UseConcMarkSweepGC -Djava.library.path=/usr/local/frc/third-party/lib -Djava.lang.invoke.stringConcat=BC_SB -jar /home/admin/myRobot-all.jar' > /home/admin/myRobotJavaRun")
111 ctx.execute("chmod +x /home/admin/myRobotJavaRun; chown lvuser /home/admin/myRobotJavaRun")
112 }
113 }
114 }
115 }
116 }
117}
118
119tasks.register('deployJava') {
120 try {
121 dependsOn tasks.named('deployjreroborio')
122 dependsOn tasks.named('deploymyRobotJavaroborio')
123 dependsOn tasks.named('deploymyRobotCpproborio') // Deploying shared C++ is how to get the Java shared libraries.
124 } catch (ignored) {
125 }
126}
127
128tasks.register('deployShared') {
129 try {
130 dependsOn tasks.named('deploymyRobotCpproborio')
131 } catch (ignored) {
132 }
133}
134
135tasks.register('deployStatic') {
136 try {
137 dependsOn tasks.named('deploymyRobotCppStaticroborio')
138 } catch (ignored) {
139 }
140}
Austin Schuh1e69f942020-11-14 15:06:14 -0800141
Brian Silverman8fce7482020-01-05 13:18:21 -0800142model {
143 components {
144 myRobotCpp(NativeExecutableSpec) {
145 targetBuildTypes 'debug'
146 sources {
147 cpp {
148 source {
149 srcDirs = ['src/main/native/cpp']
150 includes = ['**/*.cpp']
151 }
152 exportedHeaders {
153 srcDirs = ['src/main/native/include']
154 includes = ['**/*.h']
155 }
156 }
157 }
158 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700159 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
160 if (binary.buildType.name == 'debug') {
161 deploy.targets.roborio.artifacts.myRobotCpp.binary = binary
162 }
163 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800164 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
165 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
166 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
167 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800168 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800169 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
170 lib project: ':cscore', library: 'cscore', linkage: 'shared'
171 lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared'
172 lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
Austin Schuh75263e32022-02-22 18:05:32 -0800173 lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared'
174 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800175 project(':hal').addHalDependency(binary, 'shared')
176 project(':hal').addHalJniDependency(binary)
177 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800178 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700179 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800180 } else {
181 def systemArch = getCurrentArch()
182 if (binary.targetPlatform.name == systemArch) {
183 simProjects.each {
184 lib project: ":simulation:$it", library: it, linkage: 'shared'
185 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800186 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800187 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800188 }
189 }
190 myRobotCppStatic(NativeExecutableSpec) {
191 targetBuildTypes 'debug'
192 nativeUtils.excludeBinariesFromStrip(it)
193 sources {
194 cpp {
195 source {
196 srcDirs = ['src/main/native/cpp']
197 includes = ['**/*.cpp']
198 }
199 exportedHeaders {
200 srcDirs = ['src/main/native/include']
201 includes = ['**/*.h']
202 }
203 }
204 }
205 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700206 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
207 if (binary.buildType.name == 'debug') {
208 deploy.targets.roborio.artifacts.myRobotCppStatic.binary = binary
209 }
210 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800211 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'static'
212 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static'
213 lib project: ':wpilibc', library: 'wpilibc', linkage: 'static'
214 lib project: ':wpimath', library: 'wpimath', linkage: 'static'
Austin Schuh75263e32022-02-22 18:05:32 -0800215 lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800216 lib project: ':ntcore', library: 'ntcore', linkage: 'static'
217 lib project: ':cscore', library: 'cscore', linkage: 'static'
218 project(':hal').addHalDependency(binary, 'static')
219 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
Austin Schuh1e69f942020-11-14 15:06:14 -0800220 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700221 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800222 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800223 }
224 }
225 }
226 tasks {
227 def c = $.components
228 project.tasks.create('runCpp', Exec) {
229 group = 'WPILib'
230 description = "Run the myRobotCpp executable"
231 def found = false
232 def systemArch = getCurrentArch()
Austin Schuh1e69f942020-11-14 15:06:14 -0800233 def runTask = it
Brian Silverman8fce7482020-01-05 13:18:21 -0800234 c.each {
235 if (it in NativeExecutableSpec && it.name == "myRobotCpp") {
236 it.binaries.each {
237 if (!found) {
238 def arch = it.targetPlatform.name
239 if (arch == systemArch) {
240 dependsOn it.tasks.install
241 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
242 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
243 run.dependsOn it.tasks.install
244 run.systemProperty 'java.library.path', filePath
245 run.environment 'LD_LIBRARY_PATH', filePath
Austin Schuh1e69f942020-11-14 15:06:14 -0800246
247 def installTask = it.tasks.install
248
249 def doFirstTask = {
250 def extensions = '';
251 installTask.installDirectory.get().getAsFile().eachFileRecurse {
252 def name = it.name
253 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) {
254 return
255 }
256 def file = it
257 simProjects.each {
258 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
259 extensions += file.absolutePath + File.pathSeparator
260 }
261 }
262 }
263 if (extensions != '') {
264 run.environment 'HALSIM_EXTENSIONS', extensions
265 runTask.environment 'HALSIM_EXTENSIONS', extensions
266 }
267 }
268
269 runTask.doFirst doFirstTask
270 run.doFirst doFirstTask
271
Brian Silverman8fce7482020-01-05 13:18:21 -0800272 run.workingDir filePath
273
274 found = true
275 }
276 }
277 }
278 }
279 }
280 }
281 installAthena(Task) {
282 $.binaries.each {
283 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCpp') {
284 dependsOn it.tasks.install
285 }
286 }
287 }
288 installAthenaStatic(Task) {
289 $.binaries.each {
290 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCppStatic') {
291 dependsOn it.tasks.install
292 }
293 }
294 }
295 }
296}