Skip to content

Commit

Permalink
Add photon.pb.h/PhotonVersion to cpp headers zip & create combined so…
Browse files Browse the repository at this point in the history
…urces zip (#1335)

Combined sources zip is useful for robotpy to build both targeting & lib in the same build
  • Loading branch information
mcm001 authored Jun 9, 2024
1 parent 7b19a95 commit 5289948
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 14 deletions.
63 changes: 63 additions & 0 deletions photon-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ task generateVendorJson() {
}

build.mustRunAfter generateVendorJson
publish.mustRunAfter generateVendorJson

task writeCurrentVersion {
def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in")
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

#include "photon/dataflow/structures/Packet.h"

using namespace photon;

Packet::Packet(std::vector<uint8_t> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <algorithm>
#include <bit>
#include <cstring>
#include <string>
#include <vector>

Expand All @@ -38,28 +39,24 @@ class Packet {
* Constructs a packet with the given data.
* @param data The packet data.
*/
explicit Packet(std::vector<uint8_t> data) : packetData(data) {}
explicit Packet(std::vector<uint8_t> 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<uint8_t>& GetData() { return packetData; }
inline const std::vector<uint8_t>& 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.
Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions shared/javacpp/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand All @@ -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 {
Expand Down

0 comments on commit 5289948

Please sign in to comment.