diff --git a/photon-lib/build.gradle b/photon-lib/build.gradle index 07aba286d0..63ea461980 100644 --- a/photon-lib/build.gradle +++ b/photon-lib/build.gradle @@ -159,6 +159,7 @@ task generateVendorJson() { } build.mustRunAfter generateVendorJson +publish.mustRunAfter generateVendorJson task writeCurrentVersion { def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in") @@ -216,3 +217,65 @@ model { } } } + +// Add photonversion to cpp sources zip +tasks.named('cppSourcesZip') { + dependsOn writeCurrentVersion + + from("$projectDir/src/generate/native/cpp") { + into '/' + } +} + +// Publish an uberzip with photon-lib and photon-targeting. This makes python binding easier to have it in one place +def zipBaseNameCombined = '_GROUP_org.photonvision_combinedcpp_ID_photonvision-combinedcpp_CLS' +task combinedCppSourcesZip(type: Zip) { + dependsOn(':photon-lib:cppSourcesZip', ':photon-targeting:cppSourcesZip') + mustRunAfter(':photon-lib:cppHeadersZip', ':photon-targeting:cppHeadersZip') + + destinationDirectory = file("$buildDir/outputs") + archiveBaseName = zipBaseNameCombined + archiveClassifier = "sources" + + // Include the contents of the photon-lib cppSourcesZip. Magic chatgpt nonsense + from(zipTree(project(':photon-lib').tasks.cppSourcesZip.archiveFile.get().asFile)) { + into 'photon-lib' + } + from(zipTree(project(':photon-targeting').tasks.cppSourcesZip.archiveFile.get().asFile)) { + into 'photon-targeting' + } + + duplicatesStrategy = DuplicatesStrategy.FAIL +} +task combinedHeadersZip(type: Zip) { + dependsOn(':photon-lib:cppHeadersZip', ':photon-targeting:cppHeadersZip') + mustRunAfter(':photon-lib:cppHeadersZip', ':photon-targeting:cppHeadersZip') + + destinationDirectory = file("$buildDir/outputs") + archiveBaseName = zipBaseNameCombined + archiveClassifier = "headers" + + // Include the contents of the photon-lib cppHeadersZip. Magic chatgpt nonsense + from(zipTree(project(':photon-lib').tasks.cppHeadersZip.archiveFile.get().asFile)) { + into 'photon-lib' + } + from(zipTree(project(':photon-targeting').tasks.cppHeadersZip.archiveFile.get().asFile)) { + into 'photon-targeting' + } + + duplicatesStrategy = DuplicatesStrategy.FAIL +} + +// Add the uberzip to our maven publications +publishing { + publications { + combinedcpp(MavenPublication) { + artifact combinedCppSourcesZip + artifact combinedHeadersZip + + artifactId = "${nativeName}-combinedcpp" + groupId artifactGroupId + version pubVersion + } + } +} diff --git a/photon-targeting/src/main/native/cpp/photon/dataflow/structures/Packet.cpp b/photon-targeting/src/main/native/cpp/photon/dataflow/structures/Packet.cpp new file mode 100644 index 0000000000..a69427a488 --- /dev/null +++ b/photon-targeting/src/main/native/cpp/photon/dataflow/structures/Packet.cpp @@ -0,0 +1,35 @@ +/* + * 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 "photon/dataflow/structures/Packet.h" + +using namespace photon; + +Packet::Packet(std::vector data) : packetData(data) {} + +void Packet::Clear() { + packetData.clear(); + readPos = 0; + writePos = 0; +} + +bool Packet::operator==(const Packet& right) const { + return packetData == right.packetData; +} +bool Packet::operator!=(const Packet& right) const { + return !operator==(right); +} diff --git a/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h b/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h index f1ed30442b..242aa9d221 100644 --- a/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h +++ b/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -38,28 +39,24 @@ class Packet { * Constructs a packet with the given data. * @param data The packet data. */ - explicit Packet(std::vector data) : packetData(data) {} + explicit Packet(std::vector data); /** * Clears the packet and resets the read and write positions. */ - void Clear() { - packetData.clear(); - readPos = 0; - writePos = 0; - } + void Clear(); /** * Returns the packet data. * @return The packet data. */ - const std::vector& GetData() { return packetData; } + inline const std::vector& GetData() { return packetData; } /** * Returns the number of bytes in the data. * @return The number of bytes in the data. */ - size_t GetDataSize() const { return packetData.size(); } + inline size_t GetDataSize() const { return packetData.size(); } /** * Adds a value to the data buffer. This should only be used with PODs. @@ -104,10 +101,8 @@ class Packet { return *this; } - bool operator==(const Packet& right) const { - return packetData == right.packetData; - } - bool operator!=(const Packet& right) const { return !operator==(right); } + bool operator==(const Packet& right) const; + bool operator!=(const Packet& right) const; private: // Data stored in the packet diff --git a/shared/javacpp/publish.gradle b/shared/javacpp/publish.gradle index 2c2b62b0ee..9c7edbd704 100644 --- a/shared/javacpp/publish.gradle +++ b/shared/javacpp/publish.gradle @@ -6,6 +6,10 @@ def baseArtifactId = nativeName def artifactGroupId = 'org.photonvision' def zipBaseName = "_GROUP_org_photonvision_${baseArtifactId}_ID_${baseArtifactId}-cpp_CLS" +// Quick hack to make this name visible to photon-lib for combined +ext.zipBaseName = zipBaseName +ext.artifactGroupId = artifactGroupId + def licenseFile = file("$rootDir/LICENCE") task cppSourcesZip(type: Zip) { @@ -17,15 +21,17 @@ task cppSourcesZip(type: Zip) { into '/' } - from('src/main/native/cpp') { + println("Sources: from $projectDir ") + from("$projectDir/src/main/native/cpp") { into '/' } // assume we will always have proto sources from("$buildDir/generated/source/proto/main/cpp") { into '/' + // Only include generated C++ source files, not headers + include "**/*.cc", "**/*.cpp" } - dependsOn generateProto } @@ -47,6 +53,14 @@ task cppHeadersZip(type: Zip) { into '/' } } + + // assume we will always have proto sources + from("$buildDir/generated/source/proto/main/cpp") { + into '/' + // Only include generated C++ headers + include "**/*.h" + } + dependsOn generateProto } artifacts {