From 1c4cdb35bb5340d55daae67f5580690efac7f256 Mon Sep 17 00:00:00 2001 From: Matt Morley Date: Sun, 22 Sep 2024 10:10:29 -0700 Subject: [PATCH] Only link to stuff I need --- .../org/photonvision/PhotonCameraTest.java | 5 -- photon-targeting/build.gradle | 57 ++++++++++--------- .../src/main/native/jni/TimeSyncClientJNI.cpp | 4 -- .../src/main/native/jni/TimeSyncServerJNI.cpp | 4 -- .../src/test/java/net/TimeSyncTest.java | 11 +--- .../src/test/native/cpp/net/TimeSyncTest.cpp | 2 +- 6 files changed, 33 insertions(+), 50 deletions(-) diff --git a/photon-lib/src/test/java/org/photonvision/PhotonCameraTest.java b/photon-lib/src/test/java/org/photonvision/PhotonCameraTest.java index 4f69732207..fb00ce324e 100644 --- a/photon-lib/src/test/java/org/photonvision/PhotonCameraTest.java +++ b/photon-lib/src/test/java/org/photonvision/PhotonCameraTest.java @@ -27,22 +27,17 @@ import edu.wpi.first.apriltag.jni.AprilTagJNI; import edu.wpi.first.cscore.CameraServerCvJNI; import edu.wpi.first.cscore.CameraServerJNI; -import edu.wpi.first.hal.HAL; import edu.wpi.first.hal.JNIWrapper; import edu.wpi.first.math.WPIMathJNI; import edu.wpi.first.net.WPINetJNI; -import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.networktables.NetworkTablesJNI; import edu.wpi.first.util.CombinedRuntimeLoader; import edu.wpi.first.util.WPIUtilJNI; -import edu.wpi.first.wpilibj.Timer; import java.io.IOException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.opencv.core.Core; import org.photonvision.common.dataflow.structures.Packet; -import org.photonvision.jni.PhotonTargetingJniLoader; -import org.photonvision.jni.TimeSyncServer; import org.photonvision.targeting.PhotonPipelineResult; class PhotonCameraTest { diff --git a/photon-targeting/build.gradle b/photon-targeting/build.gradle index 5311c58a12..6fa06b8629 100644 --- a/photon-targeting/build.gradle +++ b/photon-targeting/build.gradle @@ -25,6 +25,28 @@ sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" apply plugin: 'edu.wpi.first.GradleJni' +// explicitly specify the opencv libraries linked to by nativeUtils.useRequiredLibrary(it, "opencv_shared") +def OPENCV_LIBRARIES_TO_EXCLUDE = [ + "**/libopencv_core.so.*", + "**/libopencv_stitching.so.*", + "**/libopencv_dnn.so.*", + "**/libopencv_photo.so.*", + "**/libopencv_video.so.*", + "**/libopencv_flann.so.*", + "**/libopencv_ml.so.*", + "**/libopencv_calib3d.so.*", + "**/libopencv_imgproc.so.*", + "**/libopencv_objdetect.so.*", + "**/libopencv_videoio.so.*", + "**/libopencv_highgui.so.*", + "**/libopencv_aruco.so.*", + "**/libopencv_gapi.so.*", + "**/libopencv_features2d.so.*", + "**/libopencv_imgcodecs.so.*", +] +nativeUtils.nativeDependencyContainer.getByName("opencv_shared").extraSharedExcludes.addAll(OPENCV_LIBRARIES_TO_EXCLUDE) +println nativeUtils.nativeDependencyContainer.getByName("opencv_shared").extraSharedExcludes.get() + // Folder whose contents will be included in the final jar def outputsFolder = file("$buildDir/extra_resources") @@ -63,9 +85,11 @@ model { } } - nativeUtils.useRequiredLibrary(it, "wpilib_shared") - nativeUtils.useRequiredLibrary(it, "apriltag_shared") - nativeUtils.useRequiredLibrary(it, "opencv_shared") + nativeUtils.useRequiredLibrary(it, "wpiutil_shared") + nativeUtils.useRequiredLibrary(it, "wpimath_shared") + nativeUtils.useRequiredLibrary(it, "wpinet_shared") + nativeUtils.useRequiredLibrary(it, "wpilibc_shared") + nativeUtils.useRequiredLibrary(it, "ntcore_shared") } "${nativeName}JNI"(JniNativeLibrarySpec) { @@ -88,8 +112,9 @@ model { lib library: nativeName, linkage: 'shared' } - nativeUtils.useRequiredLibrary(it, "opencv_shared") - nativeUtils.useRequiredLibrary(it, "wpilib_shared") + nativeUtils.useRequiredLibrary(it, "wpiutil_shared") + nativeUtils.useRequiredLibrary(it, "wpinet_shared") + nativeUtils.useRequiredLibrary(it, "ntcore_shared") } all { @@ -112,7 +137,6 @@ model { } } } - } testSuites { "${nativeName}Test"(GoogleTestTestSuiteSpec) { @@ -140,25 +164,9 @@ model { } } - nativeUtils.useRequiredLibrary(it, "cscore_shared") - nativeUtils.useRequiredLibrary(it, "cameraserver_shared") nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared") nativeUtils.useRequiredLibrary(it, "googletest_static") nativeUtils.useRequiredLibrary(it, "apriltag_shared") - nativeUtils.useRequiredLibrary(it, "opencv_shared") - } - } - - binaries { - withType(NativeBinarySpec).all { - if (it.toolChain instanceof VisualCpp) { - // TODO - } - - if (it.toolChain instanceof GccCompatibleToolChain) { - // Ends up appending this flag, not prepending - it.linker.args '-Wl,--as-needed' - } } } @@ -220,11 +228,8 @@ def nativeTasks = wpilibTools.createExtractionTasks { nativeTasks.addToSourceSetResources(sourceSets.test) +nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil") nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath") nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet") -nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil") nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore") -nativeConfig.dependencies.add wpilibTools.deps.wpilib("cscore") -nativeConfig.dependencies.add wpilibTools.deps.wpilib("apriltag") nativeConfig.dependencies.add wpilibTools.deps.wpilib("hal") -nativeConfig.dependencies.add wpilibTools.deps.wpilibOpenCv("frc" + wpi.frcYear.get(), wpi.versions.opencvVersion.get()) diff --git a/photon-targeting/src/main/native/jni/TimeSyncClientJNI.cpp b/photon-targeting/src/main/native/jni/TimeSyncClientJNI.cpp index 0d126727a8..a7c197295c 100644 --- a/photon-targeting/src/main/native/jni/TimeSyncClientJNI.cpp +++ b/photon-targeting/src/main/native/jni/TimeSyncClientJNI.cpp @@ -20,10 +20,6 @@ #include #include -#include -#include -#include - #include "net/TimeSyncClientServer.h" using namespace wpi; diff --git a/photon-targeting/src/main/native/jni/TimeSyncServerJNI.cpp b/photon-targeting/src/main/native/jni/TimeSyncServerJNI.cpp index fdb5f44591..42a4f088b1 100644 --- a/photon-targeting/src/main/native/jni/TimeSyncServerJNI.cpp +++ b/photon-targeting/src/main/native/jni/TimeSyncServerJNI.cpp @@ -20,10 +20,6 @@ #include -#include -#include -#include - #include "net/TimeSyncClientServer.h" using namespace wpi; diff --git a/photon-targeting/src/test/java/net/TimeSyncTest.java b/photon-targeting/src/test/java/net/TimeSyncTest.java index 52badad8e4..162087cd56 100644 --- a/photon-targeting/src/test/java/net/TimeSyncTest.java +++ b/photon-targeting/src/test/java/net/TimeSyncTest.java @@ -31,7 +31,6 @@ import edu.wpi.first.util.WPIUtilJNI; import java.io.IOException; import org.junit.jupiter.api.Test; -import org.opencv.core.Core; import org.photonvision.jni.PhotonTargetingJniLoader; import org.photonvision.jni.TimeSyncClient; import org.photonvision.jni.TimeSyncServer; @@ -49,15 +48,7 @@ public static void load_wpilib() { try { CombinedRuntimeLoader.loadLibraries( - TimeSyncTest.class, - "wpiutiljni", - "wpimathjni", - "ntcorejni", - "wpinetjni", - "wpiHaljni", - "cscorejni", - "apriltagjni"); - CombinedRuntimeLoader.loadLibraries(TimeSyncTest.class, Core.NATIVE_LIBRARY_NAME); + TimeSyncTest.class, "wpiutiljni", "wpimathjni", "wpinetjni", "ntcorejni", "wpiHaljni"); } catch (IOException e) { e.printStackTrace(); } diff --git a/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp b/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp index 0a59add840..04a3509db6 100644 --- a/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp +++ b/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp @@ -30,7 +30,7 @@ TEST(TimeSyncProtocolTest, TestClient) { server.Start(); for (int i = 0; i < 10; i++) { - std::this_thread::sleep_for(1000ms); + std::this_thread::sleep_for(50ms); // busywait }