mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-03 03:01:40 +00:00
Move PhotonVersion to C++ file (#949)
This was supposed to speed up incremental compilation, but not sure it actually does. It's better form tm tho and fixes a robotpy-wrapper weirdness
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -162,5 +162,6 @@ photonlib-cpp-examples/*/networktables.json.bck
|
||||
photonlib-java-examples/*/networktables.json.bck
|
||||
*.sqlite
|
||||
photon-server/src/main/resources/web/index.html
|
||||
photon-lib/src/generate/native/cpp/PhotonVersion.cpp
|
||||
|
||||
venv
|
||||
|
||||
@@ -28,7 +28,7 @@ model {
|
||||
sources {
|
||||
cpp {
|
||||
source {
|
||||
srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp"
|
||||
srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp", "src/generate/native/cpp"
|
||||
include '**/*.cpp', '**/*.cc'
|
||||
}
|
||||
exportedHeaders {
|
||||
@@ -164,8 +164,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)
|
||||
}
|
||||
|
||||
|
||||
199
photon-lib/publish.gradle
Normal file
199
photon-lib/publish.gradle
Normal file
@@ -0,0 +1,199 @@
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
ext.licenseFile = files("$rootDir/LICENSE")
|
||||
|
||||
def outputsFolder = file("$buildDir/outputs")
|
||||
def allOutputsFolder = file("$buildDir/allOutputs")
|
||||
|
||||
def versionFile = file("$allOutputsFolder/version.txt")
|
||||
|
||||
task outputVersions() {
|
||||
description = 'Prints the versions of wpilib to a file for use by the downstream packaging project'
|
||||
group = 'Build'
|
||||
outputs.files(versionFile)
|
||||
|
||||
doFirst {
|
||||
buildDir.mkdir()
|
||||
outputsFolder.mkdir()
|
||||
allOutputsFolder.mkdir()
|
||||
}
|
||||
|
||||
doLast {
|
||||
versionFile.write pubVersion
|
||||
}
|
||||
}
|
||||
|
||||
task libraryBuild() {}
|
||||
|
||||
build.dependsOn outputVersions
|
||||
|
||||
task copyAllOutputs(type: Copy) {
|
||||
destinationDir allOutputsFolder
|
||||
}
|
||||
|
||||
build.dependsOn copyAllOutputs
|
||||
copyAllOutputs.dependsOn outputVersions
|
||||
|
||||
ext.addTaskToCopyAllOutputs = { task ->
|
||||
copyAllOutputs.dependsOn task
|
||||
copyAllOutputs.inputs.file task.archivePath
|
||||
copyAllOutputs.from task.archivePath
|
||||
}
|
||||
|
||||
def artifactGroupId = 'org.photonvision'
|
||||
def baseArtifactId = 'PhotonLib'
|
||||
def zipBaseName = "_GROUP_org_photonvision_photonlib_ID_${baseArtifactId}-cpp_CLS"
|
||||
def javaBaseName = "_GROUP_org_photonvision_photonlib_ID_${baseArtifactId}-java_CLS"
|
||||
|
||||
task cppHeadersZip(type: Zip) {
|
||||
destinationDirectory = outputsFolder
|
||||
archiveBaseName = zipBaseName
|
||||
classifier = "headers"
|
||||
|
||||
duplicatesStrategy = "warn"
|
||||
|
||||
from(licenseFile) {
|
||||
into '/'
|
||||
}
|
||||
|
||||
from('src/main/native/include/') {
|
||||
into '/'
|
||||
}
|
||||
}
|
||||
|
||||
task cppSourcesZip(type: Zip) {
|
||||
destinationDirectory = outputsFolder
|
||||
archiveBaseName = zipBaseName
|
||||
classifier = "sources"
|
||||
|
||||
from(licenseFile) {
|
||||
into '/'
|
||||
}
|
||||
|
||||
from('src/main/native/cpp') {
|
||||
into '/'
|
||||
}
|
||||
}
|
||||
|
||||
build.dependsOn cppHeadersZip
|
||||
addTaskToCopyAllOutputs(cppHeadersZip)
|
||||
build.dependsOn cppSourcesZip
|
||||
addTaskToCopyAllOutputs(cppSourcesZip)
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
task outputJar(type: Jar, dependsOn: classes) {
|
||||
archiveBaseName = javaBaseName
|
||||
destinationDirectory = outputsFolder
|
||||
from sourceSets.main.output
|
||||
}
|
||||
|
||||
task outputSourcesJar(type: Jar, dependsOn: classes) {
|
||||
archiveBaseName = javaBaseName
|
||||
destinationDirectory = outputsFolder
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task outputJavadocJar(type: Jar, dependsOn: javadoc) {
|
||||
archiveBaseName = javaBaseName
|
||||
destinationDirectory = outputsFolder
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
def vendorJson = artifacts.add('archives', file("$photonlibFileOutput"))
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
archives outputJar
|
||||
archives outputSourcesJar
|
||||
archives outputJavadocJar
|
||||
}
|
||||
|
||||
addTaskToCopyAllOutputs(outputSourcesJar)
|
||||
addTaskToCopyAllOutputs(outputJavadocJar)
|
||||
addTaskToCopyAllOutputs(outputJar)
|
||||
|
||||
build.dependsOn outputSourcesJar
|
||||
build.dependsOn outputJavadocJar
|
||||
build.dependsOn outputJar
|
||||
|
||||
libraryBuild.dependsOn build
|
||||
|
||||
def releasesRepoUrl = "$buildDir/repos/releases"
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
url = releasesRepoUrl
|
||||
}
|
||||
maven {
|
||||
url ('https://maven.photonvision.org/repository/' + (isDev ? 'snapshots' : 'internal'))
|
||||
credentials {
|
||||
username 'ghactions'
|
||||
password System.getenv("ARTIFACTORY_API_KEY")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(PublishToMavenRepository) {
|
||||
doFirst {
|
||||
println("Publishing to " + repository.url);
|
||||
}
|
||||
}
|
||||
|
||||
task cleanReleaseRepo(type: Delete) {
|
||||
delete releasesRepoUrl
|
||||
}
|
||||
|
||||
tasks.matching {it != cleanReleaseRepo}.all {it.dependsOn cleanReleaseRepo}
|
||||
|
||||
model {
|
||||
publishing {
|
||||
def taskList = createComponentZipTasks($.components, ['Photon'], zipBaseName, Zip, project, includeStandardZipFormat)
|
||||
|
||||
publications {
|
||||
cpp(MavenPublication) {
|
||||
taskList.each {
|
||||
artifact it
|
||||
}
|
||||
artifact cppHeadersZip
|
||||
artifact cppSourcesZip
|
||||
|
||||
artifactId = "${baseArtifactId}-cpp"
|
||||
groupId artifactGroupId
|
||||
version pubVersion
|
||||
}
|
||||
java(MavenPublication) {
|
||||
artifact jar
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
|
||||
artifactId = "${baseArtifactId}-java"
|
||||
groupId artifactGroupId
|
||||
version pubVersion
|
||||
}
|
||||
vendorjson(MavenPublication) {
|
||||
artifact vendorJson
|
||||
|
||||
artifactId = "${baseArtifactId}-json"
|
||||
groupId = artifactGroupId
|
||||
version "1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishToMavenLocal.dependsOn libraryBuild
|
||||
publish.dependsOn libraryBuild
|
||||
@@ -193,6 +193,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;
|
||||
|
||||
36
photon-lib/src/main/native/include/PhotonVersion.h
Normal file
36
photon-lib/src/main/native/include/PhotonVersion.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
namespace photon {
|
||||
namespace PhotonVersion {
|
||||
extern const char* versionString;
|
||||
extern const char* buildDate;
|
||||
extern const bool isRelease;
|
||||
} // namespace PhotonVersion
|
||||
} // namespace photon
|
||||
32
photon-lib/src/test/native/cpp/VersionTest.cpp
Normal file
32
photon-lib/src/test/native/cpp/VersionTest.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 << photon::PhotonVersion::versionString << std::endl;
|
||||
}
|
||||
@@ -23,23 +23,12 @@
|
||||
* regenerated any time the publish task is run, or when this file is deleted.
|
||||
*/
|
||||
|
||||
static const char* dev_ = "dev";
|
||||
|
||||
namespace photon {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user