diff --git a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java index 76109878a2..3d399c0299 100644 --- a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java +++ b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java @@ -43,11 +43,13 @@ 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 PhotonCamera(NetworkTableInstance instance, String cameraName) { // 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); + } } /** diff --git a/photon-lib/src/main/native/include/PhotonVersion.h b/photon-lib/src/main/native/include/PhotonVersion.h index 4a95048069..e2533929a5 100644 --- a/photon-lib/src/main/native/include/PhotonVersion.h +++ b/photon-lib/src/main/native/include/PhotonVersion.h @@ -24,13 +24,12 @@ #pragma once -#include -#include - 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 diff --git a/photon-lib/src/test/java/org/photonvision/PhotonVersionTest.java b/photon-lib/src/test/java/org/photonvision/PhotonVersionTest.java index 3009de49e9..216a0536a1 100644 --- a/photon-lib/src/test/java/org/photonvision/PhotonVersionTest.java +++ b/photon-lib/src/test/java/org/photonvision/PhotonVersionTest.java @@ -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 void testVersion() { Assertions.assertFalse(versionMatches("", "v2021.1.6")); Assertions.assertFalse(versionMatches("v2021.1.6", "")); } + + @Test + public void testNominalDeps() { + assertDoesNotThrow(PhotonCamera::verifyDependencies); + } } diff --git a/shared/PhotonVersion.cpp.in b/shared/PhotonVersion.cpp.in index 9b6f84dd00..d6aacbeaac 100644 --- a/shared/PhotonVersion.cpp.in +++ b/shared/PhotonVersion.cpp.in @@ -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}"; } } diff --git a/shared/PhotonVersion.java.in b/shared/PhotonVersion.java.in index 0db5ddac31..34797d3614 100644 --- a/shared/PhotonVersion.java.in +++ b/shared/PhotonVersion.java.in @@ -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]+"); diff --git a/versioningHelper.gradle b/versioningHelper.gradle index e9dd6e3d0a..e2fb22731f 100644 --- a/versioningHelper.gradle +++ b/versioningHelper.gradle @@ -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)