Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | import edu.wpi.first.deployutils.deploy.target.RemoteTarget |
| 2 | import edu.wpi.first.deployutils.deploy.target.location.SshDeployLocation |
| 3 | import edu.wpi.first.deployutils.deploy.artifact.* |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 4 | import org.gradle.internal.os.OperatingSystem |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 5 | |
| 6 | plugins { |
| 7 | id 'java' |
| 8 | id 'application' |
| 9 | id 'cpp' |
| 10 | id 'visual-studio' |
| 11 | } |
| 12 | |
| 13 | apply plugin: 'edu.wpi.first.NativeUtils' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | apply plugin: 'edu.wpi.first.DeployUtils' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 15 | |
| 16 | apply from: '../shared/config.gradle' |
| 17 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 18 | application { |
| 19 | if (OperatingSystem.current().isMacOsX()) { |
| 20 | applicationDefaultJvmArgs = ['-XstartOnFirstThread'] |
| 21 | } |
| 22 | } |
| 23 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 24 | ext { |
| 25 | sharedCvConfigs = [myRobotCpp: []] |
| 26 | staticCvConfigs = [myRobotCppStatic: []] |
| 27 | useJava = true |
| 28 | useCpp = true |
| 29 | skipDev = true |
| 30 | } |
| 31 | |
| 32 | apply from: "${rootDir}/shared/opencv.gradle" |
| 33 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 34 | application { |
| 35 | mainClass = 'frc.robot.Main' |
| 36 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 37 | |
| 38 | apply plugin: 'com.github.johnrengelman.shadow' |
| 39 | |
| 40 | repositories { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 41 | maven { |
| 42 | url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn' |
| 43 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | dependencies { |
| 47 | implementation project(':wpilibj') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 48 | implementation project(':wpimath') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 49 | implementation project(':hal') |
| 50 | implementation project(':wpiutil') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 51 | implementation project(':wpinet') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 52 | implementation project(':ntcore') |
| 53 | implementation project(':cscore') |
| 54 | implementation project(':cameraserver') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 55 | implementation project(':wpilibNewCommands') |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 56 | implementation project(':apriltag') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 57 | } |
| 58 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 59 | tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { |
| 60 | onlyIf { false } |
| 61 | } |
| 62 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 63 | def simProjects = ['halsim_gui'] |
| 64 | |
| 65 | deploy { |
| 66 | targets { |
| 67 | roborio(RemoteTarget) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 68 | directory = '/home/lvuser' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 69 | 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 88 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 90 | } |
| 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 Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 99 | def excludes = getLibraryFilter().getExcludes() |
| 100 | excludes.add('**/*.so.debug') |
| 101 | excludes.add('**/*.so.*.debug') |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 102 | postdeploy << { ctx -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 103 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 106 | ctx.execute('chmod +x myRobotCpp') |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | myRobotCppStatic(NativeExecutableArtifact) { |
| 111 | libraryDirectory = '/usr/local/frc/third-party/lib' |
| 112 | postdeploy << { ctx -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 113 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 116 | ctx.execute('chmod +x myRobotCppStatic') |
| 117 | } |
| 118 | } |
| 119 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 120 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 127 | jre(WPIJREArtifact) { |
| 128 | } |
| 129 | |
| 130 | myRobotJava(JavaArtifact) { |
| 131 | jarTask = shadowJar |
| 132 | postdeploy << { ctx -> |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 133 | 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 134 | ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand") |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | tasks.register('deployJava') { |
| 143 | try { |
| 144 | dependsOn tasks.named('deployjreroborio') |
| 145 | dependsOn tasks.named('deploymyRobotJavaroborio') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 146 | dependsOn tasks.named('deploymyRobotCppJavaroborio') // Deploying shared C++ is how to get the Java shared libraries. |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 147 | } catch (ignored) { |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | tasks.register('deployShared') { |
| 152 | try { |
| 153 | dependsOn tasks.named('deploymyRobotCpproborio') |
| 154 | } catch (ignored) { |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | tasks.register('deployStatic') { |
| 159 | try { |
| 160 | dependsOn tasks.named('deploymyRobotCppStaticroborio') |
| 161 | } catch (ignored) { |
| 162 | } |
| 163 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 164 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 165 | model { |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 182 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 183 | if (binary.buildType.name == 'debug') { |
| 184 | deploy.targets.roborio.artifacts.myRobotCpp.binary = binary |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 185 | deploy.targets.roborio.artifacts.myRobotCppJava.binary = binary |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 188 | lib project: ':apriltag', library: 'apriltag', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 189 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 190 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 191 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 192 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 193 | project(':ntcore').addNtcoreDependency(binary, 'shared') |
| 194 | project(':ntcore').addNtcoreJniDependency(binary) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 195 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 196 | lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 197 | lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 198 | lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 199 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 200 | project(':hal').addHalDependency(binary, 'shared') |
| 201 | project(':hal').addHalJniDependency(binary) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 202 | lib project: ':wpinet', library: 'wpinet', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 203 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 204 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 205 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 206 | } 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 212 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 213 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 214 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 232 | 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 237 | lib project: ':apriltag', library: 'apriltag', linkage: 'static' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 238 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static' |
| 239 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'static' |
| 240 | lib project: ':wpimath', library: 'wpimath', linkage: 'static' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 241 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'static' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 242 | project(':ntcore').addNtcoreDependency(binary, 'static') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 243 | lib project: ':cscore', library: 'cscore', linkage: 'static' |
| 244 | project(':hal').addHalDependency(binary, 'static') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 245 | lib project: ':wpinet', library: 'wpinet', linkage: 'static' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 246 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 247 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 248 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 249 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 250 | } |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 260 | def runTask = it |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 261 | 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 273 | run.environment 'DYLD_LIBRARY_PATH', filePath |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 274 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 300 | 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 | } |