Skip to content

Commit

Permalink
RSDK-8306 - set version in metadata (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuqdog authored Jul 30, 2024
1 parent e33ae74 commit b1724d0
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/update_protos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
BOOST_ROOT: ${{ github.workspace }}/boost/boost
- name: cleanup
run: rm -rf boost/ && rm -rf vcpkg/
- name: Update proto tag
run: echo "${{ github.event.client_payload.tag }}" > src/viam/api/api_proto_tag.lock
- name: Add + Commit + Open PR
uses: peter-evans/create-pull-request@v3
with:
Expand Down
1 change: 1 addition & 0 deletions src/viam/api/api_proto_tag.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.327
4 changes: 2 additions & 2 deletions src/viam/examples/modules/complex/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: f0e53af8f2fc4556b94f482688b57223
digest: shake256:de26a277fc28b8b411ecf58729d78d32fcf15090ffd998a4469225b17889bfb51442eaab04bb7a8d88d203ecdf0a9febd4ffd52c18ed1c2229160c7bd353ca95
commit: 2bbd25900cb34c79bae97d85c948d3cf
digest: shake256:a6446e23f4408160217c22738a0c8c370ff3ff966f601d678960b803829cf53b5cf5998d20fcb3f9c9be944b24337843e7beb6e681ddbf9d036fb6491c0e47e7
12 changes: 12 additions & 0 deletions src/viam/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ target_include_directories(viamsdk
"$<BUILD_INTERFACE:$<TARGET_PROPERTY:viam-cpp-sdk::viamapi,INTERFACE_INCLUDE_DIRECTORIES>>"
)

# Configure the SDK version file
if (VIAMCPPSDK_USE_LOCAL_PROTOS)
set(VIAMCPPSDK_API_PROTO_LABEL "unknown (local generation)")
else()
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../api/api_proto_tag.lock" VIAMCPPSDK_API_PROTO_LABEL)
string(REGEX REPLACE "\n$" "" VIAMCPPSDK_API_PROTO_LABEL "${VIAMCPPSDK_API_PROTO_LABEL}")
endif()
message(WARNING "api proto label is ${VIAMCPPSDK_API_PROTO_LABEL}")
configure_file(common/private/version_metadata.hpp.in common/private/version_metadata.hpp @ONLY)


# Set compile and link options based on arguments
if (VIAMCPPSDK_USE_WALL_WERROR)
Expand Down Expand Up @@ -189,6 +199,8 @@ target_include_directories(viamsdk
"$<INSTALL_INTERFACE:${VIAMCPPSDK_GRPC_INCLUDE_DIRS}>"
"$<BUILD_INTERFACE:${VIAMCPPSDK_PROTOBUF_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${VIAMCPPSDK_PROTOBUF_INCLUDE_DIRS}>"
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../..>"
)

target_link_directories(viamsdk
Expand Down
11 changes: 11 additions & 0 deletions src/viam/sdk/common/private/version_metadata.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace viam {
namespace sdk {
namespace impl {

constexpr char k_version[] = "cpp;v@CMAKE_PROJECT_VERSION@;@VIAMCPPSDK_API_PROTO_LABEL@";

} // namespace impl
} // namespace sdk
} // namespace viam
7 changes: 6 additions & 1 deletion src/viam/sdk/common/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <viam/sdk/common/utils.hpp>

#include <tuple>
#include <unordered_map>
#include <vector>

Expand All @@ -15,6 +14,7 @@

#include <viam/api/common/v1/common.pb.h>

#include <viam/sdk/common/private/version_metadata.hpp>
#include <viam/sdk/components/component.hpp>
#include <viam/sdk/registry/registry.hpp>

Expand Down Expand Up @@ -108,8 +108,13 @@ void ClientContext::set_client_ctx_authority_() {
wrapped_context_.set_authority("viam-placeholder");
}

void ClientContext::add_viam_client_version_() {
wrapped_context_.AddMetadata("viam_client", impl::k_version);
}

ClientContext::ClientContext() {
set_client_ctx_authority_();
add_viam_client_version_();
}

ClientContext::operator const grpc::ClientContext*() const {
Expand Down
1 change: 1 addition & 0 deletions src/viam/sdk/common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ClientContext {

private:
void set_client_ctx_authority_();
void add_viam_client_version_();
grpc::ClientContext wrapped_context_;
};

Expand Down
33 changes: 28 additions & 5 deletions src/viam/sdk/tests/mocks/mock_robot.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <vector>
#include <viam/sdk/tests/mocks/mock_robot.hpp>

#include <vector>

#include <grpcpp/support/status.h>

#include <common/v1/common.pb.h>
#include <robot/v1/robot.pb.h>

Expand Down Expand Up @@ -265,9 +268,14 @@ std::vector<FrameSystemConfig> mock_proto_config_response() {
}

::grpc::Status MockRobotService::FrameSystemConfig(
::grpc::ServerContext*,
::grpc::ServerContext* context,
const ::viam::robot::v1::FrameSystemConfigRequest*,
::viam::robot::v1::FrameSystemConfigResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
auto* configs = response->mutable_frame_system_configs();
for (const auto& c : mock_proto_config_response()) {
*configs->Add() = c;
Expand All @@ -276,26 +284,41 @@ ::grpc::Status MockRobotService::FrameSystemConfig(
}

::grpc::Status MockRobotService::DiscoverComponents(
::grpc::ServerContext*,
::grpc::ServerContext* context,
const ::viam::robot::v1::DiscoverComponentsRequest*,
::viam::robot::v1::DiscoverComponentsResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
auto* discovery = response->mutable_discovery();
for (auto& d : mock_proto_discovery_response()) {
*discovery->Add() = d;
}
return ::grpc::Status();
}

::grpc::Status MockRobotService::TransformPose(::grpc::ServerContext*,
::grpc::Status MockRobotService::TransformPose(::grpc::ServerContext* context,
const ::viam::robot::v1::TransformPoseRequest*,
::viam::robot::v1::TransformPoseResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
*response->mutable_pose() = mock_proto_transform_response();
return ::grpc::Status();
}

::grpc::Status MockRobotService::GetOperations(::grpc::ServerContext*,
::grpc::Status MockRobotService::GetOperations(::grpc::ServerContext* context,
const ::viam::robot::v1::GetOperationsRequest*,
::viam::robot::v1::GetOperationsResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
auto* ops = response->mutable_operations();
for (auto& op : mock_proto_operations_response()) {
*ops->Add() = op;
Expand Down
2 changes: 1 addition & 1 deletion src/viam/sdk/tests/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::vector<GeometryConfig> fake_geometries() {
std::move(capsule_config)};
}

TestServer::TestServer(std::shared_ptr<Server> sdk_server) : sdk_server_(sdk_server) {}
TestServer::TestServer(std::shared_ptr<Server> sdk_server) : sdk_server_(std::move(sdk_server)) {}

TestServer::~TestServer() = default;

Expand Down

0 comments on commit b1724d0

Please sign in to comment.