Skip to content

Commit

Permalink
Fix shit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Oct 15, 2023
1 parent f871b21 commit e7f27c1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 45 deletions.
7 changes: 2 additions & 5 deletions photon-lib/publish.gradle
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -51,11 +50,9 @@ task cppHeadersZip(type: Zip) {
archiveBaseName = zipBaseName
classifier = "headers"

from(licenseFile) {
into '/'
}
duplicatesStrategy = "warn"

from(photonVersionFile) {
from(licenseFile) {
into '/'
}

Expand Down
16 changes: 16 additions & 0 deletions photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ std::optional<cv::Mat> 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;

Expand Down
47 changes: 27 additions & 20 deletions photon-lib/src/main/native/include/PhotonVersion.h
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
* 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 <string.h>
#pragma once

#include <regex>
#include <string>

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
33 changes: 29 additions & 4 deletions photon-lib/src/test/native/cpp/VersionTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

#include "PhotonVersion.h"
#include "gtest/gtest.h"

TEST(VersionTest, PrintVersion) {
std::cout << photonlib::PhotonVersion::versionString << std::endl;
}
std::cout << photonlib::PhotonVersion::versionString << std::endl;
}
21 changes: 5 additions & 16 deletions shared/PhotonVersion.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit e7f27c1

Please sign in to comment.