diff --git a/.gitignore b/.gitignore index d09973a9..87c614f9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,11 +27,12 @@ *.out *.app -# custom files and directories +# custom files and directories third_party/_submodules _out/ build/ bin/ +obj/ .idea node_modules @@ -41,4 +42,4 @@ cmd/protoc-gen-cpp-tableau-loader/protoc-gen-cpp-tableau-loader cmd/protoc-gen-go-tableau-loader/protoc-gen-go-tableau-loader test/go-tableau-loader/go-tableau-loader -_lab/ts/src/protoconf \ No newline at end of file +_lab/ts/src/protoconf diff --git a/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc b/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc index 5c60d98b..52a44b99 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc @@ -1,5 +1,9 @@ #include "load.pc.h" +#if __cplusplus >= 201703L +#include +#endif + #include "logger.pc.h" #include "util.pc.h" @@ -175,8 +179,13 @@ bool LoadMessageWithPatch(google::protobuf::Message& msg, const std::string& pat // patch path specified in PatchPaths, then use it instead of PatchDirs. patch_paths = iter->second; } else { + std::string filename = name + util::Format2Ext(fmt); for (auto&& patch_dir : options->patch_dirs) { - patch_paths.emplace_back(patch_dir + name + util::Format2Ext(fmt)); +#if __cplusplus >= 201703L + patch_paths.emplace_back((std::filesystem::path(patch_dir) / filename).make_preferred().string()); +#else + patch_paths.emplace_back(patch_dir + kPathSeperator + filename); +#endif } } @@ -276,7 +285,12 @@ bool LoadMessage(google::protobuf::Message& msg, const std::string& dir, Format } } if (path.empty()) { - path = dir + name + util::Format2Ext(fmt); + std::string filename = name + util::Format2Ext(fmt); +#if __cplusplus >= 201703L + path = (std::filesystem::path(dir) / filename).make_preferred().string(); +#else + path = dir + kPathSeperator + filename; +#endif } const google::protobuf::Descriptor* descriptor = msg.GetDescriptor(); diff --git a/cmd/protoc-gen-cpp-tableau-loader/embed/messager.pc.h b/cmd/protoc-gen-cpp-tableau-loader/embed/messager.pc.h index a021f59e..3949b256 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/messager.pc.h +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/messager.pc.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -14,9 +15,6 @@ class Messager { public: struct Stats { std::chrono::microseconds duration; // total load time consuming. - // TODO: crc32 of config file to decide whether changed or not - // std::string crc32; - // int64_t last_modified_time = 0; // unix timestamp }; public: diff --git a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc index 72cbc824..e6ec6c69 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc @@ -9,7 +9,6 @@ #if __cplusplus >= 201703L #include -namespace fs = std::filesystem; #else #ifdef _WIN32 #include @@ -26,9 +25,6 @@ namespace fs = std::filesystem; namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -static constexpr char kPathSeperator = '\\'; -#else -static constexpr char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; @@ -44,7 +40,7 @@ namespace util { int Mkdir(const std::string& path) { #if __cplusplus >= 201703L std::error_code ec; - if (!fs::create_directories(path, ec)) { + if (!std::filesystem::create_directories(path, ec)) { if (ec) { std::cerr << "system error: " << ec.message() << std::endl; return -1; @@ -72,7 +68,7 @@ int Mkdir(const std::string& path) { std::string GetDir(const std::string& path) { #if __cplusplus >= 201703L - return fs::path(path).parent_path().string(); + return std::filesystem::path(path).parent_path().string(); #else size_t pos = path.find_last_of(kPathSeperator); if (pos != std::string::npos) { @@ -84,7 +80,7 @@ std::string GetDir(const std::string& path) { bool ExistsFile(const std::string& filename) { #if __cplusplus >= 201703L - return fs::exists(filename); + return std::filesystem::exists(filename); #else std::ifstream file(filename); // returns true if the file exists and is accessible @@ -137,14 +133,6 @@ const std::string& Format2Ext(Format fmt) { } } -bool Message2JSON(const google::protobuf::Message& msg, std::string& json) { - google::protobuf::util::JsonPrintOptions options; - options.add_whitespace = true; - options.always_print_primitive_fields = true; - options.preserve_proto_field_names = true; - return google::protobuf::util::MessageToJsonString(msg, &json, options).ok(); -} - bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options /* = nullptr */) { google::protobuf::util::Status status; if (options != nullptr) { diff --git a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h index ab8d9e08..7e21f23b 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h @@ -11,6 +11,15 @@ namespace tableau { const std::string& GetErrMsg(); void SetErrMsg(const std::string& msg); +#if __cplusplus < 201703L +// Platform-specific path separator +#ifdef _WIN32 +constexpr char kPathSeperator = '\\'; +#else +constexpr char kPathSeperator = '/'; +#endif +#endif + enum class Format { kUnknown, kJSON, @@ -73,7 +82,6 @@ Format Ext2Format(const std::string& ext); // and the error message can be obtained by GetErrMsg(). const std::string& Format2Ext(Format fmt); -bool Message2JSON(const google::protobuf::Message& msg, std::string& json); bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options = nullptr); bool Text2Message(const std::string& text, google::protobuf::Message& msg); bool Bin2Message(const std::string& bin, google::protobuf::Message& msg); diff --git a/cmd/protoc-gen-cpp-tableau-loader/hub.go b/cmd/protoc-gen-cpp-tableau-loader/hub.go index a181f686..c74fe51f 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/hub.go +++ b/cmd/protoc-gen-cpp-tableau-loader/hub.go @@ -138,10 +138,6 @@ func generateHubCppRegistry(gen *protogen.Plugin, g *protogen.GeneratedFile, pro } const hubHpp = `#pragma once -#include -#include -#include - #include #include #include @@ -290,12 +286,6 @@ void Registry::Register() { const hubCppHeader = `#include "hub.pc.h" -#include -#include -#include - -#include - #include "logger.pc.h" #include "messager.pc.h" #include "util.pc.h"` diff --git a/test/cpp-tableau-loader/src/CMakeLists.txt b/test/cpp-tableau-loader/src/CMakeLists.txt index d8f72795..b827e3d4 100644 --- a/test/cpp-tableau-loader/src/CMakeLists.txt +++ b/test/cpp-tableau-loader/src/CMakeLists.txt @@ -22,7 +22,7 @@ if (MSVC) if(USE_CPP17) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG /std:c++17") else() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG /std:c++11") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /DNDEBUG") endif() else() if(USE_CPP17) diff --git a/test/cpp-tableau-loader/src/protoconf/hub.pc.cc b/test/cpp-tableau-loader/src/protoconf/hub.pc.cc index a39c0353..c4339b8a 100644 --- a/test/cpp-tableau-loader/src/protoconf/hub.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/hub.pc.cc @@ -5,12 +5,6 @@ #include "hub.pc.h" -#include -#include -#include - -#include - #include "logger.pc.h" #include "messager.pc.h" #include "util.pc.h" diff --git a/test/cpp-tableau-loader/src/protoconf/hub.pc.h b/test/cpp-tableau-loader/src/protoconf/hub.pc.h index 62fa5779..72c1593f 100644 --- a/test/cpp-tableau-loader/src/protoconf/hub.pc.h +++ b/test/cpp-tableau-loader/src/protoconf/hub.pc.h @@ -4,10 +4,6 @@ // - protoc v3.19.3 #pragma once -#include -#include -#include - #include #include #include diff --git a/test/cpp-tableau-loader/src/protoconf/load.pc.cc b/test/cpp-tableau-loader/src/protoconf/load.pc.cc index fa46ea5c..90e3ee39 100644 --- a/test/cpp-tableau-loader/src/protoconf/load.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/load.pc.cc @@ -5,6 +5,10 @@ #include "load.pc.h" +#if __cplusplus >= 201703L +#include +#endif + #include "logger.pc.h" #include "util.pc.h" @@ -180,8 +184,13 @@ bool LoadMessageWithPatch(google::protobuf::Message& msg, const std::string& pat // patch path specified in PatchPaths, then use it instead of PatchDirs. patch_paths = iter->second; } else { + std::string filename = name + util::Format2Ext(fmt); for (auto&& patch_dir : options->patch_dirs) { - patch_paths.emplace_back(patch_dir + name + util::Format2Ext(fmt)); +#if __cplusplus >= 201703L + patch_paths.emplace_back((std::filesystem::path(patch_dir) / filename).make_preferred().string()); +#else + patch_paths.emplace_back(patch_dir + kPathSeperator + filename); +#endif } } @@ -281,7 +290,12 @@ bool LoadMessage(google::protobuf::Message& msg, const std::string& dir, Format } } if (path.empty()) { - path = dir + name + util::Format2Ext(fmt); + std::string filename = name + util::Format2Ext(fmt); +#if __cplusplus >= 201703L + path = (std::filesystem::path(dir) / filename).make_preferred().string(); +#else + path = dir + kPathSeperator + filename; +#endif } const google::protobuf::Descriptor* descriptor = msg.GetDescriptor(); diff --git a/test/cpp-tableau-loader/src/protoconf/messager.pc.h b/test/cpp-tableau-loader/src/protoconf/messager.pc.h index b7151709..c0f73bfc 100644 --- a/test/cpp-tableau-loader/src/protoconf/messager.pc.h +++ b/test/cpp-tableau-loader/src/protoconf/messager.pc.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include @@ -19,9 +20,6 @@ class Messager { public: struct Stats { std::chrono::microseconds duration; // total load time consuming. - // TODO: crc32 of config file to decide whether changed or not - // std::string crc32; - // int64_t last_modified_time = 0; // unix timestamp }; public: diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.cc b/test/cpp-tableau-loader/src/protoconf/util.pc.cc index 9266d816..1e92f206 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.cc @@ -14,7 +14,6 @@ #if __cplusplus >= 201703L #include -namespace fs = std::filesystem; #else #ifdef _WIN32 #include @@ -31,9 +30,6 @@ namespace fs = std::filesystem; namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -static constexpr char kPathSeperator = '\\'; -#else -static constexpr char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; @@ -49,7 +45,7 @@ namespace util { int Mkdir(const std::string& path) { #if __cplusplus >= 201703L std::error_code ec; - if (!fs::create_directories(path, ec)) { + if (!std::filesystem::create_directories(path, ec)) { if (ec) { std::cerr << "system error: " << ec.message() << std::endl; return -1; @@ -77,7 +73,7 @@ int Mkdir(const std::string& path) { std::string GetDir(const std::string& path) { #if __cplusplus >= 201703L - return fs::path(path).parent_path().string(); + return std::filesystem::path(path).parent_path().string(); #else size_t pos = path.find_last_of(kPathSeperator); if (pos != std::string::npos) { @@ -89,7 +85,7 @@ std::string GetDir(const std::string& path) { bool ExistsFile(const std::string& filename) { #if __cplusplus >= 201703L - return fs::exists(filename); + return std::filesystem::exists(filename); #else std::ifstream file(filename); // returns true if the file exists and is accessible @@ -142,14 +138,6 @@ const std::string& Format2Ext(Format fmt) { } } -bool Message2JSON(const google::protobuf::Message& msg, std::string& json) { - google::protobuf::util::JsonPrintOptions options; - options.add_whitespace = true; - options.always_print_primitive_fields = true; - options.preserve_proto_field_names = true; - return google::protobuf::util::MessageToJsonString(msg, &json, options).ok(); -} - bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options /* = nullptr */) { google::protobuf::util::Status status; if (options != nullptr) { diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.h b/test/cpp-tableau-loader/src/protoconf/util.pc.h index 9d24149b..32b1b3d3 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.h +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.h @@ -16,6 +16,15 @@ namespace tableau { const std::string& GetErrMsg(); void SetErrMsg(const std::string& msg); +#if __cplusplus < 201703L +// Platform-specific path separator +#ifdef _WIN32 +constexpr char kPathSeperator = '\\'; +#else +constexpr char kPathSeperator = '/'; +#endif +#endif + enum class Format { kUnknown, kJSON, @@ -78,7 +87,6 @@ Format Ext2Format(const std::string& ext); // and the error message can be obtained by GetErrMsg(). const std::string& Format2Ext(Format fmt); -bool Message2JSON(const google::protobuf::Message& msg, std::string& json); bool JSON2Message(const std::string& json, google::protobuf::Message& msg, const LoadOptions* options = nullptr); bool Text2Message(const std::string& text, google::protobuf::Message& msg); bool Bin2Message(const std::string& bin, google::protobuf::Message& msg);