From be12be1dec1e529678bcad2aa595a6d1fecc3229 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 20 Sep 2024 18:06:29 -0700 Subject: [PATCH] Actually use outputs folder --- photon-core/build.gradle | 3 -- photon-server/build.gradle | 1 + photon-targeting/build.gradle | 23 +++++++------ .../photonvision/jni/TimeSyncJNILoader.java | 19 +++++++++-- .../native/cpp/net/TimeSyncClientServer.cpp | 2 +- .../src/test/java/net/TimeSyncTest.java | 33 ++++++++++++++----- .../src/test/native/cpp/net/TimeSyncTest.cpp | 22 ++++++++++--- 7 files changed, 73 insertions(+), 30 deletions(-) diff --git a/photon-core/build.gradle b/photon-core/build.gradle index b1b5377f3c..a63354dcb6 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 99375bb599..943ab9e9a0 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 640e95ffb4..d3f42bba89 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 0d19ef7533..042b5889b8 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 96a41a8f04..749af13e94 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 b9183dc103..367a240ff5 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 1d33f25be3..8faa4f1b45 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;