blob: 045f8271217683bc5e73c975ad1a66f85c60358b [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'
89 postdeploy << { ctx ->
90 ctx.execute('chmod +x myRobotCpp')
91 }
92 }
93
94 myRobotCppStatic(NativeExecutableArtifact) {
95 libraryDirectory = '/usr/local/frc/third-party/lib'
96 postdeploy << { ctx ->
97 ctx.execute('chmod +x myRobotCppStatic')
98 }
99 }
100
101 jre(WPIJREArtifact) {
102 }
103
104 myRobotJava(JavaArtifact) {
105 jarTask = shadowJar
106 postdeploy << { ctx ->
107 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")
108 ctx.execute("chmod +x /home/admin/myRobotJavaRun; chown lvuser /home/admin/myRobotJavaRun")
109 }
110 }
111 }
112 }
113 }
114}
115
116tasks.register('deployJava') {
117 try {
118 dependsOn tasks.named('deployjreroborio')
119 dependsOn tasks.named('deploymyRobotJavaroborio')
120 dependsOn tasks.named('deploymyRobotCpproborio') // Deploying shared C++ is how to get the Java shared libraries.
121 } catch (ignored) {
122 }
123}
124
125tasks.register('deployShared') {
126 try {
127 dependsOn tasks.named('deploymyRobotCpproborio')
128 } catch (ignored) {
129 }
130}
131
132tasks.register('deployStatic') {
133 try {
134 dependsOn tasks.named('deploymyRobotCppStaticroborio')
135 } catch (ignored) {
136 }
137}
Austin Schuh1e69f942020-11-14 15:06:14 -0800138
Brian Silverman8fce7482020-01-05 13:18:21 -0800139model {
140 components {
141 myRobotCpp(NativeExecutableSpec) {
142 targetBuildTypes 'debug'
143 sources {
144 cpp {
145 source {
146 srcDirs = ['src/main/native/cpp']
147 includes = ['**/*.cpp']
148 }
149 exportedHeaders {
150 srcDirs = ['src/main/native/include']
151 includes = ['**/*.h']
152 }
153 }
154 }
155 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700156 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
157 if (binary.buildType.name == 'debug') {
158 deploy.targets.roborio.artifacts.myRobotCpp.binary = binary
159 }
160 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800161 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
162 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
163 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
164 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
165 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
166 lib project: ':cscore', library: 'cscore', linkage: 'shared'
167 lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared'
168 lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
169 project(':hal').addHalDependency(binary, 'shared')
170 project(':hal').addHalJniDependency(binary)
171 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
172 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
173 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700174 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800175 } else {
176 def systemArch = getCurrentArch()
177 if (binary.targetPlatform.name == systemArch) {
178 simProjects.each {
179 lib project: ":simulation:$it", library: it, linkage: 'shared'
180 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800181 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800182 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800183 }
184 }
185 myRobotCppStatic(NativeExecutableSpec) {
186 targetBuildTypes 'debug'
187 nativeUtils.excludeBinariesFromStrip(it)
188 sources {
189 cpp {
190 source {
191 srcDirs = ['src/main/native/cpp']
192 includes = ['**/*.cpp']
193 }
194 exportedHeaders {
195 srcDirs = ['src/main/native/include']
196 includes = ['**/*.h']
197 }
198 }
199 }
200 binaries.all { binary ->
Austin Schuh812d0d12021-11-04 20:16:48 -0700201 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
202 if (binary.buildType.name == 'debug') {
203 deploy.targets.roborio.artifacts.myRobotCppStatic.binary = binary
204 }
205 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800206 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'static'
207 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static'
208 lib project: ':wpilibc', library: 'wpilibc', linkage: 'static'
209 lib project: ':wpimath', library: 'wpimath', linkage: 'static'
210 lib project: ':ntcore', library: 'ntcore', linkage: 'static'
211 lib project: ':cscore', library: 'cscore', linkage: 'static'
212 project(':hal').addHalDependency(binary, 'static')
213 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
214 lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
215 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700216 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Austin Schuh1e69f942020-11-14 15:06:14 -0800217 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800218 }
219 }
220 }
221 tasks {
222 def c = $.components
223 project.tasks.create('runCpp', Exec) {
224 group = 'WPILib'
225 description = "Run the myRobotCpp executable"
226 def found = false
227 def systemArch = getCurrentArch()
Austin Schuh1e69f942020-11-14 15:06:14 -0800228 def runTask = it
Brian Silverman8fce7482020-01-05 13:18:21 -0800229 c.each {
230 if (it in NativeExecutableSpec && it.name == "myRobotCpp") {
231 it.binaries.each {
232 if (!found) {
233 def arch = it.targetPlatform.name
234 if (arch == systemArch) {
235 dependsOn it.tasks.install
236 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
237 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
238 run.dependsOn it.tasks.install
239 run.systemProperty 'java.library.path', filePath
240 run.environment 'LD_LIBRARY_PATH', filePath
Austin Schuh1e69f942020-11-14 15:06:14 -0800241
242 def installTask = it.tasks.install
243
244 def doFirstTask = {
245 def extensions = '';
246 installTask.installDirectory.get().getAsFile().eachFileRecurse {
247 def name = it.name
248 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) {
249 return
250 }
251 def file = it
252 simProjects.each {
253 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
254 extensions += file.absolutePath + File.pathSeparator
255 }
256 }
257 }
258 if (extensions != '') {
259 run.environment 'HALSIM_EXTENSIONS', extensions
260 runTask.environment 'HALSIM_EXTENSIONS', extensions
261 }
262 }
263
264 runTask.doFirst doFirstTask
265 run.doFirst doFirstTask
266
Brian Silverman8fce7482020-01-05 13:18:21 -0800267 run.workingDir filePath
268
269 found = true
270 }
271 }
272 }
273 }
274 }
275 }
276 installAthena(Task) {
277 $.binaries.each {
278 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCpp') {
279 dependsOn it.tasks.install
280 }
281 }
282 }
283 installAthenaStatic(Task) {
284 $.binaries.each {
285 if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCppStatic') {
286 dependsOn it.tasks.install
287 }
288 }
289 }
290 }
291}