mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-02 02:51:40 +00:00
Verify WPILib/OpenCV versions at runtime (#1772)
This commit is contained in:
@@ -43,11 +43,13 @@ import edu.wpi.first.networktables.PubSubOption;
|
||||
import edu.wpi.first.networktables.StringSubscriber;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.util.WPILibVersion;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Core;
|
||||
import org.photonvision.common.hardware.VisionLEDMode;
|
||||
import org.photonvision.common.networktables.PacketSubscriber;
|
||||
import org.photonvision.targeting.PhotonPipelineResult;
|
||||
@@ -157,6 +159,76 @@ public class PhotonCamera implements AutoCloseable {
|
||||
|
||||
// HACK - start a TimeSyncServer, if we haven't yet.
|
||||
TimeSyncSingleton.load();
|
||||
|
||||
// HACK - check if things are compatible
|
||||
verifyDependencies();
|
||||
}
|
||||
|
||||
public static void verifyDependencies() {
|
||||
if (!WPILibVersion.Version.equals(PhotonVersion.wpilibTargetVersion)) {
|
||||
String bfw =
|
||||
"\n\n\n\n\n"
|
||||
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"
|
||||
+ ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
||||
+ ">>> \n"
|
||||
+ ">>> You are running an incompatible version \n"
|
||||
+ ">>> of PhotonVision ! \n"
|
||||
+ ">>> \n"
|
||||
+ ">>> PhotonLib "
|
||||
+ PhotonVersion.versionString
|
||||
+ " is built for WPILib "
|
||||
+ PhotonVersion.wpilibTargetVersion
|
||||
+ "\n"
|
||||
+ ">>> but you are using WPILib "
|
||||
+ WPILibVersion.Version
|
||||
+ ">>> \n"
|
||||
+ ">>> This is neither tested nor supported. \n"
|
||||
+ ">>> You MUST update PhotonVision, \n"
|
||||
+ ">>> PhotonLib, or both. \n"
|
||||
+ ">>> Verify the output of `./gradlew dependencies` \n"
|
||||
+ ">>> \n"
|
||||
+ ">>> Your code will now crash. \n"
|
||||
+ ">>> We hope your day gets better. \n"
|
||||
+ ">>> \n"
|
||||
+ ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
||||
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
|
||||
|
||||
DriverStation.reportWarning(bfw, false);
|
||||
DriverStation.reportError(bfw, false);
|
||||
throw new UnsupportedOperationException(bfw);
|
||||
}
|
||||
if (!Core.VERSION.equals(PhotonVersion.opencvTargetVersion)) {
|
||||
String bfw =
|
||||
"\n\n\n\n\n"
|
||||
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"
|
||||
+ ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
||||
+ ">>> \n"
|
||||
+ ">>> You are running an incompatible version \n"
|
||||
+ ">>> of PhotonVision ! \n"
|
||||
+ ">>> \n"
|
||||
+ ">>> PhotonLib "
|
||||
+ PhotonVersion.versionString
|
||||
+ " is built for OpenCV "
|
||||
+ PhotonVersion.opencvTargetVersion
|
||||
+ "\n"
|
||||
+ ">>> but you are using OpenCV "
|
||||
+ Core.VERSION
|
||||
+ ">>> \n"
|
||||
+ ">>> This is neither tested nor supported. \n"
|
||||
+ ">>> You MUST update PhotonVision, \n"
|
||||
+ ">>> PhotonLib, or both. \n"
|
||||
+ ">>> Verify the output of `./gradlew dependencies` \n"
|
||||
+ ">>> \n"
|
||||
+ ">>> Your code will now crash. \n"
|
||||
+ ">>> We hope your day gets better. \n"
|
||||
+ ">>> \n"
|
||||
+ ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
||||
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
|
||||
|
||||
DriverStation.reportWarning(bfw, false);
|
||||
DriverStation.reportError(bfw, false);
|
||||
throw new UnsupportedOperationException(bfw);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,13 +24,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
namespace photon {
|
||||
namespace PhotonVersion {
|
||||
extern const char* versionString;
|
||||
extern const char* buildDate;
|
||||
extern const bool isRelease;
|
||||
extern const char* wpilibTargetVersion;
|
||||
extern const char* opencvTargetVersion;
|
||||
} // namespace PhotonVersion
|
||||
} // namespace photon
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
package org.photonvision;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -56,4 +58,9 @@ public class PhotonVersionTest {
|
||||
Assertions.assertFalse(versionMatches("", "v2021.1.6"));
|
||||
Assertions.assertFalse(versionMatches("v2021.1.6", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNominalDeps() {
|
||||
assertDoesNotThrow(PhotonCamera::verifyDependencies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,5 +30,9 @@ namespace photon {
|
||||
const char* versionString = "${version}";
|
||||
const char* buildDate = "${date}";
|
||||
const bool isRelease = strncmp(dev_, versionString, strlen(dev_)) != 0;
|
||||
|
||||
// Versions of dependant libraries
|
||||
const char* wpilibTargetVersion = "${wpilibVersion}";
|
||||
const char* opencvTargetVersion = "${opencvVersion}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ public final class PhotonVersion {
|
||||
public static final String buildDate = "${date}";
|
||||
public static final boolean isRelease = !versionString.startsWith("dev");
|
||||
|
||||
// Versions of dependant libraries
|
||||
public static final String wpilibTargetVersion = "${wpilibVersion}";
|
||||
public static final String opencvTargetVersion = "${opencvVersion}";
|
||||
|
||||
public static final boolean versionMatches(String other) {
|
||||
String c = versionString;
|
||||
Pattern p = Pattern.compile("v[0-9]+.[0-9]+.[0-9]+");
|
||||
|
||||
@@ -34,7 +34,11 @@ gradle.allprojects {
|
||||
String date = DateTimeFormatter.ofPattern("yyyy-M-d hh:mm:ss").format(LocalDateTime.now())
|
||||
File versionFileOut = new File(path.toAbsolutePath().toString())
|
||||
versionFileOut.delete()
|
||||
def read = versionFileIn.text.replace('${version}', version).replace('${date}', date)
|
||||
def read = versionFileIn.text.replace('${version}', version)
|
||||
.replace('${date}', date)
|
||||
.replace('${wpilibVersion}', wpilibVersion)
|
||||
// Note that OpenCV is usually {VERSION}-{some suffix}, we just want the first bit
|
||||
.replace('${opencvVersion}', openCVversion.split("-").first())
|
||||
if (!versionFileOut.parentFile.exists()) versionFileOut.parentFile.mkdirs()
|
||||
if (!versionFileOut.exists()) versionFileOut.createNewFile()
|
||||
versionFileOut.write(read)
|
||||
|
||||
Reference in New Issue
Block a user