Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions photon-lib/src/main/java/org/photonvision/PhotonCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to do this in C++ and Python as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ggezwp. Yeah. But this gets us 80% of the way there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, I'll open a follow up for you

}

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);
}
}

/**
Expand Down
5 changes: 2 additions & 3 deletions photon-lib/src/main/native/include/PhotonVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions shared/PhotonVersion.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}
4 changes: 4 additions & 0 deletions shared/PhotonVersion.java.in
Original file line number Diff line number Diff line change
Expand Up @@ -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]+");
Expand Down
6 changes: 5 additions & 1 deletion versioningHelper.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading