From 278f8f8e37a78cead8c9e6ddf18dc031b7422f71 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Wed, 7 May 2025 20:26:57 +0800 Subject: [PATCH 1/7] feat: update includes --- .gitignore | 5 +++-- cmd/protoc-gen-cpp-tableau-loader/embed/messager.pc.h | 4 +--- cmd/protoc-gen-cpp-tableau-loader/hub.go | 10 ---------- test/cpp-tableau-loader/src/protoconf/hub.pc.cc | 6 ------ test/cpp-tableau-loader/src/protoconf/hub.pc.h | 4 ---- test/cpp-tableau-loader/src/protoconf/messager.pc.h | 4 +--- 6 files changed, 5 insertions(+), 28 deletions(-) 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/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/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/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/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: From b1775dc3077e095ffcb4b4f0cc19c9aaaf1cae13 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Thu, 8 May 2025 14:55:01 +0800 Subject: [PATCH 2/7] feat: remove useless func --- cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc | 8 -------- cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h | 1 - test/cpp-tableau-loader/src/protoconf/util.pc.cc | 8 -------- test/cpp-tableau-loader/src/protoconf/util.pc.h | 1 - 4 files changed, 18 deletions(-) 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..65fa2e62 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc @@ -137,14 +137,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..dd66d431 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h @@ -73,7 +73,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/test/cpp-tableau-loader/src/protoconf/util.pc.cc b/test/cpp-tableau-loader/src/protoconf/util.pc.cc index 9266d816..d8299b23 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.cc @@ -142,14 +142,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..794cb76a 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.h +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.h @@ -78,7 +78,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); From 325e1769477d80789c7d46f82d280e7b61cca202 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 9 May 2025 15:33:46 +0800 Subject: [PATCH 3/7] feat: use std::filesystem for path joining in c++17 --- .../embed/load.pc.cc | 19 +++++++++++++++++-- .../embed/util.pc.cc | 4 ++-- .../embed/util.pc.h | 3 +++ .../src/protoconf/load.pc.cc | 19 +++++++++++++++++-- .../src/protoconf/util.pc.cc | 4 ++-- .../src/protoconf/util.pc.h | 3 +++ 6 files changed, 44 insertions(+), 8 deletions(-) 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..dd2d8b36 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,10 @@ #include "load.pc.h" +#if __cplusplus >= 201703L +#include +namespace fs = std::filesystem; +#endif + #include "logger.pc.h" #include "util.pc.h" @@ -175,8 +180,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((fs::path(patch_dir) / filename).make_preferred().string()); +#else + patch_paths.emplace_back(patch_dir + kPathSeperator + filename); +#endif } } @@ -276,7 +286,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 = (fs::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/util.pc.cc b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc index 65fa2e62..908bc452 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc @@ -26,9 +26,9 @@ namespace fs = std::filesystem; namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -static constexpr char kPathSeperator = '\\'; +constexpr char kPathSeperator = '\\'; #else -static constexpr char kPathSeperator = '/'; +constexpr char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; 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 dd66d431..c2cb6c07 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,9 @@ namespace tableau { const std::string& GetErrMsg(); void SetErrMsg(const std::string& msg); +// Platform-specific path separator +extern const char kPathSeperator; + enum class Format { kUnknown, kJSON, diff --git a/test/cpp-tableau-loader/src/protoconf/load.pc.cc b/test/cpp-tableau-loader/src/protoconf/load.pc.cc index fa46ea5c..9f0bd6f8 100644 --- a/test/cpp-tableau-loader/src/protoconf/load.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/load.pc.cc @@ -5,6 +5,11 @@ #include "load.pc.h" +#if __cplusplus >= 201703L +#include +namespace fs = std::filesystem; +#endif + #include "logger.pc.h" #include "util.pc.h" @@ -180,8 +185,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((fs::path(patch_dir) / filename).make_preferred().string()); +#else + patch_paths.emplace_back(patch_dir + kPathSeperator + filename); +#endif } } @@ -281,7 +291,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 = (fs::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/util.pc.cc b/test/cpp-tableau-loader/src/protoconf/util.pc.cc index d8299b23..113d1e23 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.cc @@ -31,9 +31,9 @@ namespace fs = std::filesystem; namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -static constexpr char kPathSeperator = '\\'; +constexpr char kPathSeperator = '\\'; #else -static constexpr char kPathSeperator = '/'; +constexpr char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.h b/test/cpp-tableau-loader/src/protoconf/util.pc.h index 794cb76a..ea1fb6c7 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.h +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.h @@ -16,6 +16,9 @@ namespace tableau { const std::string& GetErrMsg(); void SetErrMsg(const std::string& msg); +// Platform-specific path separator +extern const char kPathSeperator; + enum class Format { kUnknown, kJSON, From 2cc5ded769d2b0f3770e2b54592c536aa5d76132 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 9 May 2025 15:37:39 +0800 Subject: [PATCH 4/7] fix: constexpr -> const --- cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc | 4 ++-- test/cpp-tableau-loader/src/protoconf/util.pc.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 908bc452..6386b4ec 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc @@ -26,9 +26,9 @@ namespace fs = std::filesystem; namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -constexpr char kPathSeperator = '\\'; +const char kPathSeperator = '\\'; #else -constexpr char kPathSeperator = '/'; +const char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.cc b/test/cpp-tableau-loader/src/protoconf/util.pc.cc index 113d1e23..2203ab8a 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.cc @@ -31,9 +31,9 @@ namespace fs = std::filesystem; namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -constexpr char kPathSeperator = '\\'; +const char kPathSeperator = '\\'; #else -constexpr char kPathSeperator = '/'; +const char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; From b9994103ad3f8e585a10fc3a4d78e96c469eff00 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 9 May 2025 15:49:49 +0800 Subject: [PATCH 5/7] fix: no need to specify /std:c++11 for MSVC --- test/cpp-tableau-loader/src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From e43d2fcfb1359291bc16b0d5c9c1026e0067bd02 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 9 May 2025 16:13:43 +0800 Subject: [PATCH 6/7] fix: do not use alias for std::filesystem --- cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc | 5 ++--- cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc | 7 +++---- test/cpp-tableau-loader/src/protoconf/load.pc.cc | 5 ++--- test/cpp-tableau-loader/src/protoconf/util.pc.cc | 7 +++---- 4 files changed, 10 insertions(+), 14 deletions(-) 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 dd2d8b36..52a44b99 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc @@ -2,7 +2,6 @@ #if __cplusplus >= 201703L #include -namespace fs = std::filesystem; #endif #include "logger.pc.h" @@ -183,7 +182,7 @@ bool LoadMessageWithPatch(google::protobuf::Message& msg, const std::string& pat std::string filename = name + util::Format2Ext(fmt); for (auto&& patch_dir : options->patch_dirs) { #if __cplusplus >= 201703L - patch_paths.emplace_back((fs::path(patch_dir) / filename).make_preferred().string()); + patch_paths.emplace_back((std::filesystem::path(patch_dir) / filename).make_preferred().string()); #else patch_paths.emplace_back(patch_dir + kPathSeperator + filename); #endif @@ -288,7 +287,7 @@ bool LoadMessage(google::protobuf::Message& msg, const std::string& dir, Format if (path.empty()) { std::string filename = name + util::Format2Ext(fmt); #if __cplusplus >= 201703L - path = (fs::path(dir) / filename).make_preferred().string(); + path = (std::filesystem::path(dir) / filename).make_preferred().string(); #else path = dir + kPathSeperator + filename; #endif 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 6386b4ec..80cad90c 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 @@ -44,7 +43,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 +71,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 +83,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 diff --git a/test/cpp-tableau-loader/src/protoconf/load.pc.cc b/test/cpp-tableau-loader/src/protoconf/load.pc.cc index 9f0bd6f8..90e3ee39 100644 --- a/test/cpp-tableau-loader/src/protoconf/load.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/load.pc.cc @@ -7,7 +7,6 @@ #if __cplusplus >= 201703L #include -namespace fs = std::filesystem; #endif #include "logger.pc.h" @@ -188,7 +187,7 @@ bool LoadMessageWithPatch(google::protobuf::Message& msg, const std::string& pat std::string filename = name + util::Format2Ext(fmt); for (auto&& patch_dir : options->patch_dirs) { #if __cplusplus >= 201703L - patch_paths.emplace_back((fs::path(patch_dir) / filename).make_preferred().string()); + patch_paths.emplace_back((std::filesystem::path(patch_dir) / filename).make_preferred().string()); #else patch_paths.emplace_back(patch_dir + kPathSeperator + filename); #endif @@ -293,7 +292,7 @@ bool LoadMessage(google::protobuf::Message& msg, const std::string& dir, Format if (path.empty()) { std::string filename = name + util::Format2Ext(fmt); #if __cplusplus >= 201703L - path = (fs::path(dir) / filename).make_preferred().string(); + path = (std::filesystem::path(dir) / filename).make_preferred().string(); #else path = dir + kPathSeperator + filename; #endif diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.cc b/test/cpp-tableau-loader/src/protoconf/util.pc.cc index 2203ab8a..b5640c5b 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 @@ -49,7 +48,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 +76,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 +88,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 From 95767f113ac555ce8db4246ee551076007dea4f2 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 9 May 2025 20:10:51 +0800 Subject: [PATCH 7/7] feat: move constexpr to .h --- cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc | 3 --- cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h | 8 +++++++- test/cpp-tableau-loader/src/protoconf/util.pc.cc | 3 --- test/cpp-tableau-loader/src/protoconf/util.pc.h | 8 +++++++- 4 files changed, 14 insertions(+), 8 deletions(-) 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 80cad90c..e6ec6c69 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc @@ -25,9 +25,6 @@ namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -const char kPathSeperator = '\\'; -#else -const char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; 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 c2cb6c07..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,8 +11,14 @@ namespace tableau { const std::string& GetErrMsg(); void SetErrMsg(const std::string& msg); +#if __cplusplus < 201703L // Platform-specific path separator -extern const char kPathSeperator; +#ifdef _WIN32 +constexpr char kPathSeperator = '\\'; +#else +constexpr char kPathSeperator = '/'; +#endif +#endif enum class Format { kUnknown, diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.cc b/test/cpp-tableau-loader/src/protoconf/util.pc.cc index b5640c5b..1e92f206 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.cc @@ -30,9 +30,6 @@ namespace tableau { #ifdef _WIN32 #define mkdir(path, mode) _mkdir(path) -const char kPathSeperator = '\\'; -#else -const char kPathSeperator = '/'; #endif static thread_local std::string g_err_msg; diff --git a/test/cpp-tableau-loader/src/protoconf/util.pc.h b/test/cpp-tableau-loader/src/protoconf/util.pc.h index ea1fb6c7..32b1b3d3 100644 --- a/test/cpp-tableau-loader/src/protoconf/util.pc.h +++ b/test/cpp-tableau-loader/src/protoconf/util.pc.h @@ -16,8 +16,14 @@ namespace tableau { const std::string& GetErrMsg(); void SetErrMsg(const std::string& msg); +#if __cplusplus < 201703L // Platform-specific path separator -extern const char kPathSeperator; +#ifdef _WIN32 +constexpr char kPathSeperator = '\\'; +#else +constexpr char kPathSeperator = '/'; +#endif +#endif enum class Format { kUnknown,