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 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 34 | mainClassName = 'frc.robot.Main' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 35 | |
| 36 | apply plugin: 'com.github.johnrengelman.shadow' |
| 37 | |
| 38 | repositories { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 39 | maven { |
| 40 | url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn' |
| 41 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | dependencies { |
| 45 | implementation project(':wpilibj') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 46 | implementation project(':wpimath') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 47 | implementation project(':hal') |
| 48 | implementation project(':wpiutil') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 49 | implementation project(':wpinet') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 50 | implementation project(':ntcore') |
| 51 | implementation project(':cscore') |
| 52 | implementation project(':cameraserver') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 53 | implementation project(':wpilibNewCommands') |
| 54 | } |
| 55 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 56 | tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { |
| 57 | onlyIf { false } |
| 58 | } |
| 59 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 60 | def simProjects = ['halsim_gui'] |
| 61 | |
| 62 | deploy { |
| 63 | targets { |
| 64 | roborio(RemoteTarget) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 65 | directory = '/home/lvuser' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 66 | 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 85 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 87 | } |
| 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 Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 96 | def excludes = getLibraryFilter().getExcludes() |
| 97 | excludes.add('**/*.so.debug') |
| 98 | excludes.add('**/*.so.*.debug') |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 99 | postdeploy << { ctx -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 100 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 103 | ctx.execute('chmod +x myRobotCpp') |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | myRobotCppStatic(NativeExecutableArtifact) { |
| 108 | libraryDirectory = '/usr/local/frc/third-party/lib' |
| 109 | postdeploy << { ctx -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 110 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 113 | ctx.execute('chmod +x myRobotCppStatic') |
| 114 | } |
| 115 | } |
| 116 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 117 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 124 | jre(WPIJREArtifact) { |
| 125 | } |
| 126 | |
| 127 | myRobotJava(JavaArtifact) { |
| 128 | jarTask = shadowJar |
| 129 | postdeploy << { ctx -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 130 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | tasks.register('deployJava') { |
| 140 | try { |
| 141 | dependsOn tasks.named('deployjreroborio') |
| 142 | dependsOn tasks.named('deploymyRobotJavaroborio') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 143 | 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] | 144 | } catch (ignored) { |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | tasks.register('deployShared') { |
| 149 | try { |
| 150 | dependsOn tasks.named('deploymyRobotCpproborio') |
| 151 | } catch (ignored) { |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | tasks.register('deployStatic') { |
| 156 | try { |
| 157 | dependsOn tasks.named('deploymyRobotCppStaticroborio') |
| 158 | } catch (ignored) { |
| 159 | } |
| 160 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 161 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 162 | model { |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 179 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 180 | if (binary.buildType.name == 'debug') { |
| 181 | deploy.targets.roborio.artifacts.myRobotCpp.binary = binary |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 182 | deploy.targets.roborio.artifacts.myRobotCppJava.binary = binary |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 185 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 186 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 187 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 188 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 189 | project(':ntcore').addNtcoreDependency(binary, 'shared') |
| 190 | project(':ntcore').addNtcoreJniDependency(binary) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 191 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 192 | lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 193 | lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 194 | lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 195 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 196 | project(':hal').addHalDependency(binary, 'shared') |
| 197 | project(':hal').addHalJniDependency(binary) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 198 | lib project: ':wpinet', library: 'wpinet', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 199 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 200 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 201 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 202 | } 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 208 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 209 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 210 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 228 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 233 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static' |
| 234 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'static' |
| 235 | lib project: ':wpimath', library: 'wpimath', linkage: 'static' |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 236 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'static' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 237 | project(':ntcore').addNtcoreDependency(binary, 'static') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 238 | lib project: ':cscore', library: 'cscore', linkage: 'static' |
| 239 | project(':hal').addHalDependency(binary, 'static') |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 240 | lib project: ':wpinet', library: 'wpinet', linkage: 'static' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 241 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 242 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 243 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 244 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 245 | } |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 255 | def runTask = it |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 256 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 268 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 294 | 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 | } |