Skip to content

Commit

Permalink
Actually use outputs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Sep 21, 2024
1 parent a4ba343 commit be12be1
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 30 deletions.
3 changes: 0 additions & 3 deletions photon-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions photon-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ shadowJar {
configurations = [
project.configurations.runtimeClasspath
]
println configurations
}

node {
Expand Down
23 changes: 13 additions & 10 deletions photon-targeting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}/"
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

package org.photonvision.jni;

import java.io.File;
Expand All @@ -6,15 +23,13 @@
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)
String arch_name = "winx64";
var clazz = TimeSyncJNILoader.class;

for (var libraryName : List.of("photontargeting", "photontargetingJNI")) {

var nativeLibName = System.mapLibraryName(libraryName);
var in = clazz.getResourceAsStream("/nativelibraries/" + arch_name + "/" + nativeLibName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void wpi::TimeSyncClient::Tick() {
int sent = 0;
try {
sent = m_udp->TrySend(wpi::SmallVector<wpi::uv::Buffer, 1>{pingBuf});
} catch (std::exception & e) {
} catch (std::exception& e) {
fmt::println("????: {}", e.what());
return;
}
Expand Down
33 changes: 24 additions & 9 deletions photon-targeting/src/test/java/net/TimeSyncTest.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <net/TimeSyncClientServer.h>
/*
* 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 <https://www.gnu.org/licenses/>.
*/

#include <gtest/gtest.h>
#include <net/TimeSyncClientServer.h>

TEST(TimeSyncProtocolTest, TestClient) {
using namespace wpi;
Expand Down

0 comments on commit be12be1

Please sign in to comment.