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 { |
| 39 | mavenCentral() |
| 40 | } |
| 41 | |
| 42 | dependencies { |
| 43 | implementation project(':wpilibj') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 44 | implementation project(':wpimath') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 45 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 54 | def simProjects = ['halsim_gui'] |
| 55 | |
| 56 | deploy { |
| 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 Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 89 | def excludes = getLibraryFilter().getExcludes() |
| 90 | excludes.add('**/*.so.debug') |
| 91 | excludes.add('**/*.so.*.debug') |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 92 | 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 | |
| 119 | tasks.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 | |
| 128 | tasks.register('deployShared') { |
| 129 | try { |
| 130 | dependsOn tasks.named('deploymyRobotCpproborio') |
| 131 | } catch (ignored) { |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | tasks.register('deployStatic') { |
| 136 | try { |
| 137 | dependsOn tasks.named('deploymyRobotCppStaticroborio') |
| 138 | } catch (ignored) { |
| 139 | } |
| 140 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 141 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 142 | model { |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 159 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 164 | 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 Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 168 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 169 | 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 Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 173 | lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared' |
| 174 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 175 | project(':hal').addHalDependency(binary, 'shared') |
| 176 | project(':hal').addHalJniDependency(binary) |
| 177 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 178 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 179 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 180 | } 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 186 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 187 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 188 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 206 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 211 | 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 Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 215 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'static' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 216 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 220 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 221 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 222 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 223 | } |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 233 | def runTask = it |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 234 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 246 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 272 | 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 | } |