diff --git a/photon-core/build.gradle b/photon-core/build.gradle index b1b5377f3..a63354dcb 100644 --- a/photon-core/build.gradle +++ b/photon-core/build.gradle @@ -61,9 +61,6 @@ dependencies { } testImplementation group: 'org.junit-pioneer' , name: 'junit-pioneer', version: '2.2.0' - - // Include photon-targeting JNI - implementation(project(path: ':photon-targeting', configuration: 'archives')) } task writeCurrentVersion { diff --git a/photon-server/build.gradle b/photon-server/build.gradle index 99375bb59..943ab9e9a 100644 --- a/photon-server/build.gradle +++ b/photon-server/build.gradle @@ -29,6 +29,7 @@ shadowJar { configurations = [ project.configurations.runtimeClasspath ] + println configurations } node { diff --git a/photon-targeting/build.gradle b/photon-targeting/build.gradle index 640e95ffb..d3f42bba8 100644 --- a/photon-targeting/build.gradle +++ b/photon-targeting/build.gradle @@ -25,16 +25,18 @@ sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" apply plugin: 'edu.wpi.first.GradleJni' -// Dummy jar for our .sos -task nativeLibsJar(type: Jar) { - archiveClassifier = 'native-libs' - build.dependsOn it -} +// Folder whose contents will be included in the final jar +def outputsFolder = file("$buildDir/outputs") -artifacts { - archives nativeLibsJar +// Sync task: like the copy task, but all files that exist in the destination directory will be deleted before copying files +task syncOutputsFolder(type: Sync) { + into outputsFolder } +jar { + from outputsFolder + dependsOn syncOutputsFolder +} model { components { @@ -98,7 +100,7 @@ model { // only include release binaries (hard coded for now) def isDebug = binary.buildType.name.contains('debug') if (!isDebug) { - nativeLibsJar { + syncOutputsFolder { // Just shove the shared library into the root of the jar output by photon-targeting:jar from(binary.sharedLibraryFile) { into "nativelibraries/${wpilibNativeName}/" @@ -188,7 +190,8 @@ cppHeadersZip { // make sure native libraries can be loaded in tests test { - classpath += files(nativeLibsJar.archiveFile) + classpath += files(outputsFolder) + dependsOn syncOutputsFolder } // setup wpilib bundled native libs @@ -201,7 +204,7 @@ def nativeTasks = wpilibTools.createExtractionTasks { configurationName = nativeConfigName } -nativeTasks.addToSourceSetResources(sourceSets.main) +nativeTasks.addToSourceSetResources(sourceSets.test) nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath") nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet") diff --git a/photon-targeting/src/main/java/org/photonvision/jni/TimeSyncJNILoader.java b/photon-targeting/src/main/java/org/photonvision/jni/TimeSyncJNILoader.java index 0d19ef753..042b5889b 100644 --- a/photon-targeting/src/main/java/org/photonvision/jni/TimeSyncJNILoader.java +++ b/photon-targeting/src/main/java/org/photonvision/jni/TimeSyncJNILoader.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.photonvision.jni; import java.io.File; @@ -6,7 +23,6 @@ import java.util.List; public class TimeSyncJNILoader { - public static void load() throws IOException { // We always extract the shared object (we could hash each so, but that's a lot // of work) @@ -14,7 +30,6 @@ public static void load() throws IOException { var clazz = TimeSyncJNILoader.class; for (var libraryName : List.of("photontargeting", "photontargetingJNI")) { - var nativeLibName = System.mapLibraryName(libraryName); var in = clazz.getResourceAsStream("/nativelibraries/" + arch_name + "/" + nativeLibName); diff --git a/photon-targeting/src/main/native/cpp/net/TimeSyncClientServer.cpp b/photon-targeting/src/main/native/cpp/net/TimeSyncClientServer.cpp index 96a41a8f0..749af13e9 100644 --- a/photon-targeting/src/main/native/cpp/net/TimeSyncClientServer.cpp +++ b/photon-targeting/src/main/native/cpp/net/TimeSyncClientServer.cpp @@ -209,7 +209,7 @@ void wpi::TimeSyncClient::Tick() { int sent = 0; try { sent = m_udp->TrySend(wpi::SmallVector{pingBuf}); - } catch (std::exception & e) { + } catch (std::exception& e) { fmt::println("????: {}", e.what()); return; } diff --git a/photon-targeting/src/test/java/net/TimeSyncTest.java b/photon-targeting/src/test/java/net/TimeSyncTest.java index b9183dc10..367a240ff 100644 --- a/photon-targeting/src/test/java/net/TimeSyncTest.java +++ b/photon-targeting/src/test/java/net/TimeSyncTest.java @@ -1,14 +1,24 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.IOException; -import org.junit.jupiter.api.Test; -import org.opencv.core.Core; -import org.photonvision.jni.TimeSyncClient; -import org.photonvision.jni.TimeSyncJNILoader; -import org.photonvision.jni.TimeSyncServer; - import edu.wpi.first.apriltag.jni.AprilTagJNI; import edu.wpi.first.cscore.CameraServerCvJNI; import edu.wpi.first.cscore.CameraServerJNI; @@ -19,6 +29,12 @@ import edu.wpi.first.networktables.NetworkTablesJNI; import edu.wpi.first.util.CombinedRuntimeLoader; 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.TimeSyncClient; +import org.photonvision.jni.TimeSyncJNILoader; +import org.photonvision.jni.TimeSyncServer; public class TimeSyncTest { public static void load_wpilib() { @@ -49,13 +65,12 @@ public static void load_wpilib() { @Test public void smoketest() throws InterruptedException { - // for (var line : System.getProperty("java.class.path", ".").split(";")) { // System.out.println(line); // } try { - load_wpilib(); + load_wpilib(); TimeSyncJNILoader.load(); } catch (IOException e) { assertTrue(false); diff --git a/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp b/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp index 1d33f25be..8faa4f1b4 100644 --- a/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp +++ b/photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp @@ -1,10 +1,22 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include +#include TEST(TimeSyncProtocolTest, TestClient) { using namespace wpi;