| import edu.wpi.first.deployutils.deploy.target.RemoteTarget |
| import edu.wpi.first.deployutils.deploy.target.location.SshDeployLocation |
| import edu.wpi.first.deployutils.deploy.artifact.* |
| import org.gradle.internal.os.OperatingSystem |
| |
| plugins { |
| id 'java' |
| id 'application' |
| id 'cpp' |
| id 'visual-studio' |
| } |
| |
| apply plugin: 'edu.wpi.first.NativeUtils' |
| apply plugin: 'edu.wpi.first.DeployUtils' |
| |
| apply from: '../shared/config.gradle' |
| |
| application { |
| if (OperatingSystem.current().isMacOsX()) { |
| applicationDefaultJvmArgs = ['-XstartOnFirstThread'] |
| } |
| } |
| |
| ext { |
| sharedCvConfigs = [myRobotCpp: []] |
| staticCvConfigs = [myRobotCppStatic: []] |
| useJava = true |
| useCpp = true |
| skipDev = true |
| } |
| |
| apply from: "${rootDir}/shared/opencv.gradle" |
| |
| application { |
| mainClass = 'frc.robot.Main' |
| } |
| |
| apply plugin: 'com.github.johnrengelman.shadow' |
| |
| repositories { |
| maven { |
| url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn' |
| } |
| } |
| |
| dependencies { |
| implementation project(':wpilibj') |
| implementation project(':wpimath') |
| implementation project(':hal') |
| implementation project(':wpiutil') |
| implementation project(':wpinet') |
| implementation project(':ntcore') |
| implementation project(':cscore') |
| implementation project(':cameraserver') |
| implementation project(':wpilibNewCommands') |
| implementation project(':apriltag') |
| } |
| |
| tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { |
| onlyIf { false } |
| } |
| |
| def simProjects = ['halsim_gui'] |
| |
| deploy { |
| targets { |
| roborio(RemoteTarget) { |
| directory = '/home/lvuser' |
| maxChannels = 4 |
| locations { |
| ssh(SshDeployLocation) { |
| address = "172.22.11.2" |
| user = 'admin' |
| password = '' |
| ipv6 = false |
| } |
| } |
| |
| def remote = it |
| |
| artifacts.registerFactory(WPIJREArtifact) { |
| return objects.newInstance(WPIJREArtifact, it, remote) |
| } |
| |
| artifacts { |
| all { |
| predeploy << { ctx -> |
| ctx.execute('. /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t 2> /dev/null') |
| ctx.execute("sed -i -e 's/\"exec /\"/' /usr/local/frc/bin/frcRunRobot.sh") |
| } |
| postdeploy << { ctx -> |
| ctx.execute("sync") |
| ctx.execute("ldconfig") |
| } |
| } |
| |
| myRobotCpp(NativeExecutableArtifact) { |
| libraryDirectory = '/usr/local/frc/third-party/lib' |
| def excludes = getLibraryFilter().getExcludes() |
| excludes.add('**/*.so.debug') |
| excludes.add('**/*.so.*.debug') |
| postdeploy << { ctx -> |
| ctx.execute("echo '/home/lvuser/myRobotCpp' > /home/lvuser/robotCommand") |
| ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand") |
| ctx.execute("setcap cap_sys_nice+eip \"/home/lvuser/myRobotCpp\"") |
| ctx.execute('chmod +x myRobotCpp') |
| } |
| } |
| |
| myRobotCppStatic(NativeExecutableArtifact) { |
| libraryDirectory = '/usr/local/frc/third-party/lib' |
| postdeploy << { ctx -> |
| ctx.execute("echo '/home/lvuser/myRobotCppStatic' > /home/lvuser/robotCommand") |
| ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand") |
| ctx.execute("setcap cap_sys_nice+eip \"/home/lvuser/myRobotCppStatic\"") |
| ctx.execute('chmod +x myRobotCppStatic') |
| } |
| } |
| |
| myRobotCppJava(NativeExecutableArtifact) { |
| libraryDirectory = '/usr/local/frc/third-party/lib' |
| def excludes = getLibraryFilter().getExcludes() |
| excludes.add('**/*.so.debug') |
| excludes.add('**/*.so.*.debug') |
| } |
| |
| jre(WPIJREArtifact) { |
| } |
| |
| myRobotJava(JavaArtifact) { |
| jarTask = shadowJar |
| postdeploy << { ctx -> |
| 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") |
| ctx.execute("chmod +x /home/lvuser/robotCommand; chown lvuser /home/lvuser/robotCommand") |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| tasks.register('deployJava') { |
| try { |
| dependsOn tasks.named('deployjreroborio') |
| dependsOn tasks.named('deploymyRobotJavaroborio') |
| dependsOn tasks.named('deploymyRobotCppJavaroborio') // Deploying shared C++ is how to get the Java shared libraries. |
| } catch (ignored) { |
| } |
| } |
| |
| tasks.register('deployShared') { |
| try { |
| dependsOn tasks.named('deploymyRobotCpproborio') |
| } catch (ignored) { |
| } |
| } |
| |
| tasks.register('deployStatic') { |
| try { |
| dependsOn tasks.named('deploymyRobotCppStaticroborio') |
| } catch (ignored) { |
| } |
| } |
| |
| model { |
| components { |
| myRobotCpp(NativeExecutableSpec) { |
| targetBuildTypes 'debug' |
| sources { |
| cpp { |
| source { |
| srcDirs = ['src/main/native/cpp'] |
| includes = ['**/*.cpp'] |
| } |
| exportedHeaders { |
| srcDirs = ['src/main/native/include'] |
| includes = ['**/*.h'] |
| } |
| } |
| } |
| binaries.all { binary -> |
| if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| if (binary.buildType.name == 'debug') { |
| deploy.targets.roborio.artifacts.myRobotCpp.binary = binary |
| deploy.targets.roborio.artifacts.myRobotCppJava.binary = binary |
| } |
| } |
| lib project: ':apriltag', library: 'apriltag', linkage: 'shared' |
| lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
| lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| project(':ntcore').addNtcoreDependency(binary, 'shared') |
| project(':ntcore').addNtcoreJniDependency(binary) |
| lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared' |
| lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared' |
| lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared' |
| lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
| project(':hal').addHalDependency(binary, 'shared') |
| project(':hal').addHalJniDependency(binary) |
| lib project: ':wpinet', library: 'wpinet', linkage: 'shared' |
| lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
| } else { |
| def systemArch = getCurrentArch() |
| if (binary.targetPlatform.name == systemArch) { |
| simProjects.each { |
| lib project: ":simulation:$it", library: it, linkage: 'shared' |
| } |
| } |
| } |
| } |
| } |
| myRobotCppStatic(NativeExecutableSpec) { |
| targetBuildTypes 'debug' |
| nativeUtils.excludeBinariesFromStrip(it) |
| sources { |
| cpp { |
| source { |
| srcDirs = ['src/main/native/cpp'] |
| includes = ['**/*.cpp'] |
| } |
| exportedHeaders { |
| srcDirs = ['src/main/native/include'] |
| includes = ['**/*.h'] |
| } |
| } |
| } |
| binaries.all { binary -> |
| if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| if (binary.buildType.name == 'debug') { |
| deploy.targets.roborio.artifacts.myRobotCppStatic.binary = binary |
| } |
| } |
| lib project: ':apriltag', library: 'apriltag', linkage: 'static' |
| lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'static' |
| lib project: ':wpilibc', library: 'wpilibc', linkage: 'static' |
| lib project: ':wpimath', library: 'wpimath', linkage: 'static' |
| lib project: ':cameraserver', library: 'cameraserver', linkage: 'static' |
| project(':ntcore').addNtcoreDependency(binary, 'static') |
| lib project: ':cscore', library: 'cscore', linkage: 'static' |
| project(':hal').addHalDependency(binary, 'static') |
| lib project: ':wpinet', library: 'wpinet', linkage: 'static' |
| lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
| if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
| } |
| } |
| } |
| } |
| tasks { |
| def c = $.components |
| project.tasks.create('runCpp', Exec) { |
| group = 'WPILib' |
| description = "Run the myRobotCpp executable" |
| def found = false |
| def systemArch = getCurrentArch() |
| def runTask = it |
| c.each { |
| if (it in NativeExecutableSpec && it.name == "myRobotCpp") { |
| it.binaries.each { |
| if (!found) { |
| def arch = it.targetPlatform.name |
| if (arch == systemArch) { |
| dependsOn it.tasks.install |
| commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| run.dependsOn it.tasks.install |
| run.systemProperty 'java.library.path', filePath |
| run.environment 'LD_LIBRARY_PATH', filePath |
| run.environment 'DYLD_LIBRARY_PATH', filePath |
| |
| def installTask = it.tasks.install |
| |
| def doFirstTask = { |
| def extensions = ''; |
| installTask.installDirectory.get().getAsFile().eachFileRecurse { |
| def name = it.name |
| if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) { |
| return |
| } |
| def file = it |
| simProjects.each { |
| if (name.startsWith(it) || name.startsWith("lib$it".toString())) { |
| extensions += file.absolutePath + File.pathSeparator |
| } |
| } |
| } |
| if (extensions != '') { |
| run.environment 'HALSIM_EXTENSIONS', extensions |
| runTask.environment 'HALSIM_EXTENSIONS', extensions |
| } |
| } |
| |
| runTask.doFirst doFirstTask |
| run.doFirst doFirstTask |
| |
| run.workingDir filePath |
| |
| found = true |
| } |
| } |
| } |
| } |
| } |
| } |
| installAthena(Task) { |
| $.binaries.each { |
| if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCpp') { |
| dependsOn it.tasks.install |
| } |
| } |
| } |
| installAthenaStatic(Task) { |
| $.binaries.each { |
| if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio && it.component.name == 'myRobotCppStatic') { |
| dependsOn it.tasks.install |
| } |
| } |
| } |
| } |
| } |