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 = [developerRobotCpp: []] staticCvConfigs = [developerRobotCppStatic: []] useJava = true useCpp = true skipDev = true } apply from: "${rootDir}/shared/opencv.gradle" application { mainClass = 'frc.robot.Main' } apply plugin: 'com.gradleup.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') implementation project(':wpiunits') implementation project(':epilogue-runtime') annotationProcessor project(':epilogue-processor') } tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { onlyIf { false } } def simProjects = ['halsim_gui'] deploy { targets { systemcore(RemoteTarget) { directory = '/home/systemcore' maxChannels = 4 locations { ssh(SshDeployLocation) { address = "limelight.local" user = 'systemcore' password = 'systemcore' ipv6 = false } } timeout = 7 def remote = it artifacts { all { postdeploy << { ctx -> ctx.execute("sync") ctx.execute("sudo ldconfig /home/systemcore/frc/third-party/lib") } } developerRobotCpp(NativeExecutableArtifact) { libraryDirectory = '/home/systemcore/frc/third-party/lib' def excludes = getLibraryFilter().getExcludes() excludes.add('**/*.so.debug') excludes.add('**/*.so.*.debug') postdeploy << { ctx -> ctx.execute("echo 'LD_LIBRARY_PATH=/home/systemcore/frc/third-party/lib /home/systemcore/developerRobotCpp' > /home/systemcore/robotCommand") ctx.execute("chmod +x /home/systemcore/robotCommand; chown systemcore /home/systemcore/robotCommand") ctx.execute("setcap cap_sys_nice+eip \"/home/systemcore/developerRobotCpp\"") ctx.execute('chmod +x developerRobotCpp') } } developerRobotCppStatic(NativeExecutableArtifact) { libraryDirectory = '/home/systemcore/frc/third-party/lib' postdeploy << { ctx -> ctx.execute("echo ''LD_LIBRARY_PATH=/home/systemcore/frc/third-party/lib /home/systemcore/developerRobotCppStatic' > /home/systemcore/robotCommand") ctx.execute("chmod +x /home/systemcore/robotCommand; chown systemcore /home/systemcore/robotCommand") ctx.execute("sudo setcap cap_sys_nice+eip \"/home/systemcore/developerRobotCppStatic\"") ctx.execute('chmod +x developerRobotCppStatic') } } developerRobotCppJava(NativeExecutableArtifact) { libraryDirectory = '/home/systemcore/frc/third-party/lib' def excludes = getLibraryFilter().getExcludes() excludes.add('**/*.so.debug') excludes.add('**/*.so.*.debug') } developerRobotJava(JavaArtifact) { jarTask = shadowJar postdeploy << { ctx -> ctx.execute("echo '/usr/bin/java -XX:+UseG1GC -Djava.library.path=/home/systemcore/frc/third-party/lib -jar /home/systemcore/developerRobot-all.jar' > /home/systemcore/robotCommand") ctx.execute("chmod +x /home/systemcore/robotCommand; chown systemcore /home/systemcore/robotCommand") } } } } } } // Prevent the eclipse compiler (used by the VS Code extension for intellisense and debugging) // from generating bad class files from annotation processors like Epilogue eclipse { classpath { containers 'org.eclipse.buildship.core.gradleclasspathcontainer' file.whenMerged { cp -> def entries = cp.entries; def src = new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/generated/sources/annotationProcessor/java/main/', null) entries.add(src) } } } tasks.register('deployJava') { try { dependsOn tasks.named('deploydeveloperRobotJavasystemcore') dependsOn tasks.named('deploydeveloperRobotCppJavasystemcore') // Deploying shared C++ is how to get the Java shared libraries. } catch (ignored) { } } tasks.register('deployShared') { try { dependsOn tasks.named('deploydeveloperRobotCppsystemcore') } catch (ignored) { } } tasks.register('deployStatic') { try { dependsOn tasks.named('deploydeveloperRobotCppStaticsystemcore') } catch (ignored) { } } model { components { developerRobotCpp(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.systemcore) { if (binary.buildType.name == 'debug') { deploy.targets.systemcore.artifacts.developerRobotCpp.binary = binary deploy.targets.systemcore.artifacts.developerRobotCppJava.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' def systemArch = getCurrentArch() if (binary.targetPlatform.name == systemArch) { simProjects.each { lib project: ":simulation:$it", library: it, linkage: 'shared' } } } } developerRobotCppStatic(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.systemcore) { if (binary.buildType.name == 'debug') { deploy.targets.systemcore.artifacts.developerRobotCppStatic.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' } } } tasks { def c = $.components project.tasks.create('runCpp', Exec) { group = 'WPILib' description = "Run the developerRobotCpp executable" def found = false def systemArch = getCurrentArch() def runTask = it c.each { if (it in NativeExecutableSpec && it.name == "developerRobotCpp") { 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 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 found = true } } } } } } installSystemCore(Task) { $.binaries.each { if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.systemcore && it.component.name == 'developerRobotCpp') { dependsOn it.tasks.install } } } installSystemCoreStatic(Task) { $.binaries.each { if (it in NativeExecutableBinarySpec && it.targetPlatform.name == nativeUtils.wpi.platforms.systemcore && it.component.name == 'developerRobotCppStatic') { dependsOn it.tasks.install } } } } }