From f871b217377af542f8b2a4d84e3f00958e9da6c4 Mon Sep 17 00:00:00 2001 From: Matthew Morley Date: Thu, 1 Jun 2023 07:44:55 -0700 Subject: [PATCH 1/3] Add broken code to move PhotonVersion to cpp --- .gitignore | 1 + photon-lib/build.gradle | 5 ++-- .../src/main/native/include/PhotonVersion.h | 29 +++++++++++++++++++ .../src/test/native/cpp/VersionTest.cpp | 7 +++++ ...hotonVersion.h.in => PhotonVersion.cpp.in} | 0 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 photon-lib/src/main/native/include/PhotonVersion.h create mode 100644 photon-lib/src/test/native/cpp/VersionTest.cpp rename shared/{PhotonVersion.h.in => PhotonVersion.cpp.in} (100%) diff --git a/.gitignore b/.gitignore index 2bb8de0059..1e7cd4620c 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ photonlib-cpp-examples/*/vendordeps/* */networktables.json *.sqlite photon-server/src/main/resources/web/index.html +photon-lib/src/generate/native/cpp/PhotonVersion.cpp diff --git a/photon-lib/build.gradle b/photon-lib/build.gradle index 1536e9b0d6..99006da779 100644 --- a/photon-lib/build.gradle +++ b/photon-lib/build.gradle @@ -78,6 +78,7 @@ model { cpp { source { srcDirs "src/main/native/cpp" + srcDirs "src/generate/native/cpp" include "**/*.cpp" } exportedHeaders { @@ -140,8 +141,8 @@ task writeCurrentVersion { def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in") writePhotonVersionFile(versionFileIn, Path.of("$projectDir", "src", "main", "java", "org", "photonvision", "PhotonVersion.java"), versionString) - versionFileIn = file("${rootDir}/shared/PhotonVersion.h.in") - writePhotonVersionFile(versionFileIn, Path.of("$projectDir", "src", "generate", "native", "include", "PhotonVersion.h"), + versionFileIn = file("${rootDir}/shared/PhotonVersion.cpp.in") + writePhotonVersionFile(versionFileIn, Path.of("$projectDir", "src", "generate", "native", "cpp", "PhotonVersion.cpp"), versionString) } diff --git a/photon-lib/src/main/native/include/PhotonVersion.h b/photon-lib/src/main/native/include/PhotonVersion.h new file mode 100644 index 0000000000..8aae56dc3e --- /dev/null +++ b/photon-lib/src/main/native/include/PhotonVersion.h @@ -0,0 +1,29 @@ +/* + * 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 . + */ + +#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); +} diff --git a/photon-lib/src/test/native/cpp/VersionTest.cpp b/photon-lib/src/test/native/cpp/VersionTest.cpp new file mode 100644 index 0000000000..1635ad9ff3 --- /dev/null +++ b/photon-lib/src/test/native/cpp/VersionTest.cpp @@ -0,0 +1,7 @@ +#include "gtest/gtest.h" +#include "PhotonVersion.h" +#include + +TEST(VersionTest, PrintVersion) { + std::cout << photonlib::PhotonVersion::versionString << std::endl; +} \ No newline at end of file diff --git a/shared/PhotonVersion.h.in b/shared/PhotonVersion.cpp.in similarity index 100% rename from shared/PhotonVersion.h.in rename to shared/PhotonVersion.cpp.in From e7f27c166340347853661ef213cc42e4011fecd3 Mon Sep 17 00:00:00 2001 From: Matthew Morley Date: Sun, 15 Oct 2023 10:03:55 -0400 Subject: [PATCH 2/3] 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; } } From 029a70773a85184360ee3e8265e37408d49dafdb Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 24 May 2024 22:12:12 -0500 Subject: [PATCH 3/3] Fix merge things --- photon-lib/src/main/native/include/PhotonVersion.h | 4 ++-- photon-lib/src/test/native/cpp/VersionTest.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/photon-lib/src/main/native/include/PhotonVersion.h b/photon-lib/src/main/native/include/PhotonVersion.h index fd8076cfd1..4a95048069 100644 --- a/photon-lib/src/main/native/include/PhotonVersion.h +++ b/photon-lib/src/main/native/include/PhotonVersion.h @@ -27,10 +27,10 @@ #include #include -namespace photonlib { +namespace photon { namespace PhotonVersion { extern const char* versionString; extern const char* buildDate; extern const bool isRelease; } // namespace PhotonVersion -} // namespace photonlib +} // namespace photon diff --git a/photon-lib/src/test/native/cpp/VersionTest.cpp b/photon-lib/src/test/native/cpp/VersionTest.cpp index 7fe5624933..4e547f6a37 100644 --- a/photon-lib/src/test/native/cpp/VersionTest.cpp +++ b/photon-lib/src/test/native/cpp/VersionTest.cpp @@ -28,5 +28,5 @@ #include "gtest/gtest.h" TEST(VersionTest, PrintVersion) { - std::cout << photonlib::PhotonVersion::versionString << std::endl; + std::cout << photon::PhotonVersion::versionString << std::endl; }