delta push service
This commit is contained in:
@@ -20,17 +20,19 @@ set(BUILD_SHARED_LIBS ON)
|
|||||||
|
|
||||||
# Abseil Standard Specifications ----------------------------------------------
|
# Abseil Standard Specifications ----------------------------------------------
|
||||||
include(cmake/absl.cmake)
|
include(cmake/absl.cmake)
|
||||||
|
include(cmake/openssl.cmake)
|
||||||
|
|
||||||
set(PROTOBUF_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}
|
set(PROTOBUF_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
CACHE INTERNAL "Path to generated protobuf files.")
|
CACHE INTERNAL "Path to generated protobuf files.")
|
||||||
include_directories(${PROTOBUF_INCLUDE_PATH})
|
include_directories(${PROTOBUF_INCLUDE_PATH})
|
||||||
|
|
||||||
# Video Libraries -------------------------------------------------------------
|
# Video Libraries -------------------------------------------------------------
|
||||||
|
set(Protobuf_PROTOC_EXECUTABLE "/Users/scawful/code/protobuf/bin/protoc")
|
||||||
|
set(Protobuf_INCLUDE_DIRS "/Users/scawful/code/protobuf/include/")
|
||||||
find_package(PNG REQUIRED)
|
find_package(PNG REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
find_package(GLEW REQUIRED)
|
find_package(GLEW REQUIRED)
|
||||||
find_package(gRPC REQUIRED)
|
find_package(gRPC REQUIRED)
|
||||||
include(cmake/openssl.cmake)
|
|
||||||
|
|
||||||
# Asar Assembly ---------------------------------------------------------------
|
# Asar Assembly ---------------------------------------------------------------
|
||||||
add_subdirectory(src/lib/asar/src)
|
add_subdirectory(src/lib/asar/src)
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ add_executable(
|
|||||||
yaze_delta
|
yaze_delta
|
||||||
app/delta/delta.cc
|
app/delta/delta.cc
|
||||||
app/delta/viewer.cc
|
app/delta/viewer.cc
|
||||||
|
app/delta/service.cc
|
||||||
app/delta/client.cc
|
app/delta/client.cc
|
||||||
app/rom.cc
|
app/rom.cc
|
||||||
${YAZE_APP_ASM_SRC}
|
${YAZE_APP_ASM_SRC}
|
||||||
@@ -115,18 +116,19 @@ add_executable(
|
|||||||
${YAZE_APP_ZELDA3_SRC}
|
${YAZE_APP_ZELDA3_SRC}
|
||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${IMGUI_SRC}
|
${IMGUI_SRC}
|
||||||
|
${ASAR_STATIC_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
yaze_delta PUBLIC
|
yaze_delta PUBLIC
|
||||||
lib/
|
lib/
|
||||||
app/
|
app/
|
||||||
|
lib/asar/src/
|
||||||
${ASAR_INCLUDE_DIR}
|
${ASAR_INCLUDE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}/src/
|
${CMAKE_SOURCE_DIR}/src/
|
||||||
${PNG_INCLUDE_DIRS}
|
${PNG_INCLUDE_DIRS}
|
||||||
${SDL2_INCLUDE_DIR}
|
${SDL2_INCLUDE_DIR}
|
||||||
${GLEW_INCLUDE_DIRS}
|
${GLEW_INCLUDE_DIRS}
|
||||||
${ASAR_STATIC_SRC}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
@@ -141,6 +143,8 @@ target_link_libraries(
|
|||||||
asar-static
|
asar-static
|
||||||
ImGui
|
ImGui
|
||||||
)
|
)
|
||||||
|
target_compile_definitions(yaze_delta PRIVATE "linux")
|
||||||
|
target_compile_definitions(yaze_delta PRIVATE "stricmp=strcasecmp")
|
||||||
|
|
||||||
set (source "${CMAKE_SOURCE_DIR}/assets")
|
set (source "${CMAKE_SOURCE_DIR}/assets")
|
||||||
set (destination "${CMAKE_CURRENT_BINARY_DIR}/assets")
|
set (destination "${CMAKE_CURRENT_BINARY_DIR}/assets")
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ message CloneResponse {}
|
|||||||
|
|
||||||
message PushRequest {
|
message PushRequest {
|
||||||
string author_name = 1;
|
string author_name = 1;
|
||||||
|
string repository_name= 2;
|
||||||
|
string branch_name = 3;
|
||||||
|
repeated Commit commits = 4;
|
||||||
}
|
}
|
||||||
message PushResponse {}
|
message PushResponse {}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <grpcpp/health_check_service_interface.h>
|
#include <grpcpp/health_check_service_interface.h>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
#include "src/app/delta/delta.grpc.pb.h"
|
#include "src/app/delta/delta.grpc.pb.h"
|
||||||
#include "src/app/delta/delta.pb.h"
|
#include "src/app/delta/delta.pb.h"
|
||||||
|
|
||||||
@@ -22,13 +23,42 @@ using grpc::Server;
|
|||||||
using grpc::ServerBuilder;
|
using grpc::ServerBuilder;
|
||||||
using grpc::Status;
|
using grpc::Status;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
auto FindRepository(std::vector<Repository>& repos, const std::string& name) {
|
||||||
|
for (auto& repo : repos) {
|
||||||
|
if (repo.project_name() == name) {
|
||||||
|
return repo.mutable_tree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto FindBranch(google::protobuf::RepeatedPtrField<Branch>* repo,
|
||||||
|
const std::string& branch_name) {
|
||||||
|
for (auto it = repo->begin(); it != repo->end(); ++it) {
|
||||||
|
if (it->branch_name() == branch_name) {
|
||||||
|
return it->mutable_commits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
Status DeltaService::Init(grpc::ServerContext* context,
|
Status DeltaService::Init(grpc::ServerContext* context,
|
||||||
const InitRequest* request, InitResponse* reply) {
|
const InitRequest* request, InitResponse* reply) {
|
||||||
|
std::filesystem::create_directories("./.yaze");
|
||||||
|
repos_.push_back(request->repo());
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status DeltaService::Push(grpc::ServerContext* context,
|
Status DeltaService::Push(grpc::ServerContext* context,
|
||||||
const PushRequest* request, PushResponse* reply) {
|
const PushRequest* request, PushResponse* reply) {
|
||||||
|
const auto& repository_name = request->repository_name();
|
||||||
|
const auto& branch_name = request->branch_name();
|
||||||
|
auto repo = FindRepository(repos_, repository_name);
|
||||||
|
auto mutable_commits = FindBranch(repo, branch_name);
|
||||||
|
auto size = request->commits().size();
|
||||||
|
for (int i = 1; i < size; ++i) {
|
||||||
|
*mutable_commits->Add() = request->commits().at(i);
|
||||||
|
}
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +67,11 @@ Status DeltaService::Pull(grpc::ServerContext* context,
|
|||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status DeltaService::Clone(grpc::ServerContext* context,
|
||||||
|
const CloneRequest* request, CloneResponse* reply) {
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace delta
|
} // namespace delta
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef YAZE_APP_DELTA_SERVICE_H
|
#ifndef YAZE_APP_DELTA_SERVICE_H
|
||||||
#define YAZE_APP_DELTA_SERVICE_H
|
#define YAZE_APP_DELTA_SERVICE_H
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include <google/protobuf/message.h>
|
#include <google/protobuf/message.h>
|
||||||
#include <grpc/support/log.h>
|
#include <grpc/support/log.h>
|
||||||
#include <grpcpp/ext/proto_server_reflection_plugin.h>
|
#include <grpcpp/ext/proto_server_reflection_plugin.h>
|
||||||
@@ -17,6 +19,8 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace delta {
|
namespace delta {
|
||||||
|
|
||||||
|
using grpc::Status;
|
||||||
|
|
||||||
class DeltaService final : public ::YazeDelta::Service {
|
class DeltaService final : public ::YazeDelta::Service {
|
||||||
public:
|
public:
|
||||||
Status Init(grpc::ServerContext* context, const InitRequest* request,
|
Status Init(grpc::ServerContext* context, const InitRequest* request,
|
||||||
@@ -28,6 +32,11 @@ class DeltaService final : public ::YazeDelta::Service {
|
|||||||
Status Pull(grpc::ServerContext* context, const PullRequest* request,
|
Status Pull(grpc::ServerContext* context, const PullRequest* request,
|
||||||
PullResponse* reply) override;
|
PullResponse* reply) override;
|
||||||
|
|
||||||
|
Status Clone(grpc::ServerContext* context, const CloneRequest* request,
|
||||||
|
CloneResponse* reply) override;
|
||||||
|
|
||||||
|
auto Repos() const { return repos_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Repository> repos_;
|
std::vector<Repository> repos_;
|
||||||
};
|
};
|
||||||
@@ -35,3 +44,5 @@ class DeltaService final : public ::YazeDelta::Service {
|
|||||||
} // namespace delta
|
} // namespace delta
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -104,6 +104,9 @@ class ROM {
|
|||||||
auto begin() { return rom_data_.begin(); }
|
auto begin() { return rom_data_.begin(); }
|
||||||
auto end() { return rom_data_.end(); }
|
auto end() { return rom_data_.end(); }
|
||||||
auto data() { return rom_data_.data(); }
|
auto data() { return rom_data_.data(); }
|
||||||
|
auto char_data() {
|
||||||
|
return reinterpret_cast<char*>(rom_data_.data());
|
||||||
|
}
|
||||||
auto size() const { return size_; }
|
auto size() const { return size_; }
|
||||||
|
|
||||||
uchar& operator[](int i) {
|
uchar& operator[](int i) {
|
||||||
|
|||||||
@@ -15,12 +15,15 @@ add_executable(
|
|||||||
yaze_test.cc
|
yaze_test.cc
|
||||||
rom_test.cc
|
rom_test.cc
|
||||||
asm_test.cc
|
asm_test.cc
|
||||||
|
delta_test.cc
|
||||||
../src/app/rom.cc
|
../src/app/rom.cc
|
||||||
../src/app/asm/script.cc
|
../src/app/asm/script.cc
|
||||||
../src/app/gfx/bitmap.cc
|
../src/app/gfx/bitmap.cc
|
||||||
../src/app/gfx/snes_tile.cc
|
../src/app/gfx/snes_tile.cc
|
||||||
../src/app/gfx/snes_palette.cc
|
../src/app/gfx/snes_palette.cc
|
||||||
../src/app/core/common.cc
|
../src/app/core/common.cc
|
||||||
|
../src/app/delta/service.cc
|
||||||
|
../src/app/delta/client.cc
|
||||||
${ASAR_STATIC_SRC}
|
${ASAR_STATIC_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,6 +42,7 @@ target_link_libraries(
|
|||||||
${ABSL_TARGETS}
|
${ABSL_TARGETS}
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
${CMAKE_DL_LIBS}
|
${CMAKE_DL_LIBS}
|
||||||
|
delta-service
|
||||||
asar-static
|
asar-static
|
||||||
gmock_main
|
gmock_main
|
||||||
gmock
|
gmock
|
||||||
|
|||||||
78
test/delta_test.cc
Normal file
78
test/delta_test.cc
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include <asar/interface-lib.h>
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <google/protobuf/repeated_field.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/status/status.h"
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
#include "app/delta/client.h"
|
||||||
|
#include "app/delta/service.h"
|
||||||
|
#include "app/core/constants.h"
|
||||||
|
#include "src/app/delta/delta.grpc.pb.h"
|
||||||
|
#include "src/app/delta/delta.pb.h"
|
||||||
|
#include "app/rom.h"
|
||||||
|
|
||||||
|
namespace yaze_test {
|
||||||
|
namespace delta_test {
|
||||||
|
|
||||||
|
TEST(DeltaTest, InitRepoAndPushOk) {
|
||||||
|
yaze::app::delta::DeltaService service;
|
||||||
|
yaze::app::ROM rom;
|
||||||
|
Bytes test_bytes;
|
||||||
|
test_bytes.push_back(0x40);
|
||||||
|
rom.LoadFromBytes(test_bytes);
|
||||||
|
grpc::ServerContext* context;
|
||||||
|
InitRequest init_request;
|
||||||
|
auto repo = init_request.mutable_repo();
|
||||||
|
repo->set_project_name("test_repo");
|
||||||
|
Branch branch;
|
||||||
|
branch.set_branch_name("test_branch");
|
||||||
|
auto new_mutable_commits = branch.mutable_commits();
|
||||||
|
new_mutable_commits->Reserve(5);
|
||||||
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
auto new_commit = new Commit();
|
||||||
|
new_commit->set_commit_id(i);
|
||||||
|
new_commit->set_data(rom.char_data());
|
||||||
|
new_mutable_commits->Add();
|
||||||
|
new_mutable_commits->at(i) = *new_commit;
|
||||||
|
}
|
||||||
|
auto mutable_tree = repo->mutable_tree();
|
||||||
|
mutable_tree->Add();
|
||||||
|
mutable_tree->at(0) = branch;
|
||||||
|
InitResponse init_response;
|
||||||
|
auto init_status = service.Init(context, &init_request, &init_response);
|
||||||
|
EXPECT_TRUE(init_status.ok());
|
||||||
|
|
||||||
|
PushRequest request;
|
||||||
|
request.set_branch_name("test_branch");
|
||||||
|
request.set_repository_name("test_repo");
|
||||||
|
auto mutable_commits = request.mutable_commits();
|
||||||
|
mutable_commits->Reserve(5);
|
||||||
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
auto new_commit = new Commit();
|
||||||
|
new_commit->set_commit_id(i * 2);
|
||||||
|
mutable_commits->Add();
|
||||||
|
mutable_commits->at(i) = *new_commit;
|
||||||
|
}
|
||||||
|
PushResponse reply;
|
||||||
|
auto status = service.Push(context, &request, &reply);
|
||||||
|
EXPECT_TRUE(status.ok());
|
||||||
|
|
||||||
|
auto repos = service.Repos();
|
||||||
|
auto result_branch = repos.at(0).tree();
|
||||||
|
std::cerr << result_branch.at(0).DebugString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace asm_test
|
||||||
|
} // namespace yaze_test
|
||||||
Reference in New Issue
Block a user