From a5dc3a251d72ef984dad955ae9f0d7e6b8128c14 Mon Sep 17 00:00:00 2001 From: Mariusz Barczak Date: Mon, 8 Apr 2024 11:45:32 +0200 Subject: [PATCH 1/3] Update gitignore Signed-off-by: Mariusz Barczak --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cbd5e72..3a72af4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ build/ tools/coding_style/backup tools/third_party/ - +.vscode/ From 368d159f900a955bce204c59318ae99e9266e3fd Mon Sep 17 00:00:00 2001 From: Mariusz Barczak Date: Mon, 8 Apr 2024 11:59:21 +0200 Subject: [PATCH 2/3] Add gRPC third party. This commit adds gRPC as a third party library. The intention is to allow auto CLI to use gRPC for communication. In addition protocol buffer will delivered with gRPC. Signed-off-by: Mariusz Barczak --- .gitmodules | 3 + CMakeLists.txt | 2 +- README.md | 3 +- doc/NOTICE | 16 ++++ source/CMakeLists.txt | 77 +++++++++---------- source/examples/auto_cli/CMakeLists.txt | 21 +++-- source/examples/plugin/client/CMakeLists.txt | 7 +- source/examples/plugin/proto/CMakeLists.txt | 19 +++-- source/examples/plugin/server/CMakeLists.txt | 4 - source/octf/CMakeLists.txt | 1 + source/octf/cli/internal/CLIUtils.cpp | 3 +- .../interface/InterfaceTraceParsingImpl.cpp | 9 ++- source/octf/proto/CMakeLists.txt | 43 +++++------ .../ParsedIoTraceEventHandlerPrinter.cpp | 7 +- .../parser/ParsedIoTraceEventHandlerPrinter.h | 2 +- .../parser/TraceEventHandlerJsonPrinter.h | 8 +- source/octf/utils/Exception.h | 1 + source/octf/utils/ProtobufReaderWriter.cpp | 8 +- source/octf/utils/ProtobufReaderWriter.h | 1 + source/octf/utils/internal/Logger.h | 3 +- source/third_party/CMakeLists.txt | 2 +- source/third_party/grpc | 1 + source/third_party/octf-grpc.cmake | 64 +++++++++++++++ 23 files changed, 188 insertions(+), 117 deletions(-) create mode 160000 source/third_party/grpc create mode 100644 source/third_party/octf-grpc.cmake diff --git a/.gitmodules b/.gitmodules index 0be96c6..e00f774 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "source/third_party/libfort"] path = source/third_party/libfort url = https://github.com/seleznevae/libfort.git +[submodule "source/third_party/grpc"] + path = source/third_party/grpc + url = https://github.com/grpc/grpc.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6353a..bcd05b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ include(octf-version.cmake) project(octf VERSION ${OCTF_VERSION} LANGUAGES C CXX) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/third_party;${CMAKE_PREFIX_PATH}") include(octf-paths.cmake) diff --git a/README.md b/README.md index db9b18a..93b346e 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ To build OCTF, the following tools are needed: * CMake 3.9 or above > **NOTE:** You can use setup dependencies script to install above tools. -> +> ~~~{.sh} sudo ./setup_dependencies.sh ~~~ @@ -165,6 +165,7 @@ OCTF uses: - Google Protocol Buffers - SeCoe Safe String Library - Google Test +- gRPC - cmake - libfort diff --git a/doc/NOTICE b/doc/NOTICE index 15a3c2e..a4568c9 100644 --- a/doc/NOTICE +++ b/doc/NOTICE @@ -178,3 +178,19 @@ 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. +****** +gRPC +****** +Copyright 2014 gRPC authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 8594ae3..cfd4d5f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -2,21 +2,18 @@ set(srcDir ${CMAKE_CURRENT_SOURCE_DIR}/octf) set(buildDir ${CMAKE_CURRENT_BINARY_DIR}/octf) -add_library(octf SHARED "" - $ - $ -) -set(OCTF_PROTO_DIR ${CMAKE_CURRENT_BINARY_DIR}/octf/proto) add_subdirectory(third_party) -add_subdirectory(octf) - -find_package(Protobuf 3.0 REQUIRED) - -add_subdirectory(octf/proto) -set(PROTOBUF_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS}" "${CMAKE_CURRENT_SOURCE_DIR}/octf/proto") +find_package(Protobuf CONFIG REQUIRED) +add_library(octf SHARED "" + $ + $ +) set_target_properties(octf PROPERTIES LINKER_LANGUAGE CXX) target_compile_options(octf PRIVATE -Wall -Wextra) + +set(OCTF_PROTO_DIR ${CMAKE_CURRENT_BINARY_DIR}/octf/proto) + target_include_directories(octf PUBLIC $ @@ -25,26 +22,25 @@ target_include_directories(octf $ $ ) -target_include_directories(octf - SYSTEM PRIVATE ${PROTOBUF_INCLUDE_DIR} -) # Specify libraries to link target_link_libraries(octf PUBLIC pthread) -target_link_libraries(octf PRIVATE ${PROTOBUF_LIBRARY}) +target_link_libraries(octf PUBLIC protobuf::libprotobuf) target_link_libraries(octf PRIVATE fort) +add_subdirectory(octf) + # Add version definitions target_compile_definitions(octf - PUBLIC - OCTF_VERSION=${OCTF_VERSION} - OCTF_VERSION_LABEL=${OCTF_VERSION_LABEL} + PUBLIC + OCTF_VERSION=${OCTF_VERSION} + OCTF_VERSION_LABEL=${OCTF_VERSION_LABEL} ) # Define static version of octf library and copy all properties from shared one add_library(octf-static STATIC EXCLUDE_FROM_ALL "" - $ - $ + $ + $ ) get_target_property(OCTF_SRCS octf SOURCES) @@ -65,15 +61,15 @@ set_target_properties(octf-static PROPERTIES INCLUDE_DIRECTORIES "${OCTF_INC}") set_target_properties(octf-static PROPERTIES COMPILE_OPTIONS "${OCTF_OPTS}") set_target_properties(octf-static PROPERTIES COMPILE_DEFINITIONS "${OCTF_DEFS}") - file(GLOB_RECURSE protoFiles - ${srcDir}/proto/*.proto) + ${srcDir}/proto/*.proto) file(GLOB_RECURSE publicHeaders - ${srcDir}/*.h) + ${srcDir}/*.h) # Replace all .proto extensions to pb.h, this is needed in order to # get a list of pb.h files before they are generated string(REPLACE "\.proto" "\.pb.h" protoHeaders "${protoFiles}") + # Modify path from source to build STRING(REGEX REPLACE "${srcDir}([^;]*\.pb\.h)" @@ -81,23 +77,24 @@ STRING(REGEX REPLACE protoHeaders "${protoHeaders}") set(publicHeaders ${publicHeaders} ${protoHeaders}) + # Remove headers not added to sdk (from internal directories) FOREACH(item ${publicHeaders}) - IF(${item} MATCHES ".*internal\/.*") - LIST(REMOVE_ITEM publicHeaders ${item}) - ENDIF(${item} MATCHES ".*internal\/.*") + IF(${item} MATCHES ".*internal\/.*") + LIST(REMOVE_ITEM publicHeaders ${item}) + ENDIF(${item} MATCHES ".*internal\/.*") ENDFOREACH(item) # Generate and copy octf.h header file, do this in pre-link phase add_custom_command( - TARGET octf - PRE_LINK - COMMAND ${srcDir}/generateCommonHeader.sh "\"${publicHeaders}\"" ${buildDir} + TARGET octf + PRE_LINK + COMMAND ${srcDir}/generateCommonHeader.sh "\"${publicHeaders}\"" ${buildDir} ) add_custom_command( - TARGET octf-static - PRE_LINK - COMMAND ${srcDir}/generateCommonHeader.sh "\"${publicHeaders}\"" ${buildDir} + TARGET octf-static + PRE_LINK + COMMAND ${srcDir}/generateCommonHeader.sh "\"${publicHeaders}\"" ${buildDir} ) # Install install-manifest with list of installed files, to allow uninstalling @@ -115,22 +112,20 @@ install(FILES ${OCTF_MANIFEST_PREINSTALL} # because we must use GNUUtils to obtain the proper path to install-manifest add_custom_target(octf-uninstall COMMAND test -f ${OCTF_MANIFEST_POSTINSTALL} && - xargs rm -vf < ${OCTF_MANIFEST_POSTINSTALL} || - echo "-- No OCTF install manifest found: ${OCTF_MANIFEST_POSTINSTALL} Nothing to uninstall!" + xargs rm -vf < ${OCTF_MANIFEST_POSTINSTALL} || + echo "-- No OCTF install manifest found: ${OCTF_MANIFEST_POSTINSTALL} Nothing to uninstall!" ) - # Install octf.so library and add octf target to export group 'octf-targets' install(TARGETS octf DESTINATION ${OCTF_LIBRARY_DIR} EXPORT octf-targets COMPONENT octf-install) -if (${CMAKE_INSTALL_PREFIX} STREQUAL "/") - install( - CODE "execute_process(COMMAND ldconfig)" - COMPONENT octf-post-install - ) +if(${CMAKE_INSTALL_PREFIX} STREQUAL "/") + install( + CODE "execute_process(COMMAND ldconfig)" + COMPONENT octf-post-install + ) endif() - # Install headers and proto files install(DIRECTORY octf ${CMAKE_CURRENT_BINARY_DIR}/octf DESTINATION ${OCTF_INCLUDE_DIR} diff --git a/source/examples/auto_cli/CMakeLists.txt b/source/examples/auto_cli/CMakeLists.txt index 1ccec02..0c30db7 100644 --- a/source/examples/auto_cli/CMakeLists.txt +++ b/source/examples/auto_cli/CMakeLists.txt @@ -1,19 +1,16 @@ add_executable(auto-cli "") -target_link_libraries(auto-cli octf ${PROTOBUF_LIBRARY}) - -target_include_directories(auto-cli - SYSTEM PRIVATE ${PROTOBUF_INCLUDE_DIR} -) - -# Generate protocol buffer headers and sources -protobuf_generate_cpp(PROTO_SRC PROTO_HEADER InterfaceHelloWorld.proto) - +target_link_libraries(auto-cli octf protobuf::libprotobuf) target_include_directories(auto-cli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(auto-cli PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_sources(auto-cli -PRIVATE +target_sources(auto-cli PRIVATE ${CMAKE_CURRENT_LIST_DIR}/main.cpp ${CMAKE_CURRENT_LIST_DIR}/InterfaceHelloWorldImpl.cpp - ${PROTO_SRC} + ${CMAKE_CURRENT_LIST_DIR}/InterfaceHelloWorld.proto +) + +protobuf_generate(TARGET auto-cli + LANGUAGE CPP + IMPORT_DIRS ${OCTF_PROTOBUF_IMPORT_DIRS} ${CMAKE_CURRENT_LIST_DIR} + GENERATE_EXTENSIONS .pb.h .pb.cc ) diff --git a/source/examples/plugin/client/CMakeLists.txt b/source/examples/plugin/client/CMakeLists.txt index 64bd41a..5c04058 100644 --- a/source/examples/plugin/client/CMakeLists.txt +++ b/source/examples/plugin/client/CMakeLists.txt @@ -1,13 +1,8 @@ add_executable(testPluginClient "") -target_include_directories(testPluginClient PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_include_directories(testPluginClient PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/proto) -target_include_directories(testPluginClient PRIVATE ${PROTOBUF_INCLUDE_DIR}) +target_link_libraries(testPluginClient octf protoexamples) target_sources(testPluginClient PRIVATE ${CMAKE_CURRENT_LIST_DIR}/TestPluginShadow.h ${CMAKE_CURRENT_LIST_DIR}/TestPluginShadow.cpp ${CMAKE_CURRENT_LIST_DIR}/main.cpp ) -target_link_libraries(testPluginClient octf) -target_link_libraries(testPluginClient protoexamples) -target_link_libraries(testPluginClient ${PROTOBUF_LIBRARIES}) diff --git a/source/examples/plugin/proto/CMakeLists.txt b/source/examples/plugin/proto/CMakeLists.txt index ded2d0a..bb8cc00 100644 --- a/source/examples/plugin/proto/CMakeLists.txt +++ b/source/examples/plugin/proto/CMakeLists.txt @@ -1,16 +1,15 @@ -set(protoListExamples - InterfaceTest.proto - test.proto - ) - -protobuf_generate_cpp(PROTO_SRC PROTO_HEADER ${protoListExamples}) -add_library(protoexamples STATIC ${PROTO_HEADER} ${PROTO_SRC} ${protoListExamples}) -add_dependencies(protoexamples protooctf) +add_library(protoexamples STATIC + ${CMAKE_CURRENT_LIST_DIR}/InterfaceTest.proto + ${CMAKE_CURRENT_LIST_DIR}/test.proto +) +protobuf_generate(TARGET protoexamples + IMPORT_DIRS ${OCTF_PROTOBUF_IMPORT_DIRS} ${CMAKE_CURRENT_LIST_DIR} +) target_include_directories(protoexamples PUBLIC - ${PROTOBUF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${OCTF_PROTO_DIR} - ) +) +target_link_libraries(protoexamples PUBLIC protobuf::libprotobuf) diff --git a/source/examples/plugin/server/CMakeLists.txt b/source/examples/plugin/server/CMakeLists.txt index cae3791..642ab49 100644 --- a/source/examples/plugin/server/CMakeLists.txt +++ b/source/examples/plugin/server/CMakeLists.txt @@ -1,9 +1,5 @@ add_executable(testPlugin "") target_link_libraries(testPlugin octf protoexamples) -target_link_libraries(testPlugin ${PROTOBUF_LIBRARIES}) -target_include_directories(testPlugin PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_include_directories(testPlugin PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/proto) -target_include_directories(testPlugin PRIVATE ${PROTOBUF_INCLUDE_DIR} ${OCTF_PROTO_DIR}) target_sources(testPlugin PRIVATE ${CMAKE_CURRENT_LIST_DIR}/InterfaceTestImpl.h diff --git a/source/octf/CMakeLists.txt b/source/octf/CMakeLists.txt index 7f909a3..f8503ec 100644 --- a/source/octf/CMakeLists.txt +++ b/source/octf/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(proto) add_subdirectory(cli) add_subdirectory(communication) add_subdirectory(interface) diff --git a/source/octf/cli/internal/CLIUtils.cpp b/source/octf/cli/internal/CLIUtils.cpp index b64e08d..7d1faea 100644 --- a/source/octf/cli/internal/CLIUtils.cpp +++ b/source/octf/cli/internal/CLIUtils.cpp @@ -144,7 +144,6 @@ void printKeys(stringstream &ss, } void printOutputMessage(MessageShRef message) { - google::protobuf::util::Status status; google::protobuf::util::JsonPrintOptions opts; string strOutput; @@ -156,7 +155,7 @@ void printOutputMessage(MessageShRef message) { // this field in output, enable this opts.always_print_primitive_fields = true; - status = google::protobuf::util::MessageToJsonString(*message, &strOutput, + auto status = google::protobuf::util::MessageToJsonString(*message, &strOutput, opts); if (!status.ok()) { throw ProtoBufferException(status.ToString()); diff --git a/source/octf/interface/InterfaceTraceParsingImpl.cpp b/source/octf/interface/InterfaceTraceParsingImpl.cpp index 298e619..ab276de 100644 --- a/source/octf/interface/InterfaceTraceParsingImpl.cpp +++ b/source/octf/interface/InterfaceTraceParsingImpl.cpp @@ -476,7 +476,7 @@ void InterfaceTraceParsingImpl::BuildExtensions( // Define variables for std::string jsonTrace; - google::protobuf::util::JsonOptions jsonOptions; + google::protobuf::util::JsonPrintOptions jsonOptions; jsonOptions.always_print_primitive_fields = true; jsonOptions.add_whitespace = false; table::Table tab; @@ -523,8 +523,11 @@ void InterfaceTraceParsingImpl::BuildExtensions( } break; case proto::OutputFormat::JSON: { jsonTrace.clear(); - google::protobuf::util::MessageToJsonString(msg, &jsonTrace, - jsonOptions); + auto status = google::protobuf::util::MessageToJsonString( + msg, &jsonTrace, jsonOptions); + if (!status.ok()) { + throw Exception("Failed to convert message to JSON"); + } cout << jsonTrace << std::endl; } break; default: { diff --git a/source/octf/proto/CMakeLists.txt b/source/octf/proto/CMakeLists.txt index a3c426c..2da7e1e 100644 --- a/source/octf/proto/CMakeLists.txt +++ b/source/octf/proto/CMakeLists.txt @@ -1,28 +1,22 @@ -set(protoList - configuration.proto - defs.proto - InterfaceCLI.proto - InterfaceIdentification.proto - InterfaceTraceParsing.proto - InterfaceService.proto - InterfaceTraceCreating.proto - InterfaceTraceManagement.proto - InterfaceConfiguration.proto - opts.proto - packets.proto - trace.proto - parsedTrace.proto - traceDefinitions.proto - statistics.proto - extensions.proto +add_library(protooctf OBJECT + ${CMAKE_CURRENT_LIST_DIR}/configuration.proto + ${CMAKE_CURRENT_LIST_DIR}/defs.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceCLI.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceIdentification.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceTraceParsing.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceService.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceTraceCreating.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceTraceManagement.proto + ${CMAKE_CURRENT_LIST_DIR}/InterfaceConfiguration.proto + ${CMAKE_CURRENT_LIST_DIR}/opts.proto + ${CMAKE_CURRENT_LIST_DIR}/packets.proto + ${CMAKE_CURRENT_LIST_DIR}/trace.proto + ${CMAKE_CURRENT_LIST_DIR}/parsedTrace.proto + ${CMAKE_CURRENT_LIST_DIR}/traceDefinitions.proto + ${CMAKE_CURRENT_LIST_DIR}/statistics.proto + ${CMAKE_CURRENT_LIST_DIR}/extensions.proto ) -protobuf_generate_cpp(PROTO_SRC PROTO_HEADER ${protoList}) -add_library(protooctf OBJECT ${PROTO_HEADER} ${PROTO_SRC}) -target_include_directories(protooctf - PUBLIC - ${PROTOBUF_INCLUDE_DIR} - ${CMAKE_SOURCE_DIR} - ) +target_link_libraries(protooctf PUBLIC protobuf::libprotobuf) target_compile_options(protooctf PRIVATE -Wno-unused-parameter PUBLIC -fPIC) # Set import dirs for protobuf and store them in 'global' variable OCTF_PROTOBUF_IMPORT_DIRS @@ -30,3 +24,4 @@ target_compile_options(protooctf PRIVATE -Wno-unused-parameter PUBLIC -fPIC) set(PROTOBUF_IMPORT_DIRS ${PROTOBUF_IMPORT_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}") set(OCTF_PROTOBUF_IMPORT_DIRS ${PROTOBUF_IMPORT_DIRS} CACHE INTERNAL "OCTF_PROTOBUF_IMPORT_DIRS") +protobuf_generate(TARGET protooctf) diff --git a/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.cpp b/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.cpp index 18ecba0..e8a1481 100644 --- a/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.cpp +++ b/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.cpp @@ -30,8 +30,11 @@ void ParsedIoTraceEventHandlerPrinter::handleIO( } break; case proto::OutputFormat::JSON: { m_jsonTrace.clear(); - google::protobuf::util::MessageToJsonString(io, &m_jsonTrace, - m_jsonOptions); + auto status = google::protobuf::util::MessageToJsonString(io, &m_jsonTrace, + m_jsonOptions); + if (!status.ok()) { + throw Exception("Failed to convert event to JSON"); + } std::cout << m_jsonTrace << std::endl; } break; default: { diff --git a/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.h b/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.h index 5f9a4ac..001a994 100644 --- a/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.h +++ b/source/octf/trace/parser/ParsedIoTraceEventHandlerPrinter.h @@ -32,7 +32,7 @@ class ParsedIoTraceEventHandlerPrinter : public ParsedIoTraceEventHandler { TraceShRef m_trace; table::Table m_table; proto::OutputFormat m_format; - google::protobuf::util::JsonOptions m_jsonOptions; + google::protobuf::util::JsonPrintOptions m_jsonOptions; std::string m_jsonTrace; }; diff --git a/source/octf/trace/parser/TraceEventHandlerJsonPrinter.h b/source/octf/trace/parser/TraceEventHandlerJsonPrinter.h index 34ac882..5798d1b 100644 --- a/source/octf/trace/parser/TraceEventHandlerJsonPrinter.h +++ b/source/octf/trace/parser/TraceEventHandlerJsonPrinter.h @@ -35,16 +35,20 @@ class TraceEventHandlerJsonPrinter : public octf::TraceEventHandler { void handleEvent(std::shared_ptr traceEvent) override { m_jsonTrace.clear(); - google::protobuf::util::MessageToJsonString( + auto status = google::protobuf::util::MessageToJsonString( *traceEvent.get(), &m_jsonTrace, m_jsonOptions); + if (!status.ok()) { + throw Exception("Failed to convert event to JSON"); + } + // TODO (mariuszbarczak) Output stream into which print traces should be // defined by constructor std::cout << m_jsonTrace << std::endl; } private: - google::protobuf::util::JsonOptions m_jsonOptions; + google::protobuf::util::JsonPrintOptions m_jsonOptions; std::string m_jsonTrace; }; diff --git a/source/octf/utils/Exception.h b/source/octf/utils/Exception.h index 6ddbb50..1151c69 100644 --- a/source/octf/utils/Exception.h +++ b/source/octf/utils/Exception.h @@ -5,6 +5,7 @@ #ifndef SOURCE_OCTF_UTILS_EXCEPTION_H #define SOURCE_OCTF_UTILS_EXCEPTION_H +#include #include namespace octf { diff --git a/source/octf/utils/ProtobufReaderWriter.cpp b/source/octf/utils/ProtobufReaderWriter.cpp index d2d3242..49b982e 100644 --- a/source/octf/utils/ProtobufReaderWriter.cpp +++ b/source/octf/utils/ProtobufReaderWriter.cpp @@ -84,14 +84,13 @@ bool ProtobufReaderWriter::read(google::protobuf::Message &message) { } // Parse JSON string into protocol buffer message - google::protobuf::util::Status status; google::protobuf::util::JsonParseOptions opts; - // Allow unknown fields - to allow forward compability (e.g. when summary + // Allow unknown fields - to allow forward compatibility (e.g. when summary // contains a new field created by a newer version of library) opts.ignore_unknown_fields = true; - status = google::protobuf::util::JsonStringToMessage(fileContent, &message, + auto status = google::protobuf::util::JsonStringToMessage(fileContent, &message, opts); return status.ok(); @@ -110,7 +109,6 @@ bool ProtobufReaderWriter::write(const google::protobuf::Message &message) { } // 1. First generate string with configuration - google::protobuf::util::Status status; google::protobuf::util::JsonPrintOptions opts; std::string str; @@ -122,7 +120,7 @@ bool ProtobufReaderWriter::write(const google::protobuf::Message &message) { // this field in output, enable this opts.always_print_primitive_fields = true; - status = google::protobuf::util::MessageToJsonString(message, &str, opts); + auto status = google::protobuf::util::MessageToJsonString(message, &str, opts); if (!status.ok()) { return false; }; diff --git a/source/octf/utils/ProtobufReaderWriter.h b/source/octf/utils/ProtobufReaderWriter.h index e1c908b..e8a1052 100644 --- a/source/octf/utils/ProtobufReaderWriter.h +++ b/source/octf/utils/ProtobufReaderWriter.h @@ -7,6 +7,7 @@ #define SOURCE_OCTF_UTILS_PROTOBUFREADERWRITER_H #include +#include #include #include diff --git a/source/octf/utils/internal/Logger.h b/source/octf/utils/internal/Logger.h index 3a456b1..c46f59b 100644 --- a/source/octf/utils/internal/Logger.h +++ b/source/octf/utils/internal/Logger.h @@ -211,14 +211,13 @@ class Logger : public NonCopyable { break; } - google::protobuf::util::Status status; google::protobuf::util::JsonPrintOptions opts; std::string result; opts.add_whitespace = true; opts.always_print_primitive_fields = false; - status = google::protobuf::util::MessageToJsonString(trace, &result, + auto status = google::protobuf::util::MessageToJsonString(trace, &result, opts); if (!status.ok()) { return "Cannot generate trace in JSON format"; diff --git a/source/third_party/CMakeLists.txt b/source/third_party/CMakeLists.txt index 76a4d3f..f809ab0 100644 --- a/source/third_party/CMakeLists.txt +++ b/source/third_party/CMakeLists.txt @@ -1,4 +1,4 @@ include(octf-safestringlib.cmake) -include(octf-protobuf.cmake) include(octf-googletest.cmake) include(octf-libfort.cmake) +include(octf-grpc.cmake) diff --git a/source/third_party/grpc b/source/third_party/grpc new file mode 160000 index 0000000..358bfb5 --- /dev/null +++ b/source/third_party/grpc @@ -0,0 +1 @@ +Subproject commit 358bfb581feeda5bf17dd3b96da1074d84a6ef8d diff --git a/source/third_party/octf-grpc.cmake b/source/third_party/octf-grpc.cmake new file mode 100644 index 0000000..8ae6014 --- /dev/null +++ b/source/third_party/octf-grpc.cmake @@ -0,0 +1,64 @@ +set(WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/grpc") +set(PROTOC_OUT_DIR "${WORKING_DIRECTORY}/src/proto/grpc/reflection/v1alpha") + +# Check if the file indicateing that the grpc library is ready is present +if(NOT EXISTS "${CMAKE_BINARY_DIR}/third_party/grpc.ready") + include(ProcessorCount) + ProcessorCount(N) + + execute_process( + COMMAND "mkdir" "-p" "${WORKING_DIRECTORY}" + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL "0") + message(FATAL_ERROR "Creating directory for grpc library failed") + endif() + + execute_process( + COMMAND ${CMAKE_COMMAND} + "${CMAKE_CURRENT_SOURCE_DIR}/grpc" + "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/third_party" + "-DCMAKE_CXX_FLAGS_INIT=${CMAKE_CXX_FLAGS_RELEASE}" + "-DCMAKE_SHARED_LINKER_FLAGS_INIT=${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" + "-DCMAKE_EXE_LINKER_FLAGS_INIT=${CMAKE_EXE_LINKER_FLAGS_RELEASE}" + "-DCMAKE_C_FLAGS_RELEASE_INIT=${CMAKE_C_FLAGS_RELEASE}" + "-DCMAKE_BUILD_TYPE=Release" + "-DABSL_ENABLE_INSTALL=ON" + WORKING_DIRECTORY "${WORKING_DIRECTORY}" + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL "0") + message(FATAL_ERROR "cmake for protobuf library failed") + endif() + + execute_process( + COMMAND "make" "install" "-j${N}" + WORKING_DIRECTORY ${WORKING_DIRECTORY} + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL "0") + message(FATAL_ERROR "Building and installing of grpc library failed") + endif() + + # Execute process to create an empty file ${CMAKE_BINARY_DIR}/third_party/grpc.ready + execute_process( + COMMAND "touch" "${CMAKE_BINARY_DIR}/third_party/grpc.ready" + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL "0") + message(FATAL_ERROR "Creating file ${CMAKE_BINARY_DIR}/third_party/grpc.ready failed") + endif() + + execute_process( + COMMAND "mkdir" "-p" "${PROTOC_OUT_DIR}" + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL "0") + message(FATAL_ERROR "Creating directory for generated protobuf files failed") + endif() +endif() From 580b43f4e8f4c73eea1473d0a2e41b41f6d1894b Mon Sep 17 00:00:00 2001 From: Mariusz Barczak Date: Mon, 8 Apr 2024 12:22:32 +0200 Subject: [PATCH 3/3] Remove protocol buffer submodule gRPC will provide the protocol Signed-off-by: Mariusz Barczak --- .gitmodules | 3 --- source/third_party/protobuf | 1 - 2 files changed, 4 deletions(-) delete mode 160000 source/third_party/protobuf diff --git a/.gitmodules b/.gitmodules index e00f774..b5a8282 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "source/third_party/safestringlib"] path = source/third_party/safestringlib url = https://github.com/intel/safestringlib -[submodule "source/third_party/protobuf"] - path = source/third_party/protobuf - url = https://github.com/protocolbuffers/protobuf.git [submodule "source/third_party/googletest"] path = source/third_party/googletest url = https://github.com/google/googletest diff --git a/source/third_party/protobuf b/source/third_party/protobuf deleted file mode 160000 index c9869dc..0000000 --- a/source/third_party/protobuf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c9869dc7803eb0a21d7e589c40ff4f9288cd34ae