blob: 4d6bb2673cc4bd2e919f60147bf76fa9b9ca1a45 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001import jaci.gradle.toolchains.*
2import jaci.gradle.nativedeps.*
Austin Schuh1e69f942020-11-14 15:06:14 -08003import org.gradle.internal.os.OperatingSystem
Brian Silverman8fce7482020-01-05 13:18:21 -08004
5plugins {
6 id 'java'
7 id 'application'
8 id 'cpp'
9 id 'visual-studio'
10}
11
12apply plugin: 'edu.wpi.first.NativeUtils'
13apply plugin: 'jaci.gradle.EmbeddedTools'
14
15apply from: '../shared/config.gradle'
16
Austin Schuh1e69f942020-11-14 15:06:14 -080017application {
18 if (OperatingSystem.current().isMacOsX()) {
19 applicationDefaultJvmArgs = ['-XstartOnFirstThread']
20 }
21}
22
Brian Silverman8fce7482020-01-05 13:18:21 -080023ext {
24 sharedCvConfigs = [myRobotCpp: []]
25 staticCvConfigs = [myRobotCppStatic: []]
26 useJava = true
27 useCpp = true
28 skipDev = true
29}
30
31apply from: "${rootDir}/shared/opencv.gradle"
32
33deploy {
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
95tasks.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
104tasks.register('deployShared') {
105 try {
106 dependsOn tasks.named('deployMyRobotCppLibrariesRoborio')
107 dependsOn tasks.named('deployMyRobotCppRoborio')
108 } catch (ignored) {
109 }
110}
111
112tasks.register('deployStatic') {
113 try {
114 dependsOn tasks.named('deployMyRobotCppStaticRoborio')
115 } catch (ignored) {
116 }
117}
118
Austin Schuh1e69f942020-11-14 15:06:14 -0800119mainClassName = 'frc.robot.Main'
Brian Silverman8fce7482020-01-05 13:18:21 -0800120
121apply plugin: 'com.github.johnrengelman.shadow'
122
123repositories {
124 mavenCentral()
125}
126
127dependencies {
128 implementation project(':wpilibj')
Austin Schuh1e69f942020-11-14 15:06:14 -0800129 implementation project(':wpimath')
Brian Silverman8fce7482020-01-05 13:18:21 -0800130 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 Schuh1e69f942020-11-14 15:06:14 -0800139def simProjects = [
140 'halsim_gui'
141]
142
Brian Silverman8fce7482020-01-05 13:18:21 -0800143model {
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 Schuh1e69f942020-11-14 15:06:14 -0800160 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 Silverman8fce7482020-01-05 13:18:21 -0800180 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800181 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800182 }
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 Schuh1e69f942020-11-14 15:06:14 -0800200 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 Silverman8fce7482020-01-05 13:18:21 -0800212 }
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 Schuh1e69f942020-11-14 15:06:14 -0800222 def runTask = it
Brian Silverman8fce7482020-01-05 13:18:21 -0800223 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 Schuh1e69f942020-11-14 15:06:14 -0800235
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 Silverman8fce7482020-01-05 13:18:21 -0800261 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}