Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | import jaci.gradle.toolchains.* |
| 2 | import jaci.gradle.nativedeps.* |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 3 | import org.gradle.internal.os.OperatingSystem |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | plugins { |
| 6 | id 'java' |
| 7 | id 'application' |
| 8 | id 'cpp' |
| 9 | id 'visual-studio' |
| 10 | } |
| 11 | |
| 12 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 13 | apply plugin: 'jaci.gradle.EmbeddedTools' |
| 14 | |
| 15 | apply from: '../shared/config.gradle' |
| 16 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 17 | application { |
| 18 | if (OperatingSystem.current().isMacOsX()) { |
| 19 | applicationDefaultJvmArgs = ['-XstartOnFirstThread'] |
| 20 | } |
| 21 | } |
| 22 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 23 | ext { |
| 24 | sharedCvConfigs = [myRobotCpp: []] |
| 25 | staticCvConfigs = [myRobotCppStatic: []] |
| 26 | useJava = true |
| 27 | useCpp = true |
| 28 | skipDev = true |
| 29 | } |
| 30 | |
| 31 | apply from: "${rootDir}/shared/opencv.gradle" |
| 32 | |
| 33 | deploy { |
| 34 | targets { |
| 35 | target('roborio') { |
| 36 | directory = '/home/admin' |
| 37 | maxChannels = 4 |
| 38 | locations { |
| 39 | ssh { |
| 40 | address = "172.22.11.2" |
| 41 | user = 'admin' |
| 42 | password = '' |
| 43 | ipv6 = false |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | artifacts { |
| 49 | all { |
| 50 | targets << 'roborio' |
| 51 | predeploy << { ctx -> |
| 52 | ctx.execute('/usr/local/frc/bin/frcKillRobot.sh -t') |
| 53 | } |
| 54 | postdeploy << { ctx -> |
| 55 | ctx.execute("sync") |
| 56 | ctx.execute("ldconfig") |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | artifact('jre', JREArtifact) { |
| 61 | jreDependency = 'edu.wpi.first.jdk:roborio-2020:11.0.4u10-2' |
| 62 | } |
| 63 | |
| 64 | javaArtifact('myRobotJava') { |
| 65 | jar = 'shadowJar' |
| 66 | postdeploy << { ctx -> |
| 67 | 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") |
| 68 | ctx.execute("chmod +x /home/admin/myRobotJavaRun; chown lvuser /home/admin/myRobotJavaRun") |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | nativeArtifact('myRobotCpp') { |
| 73 | component = 'myRobotCpp' |
| 74 | targetPlatform = nativeUtils.wpi.platforms.roborio |
| 75 | libraryDirectory = '/usr/local/frc/third-party/lib' |
| 76 | buildType = 'debug' |
| 77 | postdeploy << { ctx -> |
| 78 | ctx.execute('chmod +x myRobotCpp') |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | nativeArtifact('myRobotCppStatic') { |
| 84 | component = 'myRobotCppStatic' |
| 85 | targetPlatform = nativeUtils.wpi.platforms.roborio |
| 86 | buildType = 'debug' |
| 87 | |
| 88 | postdeploy << { ctx -> |
| 89 | ctx.execute('chmod +x myRobotCppStatic') |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | tasks.register('deployJava') { |
| 96 | try { |
| 97 | dependsOn tasks.named('deployJreRoborio') |
| 98 | dependsOn tasks.named('deployMyRobotJavaRoborio') |
| 99 | dependsOn tasks.named('deployMyRobotCppLibrariesRoborio') |
| 100 | } catch (ignored) { |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | tasks.register('deployShared') { |
| 105 | try { |
| 106 | dependsOn tasks.named('deployMyRobotCppLibrariesRoborio') |
| 107 | dependsOn tasks.named('deployMyRobotCppRoborio') |
| 108 | } catch (ignored) { |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | tasks.register('deployStatic') { |
| 113 | try { |
| 114 | dependsOn tasks.named('deployMyRobotCppStaticRoborio') |
| 115 | } catch (ignored) { |
| 116 | } |
| 117 | } |
| 118 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 119 | mainClassName = 'frc.robot.Main' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 120 | |
| 121 | apply plugin: 'com.github.johnrengelman.shadow' |
| 122 | |
| 123 | repositories { |
| 124 | mavenCentral() |
| 125 | } |
| 126 | |
| 127 | dependencies { |
| 128 | implementation project(':wpilibj') |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 129 | implementation project(':wpimath') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 130 | implementation project(':hal') |
| 131 | implementation project(':wpiutil') |
| 132 | implementation project(':ntcore') |
| 133 | implementation project(':cscore') |
| 134 | implementation project(':cameraserver') |
| 135 | implementation project(':wpilibOldCommands') |
| 136 | implementation project(':wpilibNewCommands') |
| 137 | } |
| 138 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 139 | def simProjects = [ |
| 140 | 'halsim_gui' |
| 141 | ] |
| 142 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 143 | model { |
| 144 | components { |
| 145 | myRobotCpp(NativeExecutableSpec) { |
| 146 | targetBuildTypes 'debug' |
| 147 | sources { |
| 148 | cpp { |
| 149 | source { |
| 150 | srcDirs = ['src/main/native/cpp'] |
| 151 | includes = ['**/*.cpp'] |
| 152 | } |
| 153 | exportedHeaders { |
| 154 | srcDirs = ['src/main/native/include'] |
| 155 | includes = ['**/*.h'] |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | binaries.all { binary -> |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 160 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 161 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 162 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 163 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
| 164 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 165 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 166 | lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared' |
| 167 | lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared' |
| 168 | project(':hal').addHalDependency(binary, 'shared') |
| 169 | project(':hal').addHalJniDependency(binary) |
| 170 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 171 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 172 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 173 | nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') |
| 174 | } else { |
| 175 | def systemArch = getCurrentArch() |
| 176 | if (binary.targetPlatform.name == systemArch) { |
| 177 | simProjects.each { |
| 178 | lib project: ":simulation:$it", library: it, linkage: 'shared' |
| 179 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 180 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 181 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | myRobotCppStatic(NativeExecutableSpec) { |
| 185 | targetBuildTypes 'debug' |
| 186 | nativeUtils.excludeBinariesFromStrip(it) |
| 187 | sources { |
| 188 | cpp { |
| 189 | source { |
| 190 | srcDirs = ['src/main/native/cpp'] |
| 191 | includes = ['**/*.cpp'] |
| 192 | } |
| 193 | exportedHeaders { |
| 194 | srcDirs = ['src/main/native/include'] |
| 195 | includes = ['**/*.h'] |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | binaries.all { binary -> |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 200 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'static' |
| 201 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static' |
| 202 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'static' |
| 203 | lib project: ':wpimath', library: 'wpimath', linkage: 'static' |
| 204 | lib project: ':ntcore', library: 'ntcore', linkage: 'static' |
| 205 | lib project: ':cscore', library: 'cscore', linkage: 'static' |
| 206 | project(':hal').addHalDependency(binary, 'static') |
| 207 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
| 208 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'static' |
| 209 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 210 | nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') |
| 211 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | tasks { |
| 216 | def c = $.components |
| 217 | project.tasks.create('runCpp', Exec) { |
| 218 | group = 'WPILib' |
| 219 | description = "Run the myRobotCpp executable" |
| 220 | def found = false |
| 221 | def systemArch = getCurrentArch() |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 222 | def runTask = it |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 223 | c.each { |
| 224 | if (it in NativeExecutableSpec && it.name == "myRobotCpp") { |
| 225 | it.binaries.each { |
| 226 | if (!found) { |
| 227 | def arch = it.targetPlatform.name |
| 228 | if (arch == systemArch) { |
| 229 | dependsOn it.tasks.install |
| 230 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 231 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 232 | run.dependsOn it.tasks.install |
| 233 | run.systemProperty 'java.library.path', filePath |
| 234 | run.environment 'LD_LIBRARY_PATH', filePath |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 235 | |
| 236 | def installTask = it.tasks.install |
| 237 | |
| 238 | def doFirstTask = { |
| 239 | def extensions = ''; |
| 240 | installTask.installDirectory.get().getAsFile().eachFileRecurse { |
| 241 | def name = it.name |
| 242 | if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) { |
| 243 | return |
| 244 | } |
| 245 | def file = it |
| 246 | simProjects.each { |
| 247 | if (name.startsWith(it) || name.startsWith("lib$it".toString())) { |
| 248 | extensions += file.absolutePath + File.pathSeparator |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | if (extensions != '') { |
| 253 | run.environment 'HALSIM_EXTENSIONS', extensions |
| 254 | runTask.environment 'HALSIM_EXTENSIONS', extensions |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | runTask.doFirst doFirstTask |
| 259 | run.doFirst doFirstTask |
| 260 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 261 | run.workingDir filePath |
| 262 | |
| 263 | found = true |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | installAthena(Task) { |
| 271 | $.binaries.each { |
| 272 | if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCpp') { |
| 273 | dependsOn it.tasks.install |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | installAthenaStatic(Task) { |
| 278 | $.binaries.each { |
| 279 | if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCppStatic') { |
| 280 | dependsOn it.tasks.install |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | } |