From e7f27c166340347853661ef213cc42e4011fecd3 Mon Sep 17 00:00:00 2001 From: Matthew Morley Date: Sun, 15 Oct 2023 10:03:55 -0400 Subject: [PATCH] Fix shit --- photon-lib/publish.gradle | 7 +-- .../native/cpp/photonlib/PhotonCamera.cpp | 16 +++++++ .../src/main/native/include/PhotonVersion.h | 47 +++++++++++-------- .../src/test/native/cpp/VersionTest.cpp | 33 +++++++++++-- shared/PhotonVersion.cpp.in | 21 ++------- 5 files changed, 79 insertions(+), 45 deletions(-) diff --git a/photon-lib/publish.gradle b/photon-lib/publish.gradle index 725d47c0e5..fe1048e11d 100644 --- a/photon-lib/publish.gradle +++ b/photon-lib/publish.gradle @@ -1,7 +1,6 @@ apply plugin: 'maven-publish' ext.licenseFile = files("$rootDir/LICENSE") -ext.photonVersionFile = files("$projectDir/src/generate/native/include") def outputsFolder = file("$buildDir/outputs") def allOutputsFolder = file("$buildDir/allOutputs") @@ -51,11 +50,9 @@ task cppHeadersZip(type: Zip) { archiveBaseName = zipBaseName classifier = "headers" - from(licenseFile) { - into '/' - } + duplicatesStrategy = "warn" - from(photonVersionFile) { + from(licenseFile) { into '/' } diff --git a/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp b/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp index d0901b10bd..aa9d57eb98 100644 --- a/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp +++ b/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp @@ -151,6 +151,22 @@ std::optional PhotonCamera::GetDistCoeffs() { return std::nullopt; } +static bool VersionMatches(std::string them_str) { + std::smatch match; + std::regex versionPattern{"v[0-9]+.[0-9]+.[0-9]+"}; + + std::string us_str = PhotonVersion::versionString; + + // Check that both versions are in the right format + if (std::regex_search(us_str, match, versionPattern) && + std::regex_search(them_str, match, versionPattern)) { + // If they are, check string equality + return (us_str == them_str); + } else { + return false; + } +} + void PhotonCamera::VerifyVersion() { if (!PhotonCamera::VERSION_CHECK_ENABLED) return; diff --git a/photon-lib/src/main/native/include/PhotonVersion.h b/photon-lib/src/main/native/include/PhotonVersion.h index 8aae56dc3e..fd8076cfd1 100644 --- a/photon-lib/src/main/native/include/PhotonVersion.h +++ b/photon-lib/src/main/native/include/PhotonVersion.h @@ -1,29 +1,36 @@ /* - * Copyright (C) Photon Vision. + * MIT License * - * 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. + * Copyright (c) PhotonVision * - * 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. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ -#include +#pragma once + #include +#include namespace photonlib { - namespace PhotonVersion { - extern const std::string versionString; - extern const std::string buildDate; - extern const bool isRelease; - } - - bool VersionMatches(const std::string& other); -} +namespace PhotonVersion { +extern const char* versionString; +extern const char* buildDate; +extern const bool isRelease; +} // namespace PhotonVersion +} // namespace photonlib diff --git a/photon-lib/src/test/native/cpp/VersionTest.cpp b/photon-lib/src/test/native/cpp/VersionTest.cpp index 1635ad9ff3..7fe5624933 100644 --- a/photon-lib/src/test/native/cpp/VersionTest.cpp +++ b/photon-lib/src/test/native/cpp/VersionTest.cpp @@ -1,7 +1,32 @@ -#include "gtest/gtest.h" -#include "PhotonVersion.h" +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #include +#include "PhotonVersion.h" +#include "gtest/gtest.h" + TEST(VersionTest, PrintVersion) { - std::cout << photonlib::PhotonVersion::versionString << std::endl; -} \ No newline at end of file + std::cout << photonlib::PhotonVersion::versionString << std::endl; +} diff --git a/shared/PhotonVersion.cpp.in b/shared/PhotonVersion.cpp.in index c7dbb1419e..802e28efbc 100644 --- a/shared/PhotonVersion.cpp.in +++ b/shared/PhotonVersion.cpp.in @@ -23,23 +23,12 @@ * regenerated any time the publish task is run, or when this file is deleted. */ +static const char* dev_ = "dev"; + namespace photonlib { namespace PhotonVersion { - const std::string versionString = "${version}"; - const std::string buildDate = "${date}"; - const bool isRelease = !(versionString.rfind("dev", 0) == 0); - } - - bool VersionMatches(const std::string& other) { - std::smatch match; - std::regex versionPattern{"v[0-9]+.[0-9]+.[0-9]+"}; - // Check that both versions are in the right format - if (std::regex_search(PhotonVersion::versionString, match, versionPattern) && - std::regex_search(other, match, versionPattern)) { - // If they are, check string equality - return (PhotonVersion::versionString == other); - } else { - return false; - } + const char* versionString = "${version}"; + const char* buildDate = "${date}"; + const bool isRelease = strncmp(dev_, versionString, strlen(dev_)) != 0; } }