From a06dd25d56339b97f1d14b2b8307f4ccacf4c20b Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 6 Nov 2016 21:47:18 -0800 Subject: [PATCH] Adds cscore and opencv to wpilib (#332) Unit tests now run using shared wpilib as well, since we had to add a ton of sharedl ibraries anyway. Test scripts also updated to work properly. --- cppSettings.gradle | 57 +++++++++++ myRobot/build.gradle | 32 ++++-- myRobotCpp/build.gradle | 100 +++++++++++++------ ni-libraries/lib/libwpi.so | 2 +- test-scripts/config.sh | 4 +- test-scripts/deploy-and-run-test-on-robot.sh | 9 +- wpilibc/athena.gradle | 4 +- wpilibcIntegrationTests/build.gradle | 10 +- wpilibj/athena.gradle | 4 + wpilibjIntegrationTests/build.gradle | 38 ++++++- 10 files changed, 206 insertions(+), 54 deletions(-) diff --git a/cppSettings.gradle b/cppSettings.gradle index cc68433bdf..9df3b3107a 100644 --- a/cppSettings.gradle +++ b/cppSettings.gradle @@ -133,6 +133,43 @@ task unzipWpiUtil(type: Copy) { into wpiUtilUnzipLocation } +task downloadArmCsCore() { + description = 'Downloads the C++ ARM CsCore Uberzip maven dependency.' + group = 'WPILib' + def depFolder = "$buildDir/dependencies" + def csZip = file("$depFolder/cscore-arm.zip") + outputs.file(csZip) + def armCsCore + + doFirst { + def armCsDependency = project.dependencies.create('edu.wpi.cscore.cpp:cscore:+:athena-uberzip@zip') + def armConfig = project.configurations.detachedConfiguration(armCsDependency) + armConfig.setTransitive(false) + armCsCore = armConfig.files[0].canonicalFile + } + + doLast { + copy { + from armCsCore + rename 'cscore(.+)', 'cscore-arm.zip' + into depFolder + } + } +} + +def csCoreUnzipLocation = "$buildDir/cscore" + +// Create a task that will unzip the cscore files into a temporary build directory +task unzipCsCore(type: Copy) { + description = 'Unzips the cscore maven dependency so that the include files and libraries can be used' + group = 'WPILib' + dependsOn downloadArmCsCore + + from zipTree(downloadArmCsCore.outputs.files.singleFile) + into csCoreUnzipLocation +} + + task clean(type: Delete) { description = "Deletes the build directory" group = "Build" @@ -198,6 +235,26 @@ subprojects { addStaticWpiUtilLibraryLinks(compileTask, linker, targetPlatform) } } + + // This defines a project property that projects depending on cscore can use to setup that dependency. + ext.defineCsCoreProperties = { + ext.csCore = csCoreUnzipLocation + ext.csCoreInclude = "$csCoreUnzipLocation/include" + ext.csLibArmLocation = "$csCoreUnzipLocation/lib" + ext.csSharedLib = "$csLibArmLocation/libcscore.so" + ext.cvSharedLib = "$csLibArmLocation/libopencv.so" + + ext.addCsCoreLibraryLinks = { compileTask, linker, targetPlatform -> + compileTask.dependsOn project(':').unzipCsCore + String architecture = targetPlatform.architecture + if (architecture.contains('arm')) { + linker.args << '-L' + csLibArmLocation + linker.args csSharedLib + linker.args cvSharedLib + } + } + } + plugins.withType(CppPlugin).whenPluginAdded { // We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi- // If this ever changes, the prefix will need to be changed here diff --git a/myRobot/build.gradle b/myRobot/build.gradle index 941f6f71f4..97fc632104 100644 --- a/myRobot/build.gradle +++ b/myRobot/build.gradle @@ -19,6 +19,8 @@ dependencies { compile wpilibj compile files(wpilibj.sourceSets.test.output.classesDir) compile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' + compile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' + compile 'edu.wpi.cscore.java:cscore:+:arm' } def nativeDirectory = "$buildDir/output" @@ -30,16 +32,21 @@ clean { task copyRobotLibraries(type: Copy) { description = 'Copies all native libraries to an easy to find folder' group = 'WPILib' + destinationDir = file(nativeDirectory) dependsOn shadowJar dependsOn ':hal:build' dependsOn ':wpilibj:build' - from (shadowJar) + from (shadowJar) { + into '/' + } project(':wpilibj').model { binaries { withType(SharedLibraryBinarySpec) { spec -> - from(spec.sharedLibraryFile) + from(spec.sharedLibraryFile) { + into '/' + } } } } @@ -47,19 +54,32 @@ task copyRobotLibraries(type: Copy) { project(':hal').model { binaries { withType(SharedLibraryBinarySpec) { spec -> - from(spec.sharedLibraryFile) + from(spec.sharedLibraryFile) { + into '/' + } } } } defineNetworkTablesProperties() defineWpiUtilProperties() + defineCsCoreProperties() - from file(netSharedLib) + from (file(netSharedLib)) { + into '/' + } - from file(wpiUtilSharedLib) + from (file(wpiUtilSharedLib)) { + into '/' + } + + from (file(csLibArmLocation).path) { + include '**/*so.3.1' + include '**/libcscore.so' + include '**/libopencv_java310.so' + into '/' + } - into nativeDirectory } diff --git a/myRobotCpp/build.gradle b/myRobotCpp/build.gradle index 72bdb0a177..41b7d616a6 100644 --- a/myRobotCpp/build.gradle +++ b/myRobotCpp/build.gradle @@ -10,38 +10,6 @@ ext.hal = project(':hal').projectDir.getAbsolutePath() model { components { myRobotcpp(NativeExecutableSpec) { - targetPlatform 'arm' - binaries.all { - tasks.withType(CppCompile) { - addNiLibraryLinks(linker, targetPlatform) - addStaticNetworkTablesLibraryLinks(it, linker, targetPlatform) - } - - cppCompiler.args '-pthread', '-Wno-unused-variable' - linker.args '-pthread', '-Wno-unused-variable', '-Wl,-rpath,/opt/GenICam_v2_3/bin/Linux_armv7-a' - } - sources { - cpp { - source { - srcDir 'src' - include '**/*.cpp' - } - exportedHeaders { - srcDirs = ['include', - "${project.athena}/include", "${project.shared}/include", - "${project.hal}/include/HAL", netTablesInclude, wpiUtilInclude] - include '**/*.h' - } - - lib project: ':wpilibc', library: 'wpilibc', linkage: 'static' - lib project: ':hal', library: 'HALAthena', linkage: 'static' - } - } - } - - // Shared target used just to check that wpilib is fully linked - // Use the static target for normal linking - myRobotcppShared(NativeExecutableSpec) { targetPlatform 'arm' binaries.all { tasks.withType(CppCompile) { @@ -72,3 +40,71 @@ model { } } } + +def nativeDirectory = "$buildDir/output" + +clean { + delete nativeDirectory +} + +task copyRobotLibraries(type: Copy) { + description = 'Copies all native libraries to an easy to find folder' + group = 'WPILib' + destinationDir = file(nativeDirectory) + dependsOn ':hal:build' + dependsOn ':wpilibc:build' + dependsOn check + + project(':wpilibc').model { + binaries { + withType(SharedLibraryBinarySpec) { spec -> + from(spec.sharedLibraryFile) { + into '/' + } + } + } + } + + project.model { + binaries { + withType(NativeExecutableBinarySpec) { spec -> + from(spec.executableFile) { + into '/' + } + } + } + } + + project(':hal').model { + binaries { + withType(SharedLibraryBinarySpec) { spec -> + from(spec.sharedLibraryFile) { + into '/' + } + } + } + } + + defineNetworkTablesProperties() + defineWpiUtilProperties() + defineCsCoreProperties() + + from (file(netSharedLib)) { + into '/' + } + + from (file(wpiUtilSharedLib)) { + into '/' + } + + from (file(csLibArmLocation).path) { + include '**/*so.3.1' + include '**/libcscore.so' + include '**/libopencv_java310.so' + into '/' + } + +} + + +build.dependsOn copyRobotLibraries diff --git a/ni-libraries/lib/libwpi.so b/ni-libraries/lib/libwpi.so index 8f18a71c79..0df9e3a2fd 100644 --- a/ni-libraries/lib/libwpi.so +++ b/ni-libraries/lib/libwpi.so @@ -1,3 +1,3 @@ /* GNU ld script */ OUTPUT_FORMAT(elf32-littlearm) -GROUP ( AS_NEEDED ( -lwpilibc -lHALAthena -lntcore -lwpiutil -lnilibraries ) ) +GROUP ( AS_NEEDED ( -lwpilibc -lHALAthena -lntcore -lwpiutil -lcscore -lopencv -lnilibraries ) ) diff --git a/test-scripts/config.sh b/test-scripts/config.sh index 81ca2cb776..1d2688e1a3 100644 --- a/test-scripts/config.sh +++ b/test-scripts/config.sh @@ -34,7 +34,7 @@ DEFAULT_JAVA_TEST_ARGS="" DEFAULT_LOCAL_JAVA_TEST_FILE=../wpilibjIntegrationTests/build/libs/wpilibjIntegrationTests-all.jar JAVA_REPORT=javareport.xml -DEFAULT_LIBRARY_JAVA_FILES=../wpilibjIntegrationTests/build/nativelibraries -DEFAULT_LIBRARY_JAVA_DESTINATION=/usr/local/frc/lib +DEFAULT_LIBRARY_NATIVE_FILES=../wpilibjIntegrationTests/build/nativelibraries +DEFAULT_LIBRARY_NATIVE_DESTINATION=/usr/local/frc/lib DEFAULT_LOCAL_JAVA_TEST_RESULT=${DEFAULT_LOCAL_TEST_RESULTS_DIR}/${JAVA_REPORT} DEFAULT_DESTINATION_JAVA_TEST_RESULTS=${DEFAULT_DESTINATION_TEST_RESULTS_DIR}/AntReports/TEST-edu.wpi.first.wpilibj.test.TestSuite.xml diff --git a/test-scripts/deploy-and-run-test-on-robot.sh b/test-scripts/deploy-and-run-test-on-robot.sh index f7aad7dfc7..a4232e6816 100644 --- a/test-scripts/deploy-and-run-test-on-robot.sh +++ b/test-scripts/deploy-and-run-test-on-robot.sh @@ -76,16 +76,19 @@ SCP_TEST_SCRIPT="scp config.sh ${DEFAULT_LOCAL_RUN_TEST_SCRIPT} ${ROBOT_ADDRESS} SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR="ssh -t ${ROBOT_ADDRESS} \"chmod a+x ${DEFAULT_DESTINATION_RUN_TEST_SCRIPT}; mkdir ${DEFAULT_TEST_SCP_DIR}; touch ${DESTINATION_TEST_FILE}\"" SCP_TEST_PROGRAM="scp ${LOCAL_TEST_FILE} ${ROBOT_ADDRESS}:${DESTINATION_TEST_FILE}" SSH_RUN_TESTS="ssh -t ${ROBOT_ADDRESS} ${DEFAULT_DESTINATION_RUN_TEST_SCRIPT} ${LANGUAGE} $(whoami) ${MUTEX_OVERRIDE_PARAM_TEXT}-d ${DEFAULT_TEST_SCP_DIR} ${TEST_RUN_ARGS}" -SCP_JAVA_LIBRARIES="scp ${DEFAULT_LIBRARY_JAVA_FILES}/* ${ROBOT_ADDRESS}:${DEFAULT_LIBRARY_JAVA_DESTINATION}" +SCP_NATIVE_LIBRARIES="scp ${DEFAULT_LIBRARY_NATIVE_FILES}/* ${ROBOT_ADDRESS}:${DEFAULT_LIBRARY_NATIVE_DESTINATION}" +CONFIG_NATIVE_LIBRARIES="ssh -t ${ADMIN_ROBOT_ADDRESS} ldconfig" if [ $(which sshpass) ]; then - sshpass -p "" ${SCP_JAVA_LIBRARIES} + sshpass -p "" ${SCP_NATIVE_LIBRARIES} + sshpass -p "" ${CONFIG_NATIVE_LIBRARIES} sshpass -p "" ${SCP_TEST_SCRIPT} sshpass -p "" ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} sshpass -p "" ${SCP_TEST_PROGRAM} sshpass -p "" ${SSH_RUN_TESTS} else - eval ${SCP_JAVA_LIBRARIES} + eval ${SCP_NATIVE_LIBRARIES} + eval ${CONFIG_NATIVE_LIBRARIES} eval ${SCP_TEST_SCRIPT} eval ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} eval ${SCP_TEST_PROGRAM} diff --git a/wpilibc/athena.gradle b/wpilibc/athena.gradle index 4a16be513a..c0269ec637 100644 --- a/wpilibc/athena.gradle +++ b/wpilibc/athena.gradle @@ -1,5 +1,6 @@ defineNetworkTablesProperties() defineWpiUtilProperties() +defineCsCoreProperties() debugStripSetup(project) @@ -14,6 +15,7 @@ model { cppCompiler.args "-DNAMESPACED_WPILIB" addNiLibraryLinks(linker, targetPlatform) addNetworkTablesLibraryLinks(it, linker, targetPlatform) + addCsCoreLibraryLinks(it, linker, targetPlatform) } } sources { @@ -23,7 +25,7 @@ model { includes = ['**/*.cpp'] } exportedHeaders { - srcDirs = ["${project.shared}/include", "${project.athena}/include", netTablesInclude, wpiUtilInclude] + srcDirs = ["${project.shared}/include", "${project.athena}/include", netTablesInclude, wpiUtilInclude, csCoreInclude] includes = ['**/*.h'] } lib project: ':hal', library: 'HALAthena', linkage: 'shared' diff --git a/wpilibcIntegrationTests/build.gradle b/wpilibcIntegrationTests/build.gradle index 3ad2251107..397e22f390 100644 --- a/wpilibcIntegrationTests/build.gradle +++ b/wpilibcIntegrationTests/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'cpp' defineNetworkTablesProperties() defineWpiUtilProperties() +defineCsCoreProperties() ext.shared = "${project(':wpilibc').projectDir.getAbsolutePath()}/shared" ext.athena = "${project(':wpilibc').projectDir.getAbsolutePath()}/athena" @@ -15,7 +16,8 @@ model { tasks.withType(CppCompile) { cppCompiler.args "-DNAMESPACED_WPILIB" addNiLibraryLinks(linker, targetPlatform) - addStaticNetworkTablesLibraryLinks(it, linker, targetPlatform) + addNetworkTablesLibraryLinks(it, linker, targetPlatform) + addCsCoreLibraryLinks(it, linker, targetPlatform) } cppCompiler.args '-pthread', '-Wno-unused-variable' @@ -35,12 +37,12 @@ model { exportedHeaders { srcDirs = ['include', 'gtest', 'gtest/include', "${project.athena}/include", "${project.shared}/include", - "${project.hal}/include/HAL", netTablesInclude] + "${project.hal}/include/HAL", netTablesInclude, wpiUtilInclude, csCoreInclude] include '**/*.h' } - lib project: ':wpilibc', library: 'wpilibc', linkage: 'static' - lib project: ':hal', library: 'HALAthena', linkage: 'static' + lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' + lib project: ':hal', library: 'HALAthena', linkage: 'shared' } } } diff --git a/wpilibj/athena.gradle b/wpilibj/athena.gradle index 2e35c961ec..cb7620f140 100644 --- a/wpilibj/athena.gradle +++ b/wpilibj/athena.gradle @@ -14,6 +14,10 @@ dependencies { athenaCompile sourceSets.shared.output athenaCompile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' athenaRuntime 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' + athenaCompile 'edu.wpi.cscore.java:cscore:+:arm' + athenaRuntime 'edu.wpi.cscore.java:cscore:+:arm' + athenaCompile 'org.opencv:opencv-java:+' + athenaRuntime 'org.opencv:opencv-java:+' } defineWpiUtilProperties() diff --git a/wpilibjIntegrationTests/build.gradle b/wpilibjIntegrationTests/build.gradle index 3332410bfb..4688697f5c 100644 --- a/wpilibjIntegrationTests/build.gradle +++ b/wpilibjIntegrationTests/build.gradle @@ -19,6 +19,8 @@ dependencies { compile wpilibj compile files(wpilibj.sourceSets.test.output.classesDir) compile 'edu.wpi.first.wpilib.networktables.java:NetworkTables:+:arm' + compile 'edu.wpi.cscore.java:cscore:+:arm' + compile 'org.opencv:opencv-java:+' compile 'junit:junit:4.11' compile 'com.googlecode.junit-toolbox:junit-toolbox:2.0' compile 'org.apache.ant:ant:1.9.4' @@ -36,14 +38,28 @@ clean { task copyIntegrationLibraries(type: Copy) { description = 'Copies all native libraries to an easy to find folder' group = 'WPILib' + destinationDir = file(nativeDirectory) dependsOn shadowJar dependsOn ':hal:build' dependsOn ':wpilibj:build' + dependsOn ':wpilibc:build' project(':wpilibj').model { binaries { withType(SharedLibraryBinarySpec) { spec -> - from(spec.sharedLibraryFile) + from(spec.sharedLibraryFile) { + into '/' + } + } + } + } + + project(':wpilibc').model { + binaries { + withType(SharedLibraryBinarySpec) { spec -> + from(spec.sharedLibraryFile) { + into '/' + } } } } @@ -51,19 +67,31 @@ task copyIntegrationLibraries(type: Copy) { project(':hal').model { binaries { withType(SharedLibraryBinarySpec) { spec -> - from(spec.sharedLibraryFile) + from(spec.sharedLibraryFile) { + into '/' + } } } } defineNetworkTablesProperties() defineWpiUtilProperties() + defineCsCoreProperties() - from file(netSharedLib) + from (file(netSharedLib)) { + into '/' + } - from file(wpiUtilSharedLib) + from (file(wpiUtilSharedLib)) { + into '/' + } - into nativeDirectory + from (file(csLibArmLocation).path) { + include '**/*so.3.1' + include '**/libcscore.so' + include '**/libopencv_java310.so' + into '/' + } } compileJava.dependsOn tasks.getByPath(':wpilibj:testClasses')