From 63ca3089dab0e2e141801e9258d63501adf14a23 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 17 Oct 2024 10:20:07 -0500 Subject: [PATCH] updated build system --- cmake/versions.cmake | 12 +-- docker/x86_64/mingw64 | 4 +- .../librepertory/src/utils/error_utils.cpp | 5 ++ scripts/copy_mingw64_deps.sh | 77 ++++++++++------- scripts/env.sh | 1 + support/include/utils/db/sqlite/db_common.hpp | 2 - support/include/utils/db/sqlite/db_delete.hpp | 11 +-- support/include/utils/db/sqlite/db_insert.hpp | 2 - support/include/utils/db/sqlite/db_select.hpp | 22 +++-- support/include/utils/db/sqlite/db_update.hpp | 22 +++-- .../include/utils/db/sqlite/db_where_t.hpp | 36 ++++---- support/include/utils/error.hpp | 18 +++- support/include/utils/windows.hpp | 4 + support/src/utils/db/sqlite/db_delete.cpp | 34 ++++---- support/src/utils/db/sqlite/db_select.cpp | 47 +++++----- support/src/utils/db/sqlite/db_update.cpp | 85 ++++++++++--------- support/src/utils/error.cpp | 21 +++++ support/src/utils/file_file.cpp | 32 ++++--- support/src/utils/windows.cpp | 33 +++++++ support/test/src/test.cpp | 17 ++-- support/test/src/utils/error_test.cpp | 9 +- support/test/src/utils/file_test.cpp | 8 +- 22 files changed, 304 insertions(+), 198 deletions(-) diff --git a/cmake/versions.cmake b/cmake/versions.cmake index fb10e730..aefb4bcb 100644 --- a/cmake/versions.cmake +++ b/cmake/versions.cmake @@ -1,15 +1,15 @@ set(BINUTILS_VERSION 2.41) -set(BOOST2_MAJOR_VERSION 1) -set(BOOST2_MINOR_VERSION 76) -set(BOOST2_PATCH_VERSION 0) set(BOOST_MAJOR_VERSION 1) set(BOOST_MINOR_VERSION 85) set(BOOST_PATCH_VERSION 0) +set(BOOST2_MAJOR_VERSION 1) +set(BOOST2_MINOR_VERSION 76) +set(BOOST2_PATCH_VERSION 0) set(CPP_HTTPLIB_VERSION 0.16.3) -set(CURL2_VERSION 8_9_1) set(CURL_VERSION 8.9.1) -set(EXPAT2_VERSION 2_6_2) +set(CURL2_VERSION 8_9_1) set(EXPAT_VERSION 2.6.2) +set(EXPAT2_VERSION 2_6_2) set(GCC_VERSION 14.2.0) set(GTEST_VERSION 1.15.2) set(ICU_VERSION 75-1) @@ -21,7 +21,7 @@ set(OPENSSL_VERSION 3.3.1) set(PKG_CONFIG_VERSION 0.29.2) set(PUGIXML_VERSION 1.14) set(SPDLOG_VERSION 1.14.1) -set(SQLITE2_VERSION 3.46.1) set(SQLITE_VERSION 3460100) +set(SQLITE2_VERSION 3.46.1) set(STDUUID_VERSION 1.2.3) set(ZLIB_VERSION 1.3.1) diff --git a/docker/x86_64/mingw64 b/docker/x86_64/mingw64 index e18b8b37..f4481acd 100644 --- a/docker/x86_64/mingw64 +++ b/docker/x86_64/mingw64 @@ -572,8 +572,8 @@ RUN if [ -f "/3rd_party/flac-${MY_FLAC_VERSION}.tar.gz" ]; then \ && cd build \ && cmake .. \ -DBUILD_DOCS=OFF \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_PROGRAMS=ON \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_PROGRAMS=OFF \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_STATIC_LIBS=ON \ -DBUILD_TESTING=OFF \ diff --git a/repertory/librepertory/src/utils/error_utils.cpp b/repertory/librepertory/src/utils/error_utils.cpp index 724f8515..2df9355d 100644 --- a/repertory/librepertory/src/utils/error_utils.cpp +++ b/repertory/librepertory/src/utils/error_utils.cpp @@ -29,6 +29,11 @@ namespace { struct repertory_exception_handler final : repertory::utils::error::i_exception_handler { + void handle_error(std::string_view function_name, + std::string_view msg) const override { + repertory::utils::error::raise_error(function_name, msg); + } + void handle_exception(std::string_view function_name) const override { repertory::utils::error::raise_error(function_name, "|exception|unknown"); } diff --git a/scripts/copy_mingw64_deps.sh b/scripts/copy_mingw64_deps.sh index 5a1b0671..6611f6da 100755 --- a/scripts/copy_mingw64_deps.sh +++ b/scripts/copy_mingw64_deps.sh @@ -18,6 +18,10 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th /mingw64/bin/zlib1.dll ) + if [ "${PROJECT_ENABLE_BACKWARD_CPP}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/msvcr90.dll) + fi + if [ "${PROJECT_ENABLE_BOOST}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libboost*.dll) fi @@ -26,10 +30,18 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcli11*.dll) fi + if [ "${PROJECT_ENABLE_CURL}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcurl*.dll) + fi + if [ "${PROJECT_ENABLE_FLAC}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libFLAC*.dll) fi + if [ "${PROJECT_ENABLE_FMT}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libfmt*.dll) + fi + if [ "${PROJECT_ENABLE_FONTCONFIG}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=( /mingw64/bin/libexpat*.dll @@ -93,14 +105,26 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libpugi*.dll) fi + if [ "${PROJECT_ENABLE_ROCKSDB}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/librocksdb*.dll) + fi + if [ "${PROJECT_ENABLE_SDL}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/SDL2*.dll) fi + if [ "${PROJECT_ENABLE_SECP256K1}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsecp256k1*.dll) + fi + if [ "${PROJECT_ENABLE_SFML}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsfml*.dll) fi + if [ "${PROJECT_ENABLE_SPDLOG}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libspdlog*.dll) + fi + if [ "${PROJECT_ENABLE_SQLITE}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsqlite3-*.dll) fi @@ -116,14 +140,32 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th ) fi + if [ "${PROJECT_ENABLE_TPL}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libtiny-process*.dll) + fi + if [ "${PROJECT_ENABLE_VORBIS}" == "ON" ]; then PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libvorbis*.dll) fi if [ "${PROJECT_ENABLE_WXWIDGETS}" == "ON" ]; then + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libLerc.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsharpyuv-*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libdeflate.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libglib-2*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libgraphite2.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libharfbuzz-*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libjbig-*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libpcre2-*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libtiff-*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libwebp-*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libwxbase*.dll) PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libwxm*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/wxbase*.dll) PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/wxm*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/libwxbase*.dll) PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/libwxm*.dll) + PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/wxbase*.dll) PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/wxm*.dll) fi @@ -132,42 +174,13 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th PROJECT_MINGW64_COPY_DEPENDENCIES+=( /mingw64/bin/libOpenCL*.dll /mingw64/bin/libopencl*.dll + /mingw64/bin/libgallium_wgl.dll /mingw64/bin/libva*.dll /mingw64/bin/opengl*.dll /mingw64/bin/vulkan*.dll ) fi - if [ "${PROJECT_IS_MINGW_UNIX}" == "1" ]; then - if [ "${PROJECT_ENABLE_BACKWARD_CPP}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/msvcr90.dll) - fi - - if [ "${PROJECT_ENABLE_FMT}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libfmt*.dll) - fi - - if [ "${PROJECT_ENABLE_CURL}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcurl*.dll) - fi - - if [ "${PROJECT_ENABLE_ROCKSDB}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/librocksdb*.dll) - fi - - if [ "${PROJECT_ENABLE_SECP256K1}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsecp256k1*.dll) - fi - - if [ "${PROJECT_ENABLE_SPDLOG}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libspdlog*.dll) - fi - - if [ "${PROJECT_ENABLE_TPL}" == "ON" ]; then - PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libtiny-process*.dll) - fi - fi - rsync -av --progress ${PROJECT_EXTERNAL_BUILD_ROOT}/bin/*.dll "${PROJECT_DIST_DIR}/" rsync -av --progress ${PROJECT_EXTERNAL_BUILD_ROOT}/lib/*.dll "${PROJECT_DIST_DIR}/" if [ "${PROJECT_ENABLE_WXWIDGETS}" == "ON" ]; then @@ -175,7 +188,7 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th fi fi -if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_ENABLE_WINFSP}" == "ON" ]; then +if [ "${PROJECT_ENABLE_WINFSP}" == "ON" ]; then if [ "${PROJECT_BUILD_ARCH}" == "x86_64" ]; then WINFSP_DLL_PART=x64 fi @@ -185,7 +198,7 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_ENABLE_WINFSP}" == "ON" ]; t fi fi -if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_ENABLE_VLC}" == "ON" ]; then +if [ "${PROJECT_ENABLE_VLC}" == "ON" ]; then rsync -av --progress ${PROJECT_3RD_PARTY_DIR}/vlc/ "${PROJECT_DIST_DIR}/vlc/" fi diff --git a/scripts/env.sh b/scripts/env.sh index b65d2e0b..9bf919cf 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -121,6 +121,7 @@ if [ "${PROJECT_ENABLE_VORBIS}" == "ON" ]; then fi if [ "${PROJECT_ENABLE_FLAC}" == "ON" ]; then + PROJECT_ENABLE_LIBICONV=ON PROJECT_ENABLE_OGG=ON PROJECT_ENABLE_VORBIS=ON fi diff --git a/support/include/utils/db/sqlite/db_common.hpp b/support/include/utils/db/sqlite/db_common.hpp index 1dd313bb..0b2dd9c2 100644 --- a/support/include/utils/db/sqlite/db_common.hpp +++ b/support/include/utils/db/sqlite/db_common.hpp @@ -183,8 +183,6 @@ template struct db_result final { } } - ~db_result() { context_->clear(); } - private: std::shared_ptr context_; mutable std::int32_t res_; diff --git a/support/include/utils/db/sqlite/db_delete.hpp b/support/include/utils/db/sqlite/db_delete.hpp index 4b92fad3..486954aa 100644 --- a/support/include/utils/db/sqlite/db_delete.hpp +++ b/support/include/utils/db/sqlite/db_delete.hpp @@ -43,12 +43,9 @@ public: : db_context_t(db3_, table_name_) {} using w_t = db_where_t; + using wd_t = where_data_t; - std::optional where; - std::map> where_actions; - std::vector where_values; - - void clear(); + std::unique_ptr where_data; }; using row = db_row; @@ -67,8 +64,8 @@ public: [[nodiscard]] auto go() const -> db_result; - [[nodiscard]] auto - group(context::w_t::group_func_t func) -> context::w_t::wn_t; + [[nodiscard]] auto group(context::w_t::group_func_t func) + -> context::w_t::wn_t; [[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t; }; diff --git a/support/include/utils/db/sqlite/db_insert.hpp b/support/include/utils/db/sqlite/db_insert.hpp index caa342fc..7453f682 100644 --- a/support/include/utils/db/sqlite/db_insert.hpp +++ b/support/include/utils/db/sqlite/db_insert.hpp @@ -34,8 +34,6 @@ public: bool or_replace{false}; std::map values; - - void clear() { values.clear(); } }; using row = db_row; diff --git a/support/include/utils/db/sqlite/db_select.hpp b/support/include/utils/db/sqlite/db_select.hpp index 9317cae6..a5ea2a19 100644 --- a/support/include/utils/db/sqlite/db_select.hpp +++ b/support/include/utils/db/sqlite/db_select.hpp @@ -44,14 +44,15 @@ public: [[nodiscard]] auto offset(std::int32_t value) -> db_select_op_t; - [[nodiscard]] auto order_by(std::string column_name, - bool ascending) -> db_select_op_t; + [[nodiscard]] auto order_by(std::string column_name, bool ascending) + -> db_select_op_t; }; context(sqlite3 *db3_, std::string table_name_) : db_context_t(db3_, table_name_) {} using w_t = db_where_t; + using wd_t = where_data_t; std::vector columns; std::map count_columns; @@ -60,11 +61,8 @@ public: std::optional limit; std::optional offset; std::optional> order_by; - std::optional where; - std::map> where_actions; - std::vector where_values; - void clear(); + std::unique_ptr where_data; }; using row = db_row; @@ -81,8 +79,8 @@ private: public: [[nodiscard]] auto column(std::string column_name) -> db_select &; - [[nodiscard]] auto count(std::string column_name, - std::string as_column_name) -> db_select &; + [[nodiscard]] auto count(std::string column_name, std::string as_column_name) + -> db_select &; [[nodiscard]] auto dump() const -> std::string; @@ -90,15 +88,15 @@ public: [[nodiscard]] auto group_by(std::string column_name) -> db_select &; - [[nodiscard]] auto - group(context::w_t::group_func_t func) -> context::w_t::wn_t; + [[nodiscard]] auto group(context::w_t::group_func_t func) + -> context::w_t::wn_t; [[nodiscard]] auto limit(std::int32_t value) -> db_select &; [[nodiscard]] auto offset(std::int32_t value) -> db_select &; - [[nodiscard]] auto order_by(std::string column_name, - bool ascending) -> db_select &; + [[nodiscard]] auto order_by(std::string column_name, bool ascending) + -> db_select &; [[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t; }; diff --git a/support/include/utils/db/sqlite/db_update.hpp b/support/include/utils/db/sqlite/db_update.hpp index acdc9fa0..407554cf 100644 --- a/support/include/utils/db/sqlite/db_update.hpp +++ b/support/include/utils/db/sqlite/db_update.hpp @@ -43,20 +43,18 @@ public: [[nodiscard]] auto limit(std::int32_t value) -> db_update_op_t; - [[nodiscard]] auto order_by(std::string column_name, - bool ascending) -> db_update_op_t; + [[nodiscard]] auto order_by(std::string column_name, bool ascending) + -> db_update_op_t; }; using w_t = db_where_t; + using wd_t = where_data_t; std::map column_values; std::optional limit; std::optional> order_by; - std::optional where; - std::map> where_actions; - std::vector where_values; - void clear(); + std::unique_ptr where_data; }; using row = db_row; @@ -71,20 +69,20 @@ private: std::shared_ptr context_; public: - [[nodiscard]] auto column_value(std::string column_name, - db_types_t value) -> db_update &; + [[nodiscard]] auto column_value(std::string column_name, db_types_t value) + -> db_update &; [[nodiscard]] auto dump() const -> std::string; [[nodiscard]] auto go() const -> db_result; - [[nodiscard]] auto - group(context::w_t::group_func_t func) -> context::w_t::wn_t; + [[nodiscard]] auto group(context::w_t::group_func_t func) + -> context::w_t::wn_t; [[nodiscard]] auto limit(std::int32_t value) -> db_update &; - [[nodiscard]] auto order_by(std::string column_name, - bool ascending) -> db_update &; + [[nodiscard]] auto order_by(std::string column_name, bool ascending) + -> db_update &; [[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t; }; diff --git a/support/include/utils/db/sqlite/db_where_t.hpp b/support/include/utils/db/sqlite/db_where_t.hpp index ee9468d3..40ea6119 100644 --- a/support/include/utils/db/sqlite/db_where_t.hpp +++ b/support/include/utils/db/sqlite/db_where_t.hpp @@ -26,6 +26,12 @@ #include "utils/db/sqlite/db_common.hpp" namespace repertory::utils::db::sqlite { +template struct where_data_t final { + w_t base; + std::map> actions; + std::vector values; +}; + template struct db_next_t final { @@ -42,7 +48,7 @@ struct db_next_t final { [[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); } [[nodiscard]] auto dump(std::int32_t &idx) const -> std::string { - return ctx->where->dump(idx); + return ctx->where_data->base.dump(idx); } [[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); } @@ -72,14 +78,14 @@ struct db_where_next_t final { "AND", }; - ctx->where_actions[action_idx].emplace_back(next); + ctx->where_data->actions[action_idx].emplace_back(next); return next; } [[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); } [[nodiscard]] auto dump(std::int32_t &idx) const -> std::string { - return ctx->where->dump(idx); + return ctx->where_data->base.dump(idx); } [[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); } @@ -97,7 +103,7 @@ struct db_where_next_t final { "OR", }; - ctx->where_actions[action_idx].emplace_back(next); + ctx->where_data->actions[action_idx].emplace_back(next); return next; } }; @@ -111,12 +117,12 @@ struct db_comp_next_t final { using wn_t = db_where_next_t; [[nodiscard]] auto create(std::string operation, db_types_t value) { - ctx->where_actions[action_idx].emplace_back(db_comp_data_t{ + ctx->where_data->actions[action_idx].emplace_back(db_comp_data_t{ column_name, operation, }); - ctx->where_values.push_back(value); + ctx->where_data->values.push_back(value); return wn_t{ action_idx, @@ -151,8 +157,8 @@ template struct db_where_t final { using action_t = std::variant; - [[nodiscard]] static auto dump(std::int32_t &idx, - auto &&actions) -> std::string { + [[nodiscard]] static auto dump(std::int32_t &idx, auto &&actions) + -> std::string { std::stringstream stream; for (auto &&action : actions) { @@ -177,24 +183,24 @@ template struct db_where_t final { [[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); } [[nodiscard]] auto dump(std::int32_t &idx) const -> std::string { - return dump(idx, ctx->where_actions[action_idx]); + return dump(idx, ctx->where_data->actions[action_idx]); } [[nodiscard]] auto get_actions() -> auto & { - return ctx->where_actions[action_idx]; + return ctx->where_data->actions[action_idx]; } [[nodiscard]] auto get_actions() const -> const auto & { - return ctx->where_actions[action_idx]; + return ctx->where_data->actions[action_idx]; } [[nodiscard]] auto group(group_func_t func) -> wn_t { - ctx->where_actions[action_idx]; + ctx->where_data->actions[action_idx]; - db_where_t where{ctx->where_actions.size(), ctx}; + db_where_t where{ctx->where_data->actions.size(), ctx}; func(where); - ctx->where_actions[action_idx].emplace_back(where); + ctx->where_data->actions[action_idx].emplace_back(where); return wn_t{ action_idx, @@ -203,7 +209,7 @@ template struct db_where_t final { } [[nodiscard]] auto where(std::string column_name) -> cn_t { - ctx->where_actions[action_idx]; + ctx->where_data->actions[action_idx]; return cn_t{ action_idx, diff --git a/support/include/utils/error.hpp b/support/include/utils/error.hpp index bf3e9778..9d809b43 100644 --- a/support/include/utils/error.hpp +++ b/support/include/utils/error.hpp @@ -33,6 +33,9 @@ struct i_exception_handler { auto operator=(const i_exception_handler &) noexcept = delete; auto operator=(i_exception_handler &&) noexcept = delete; + virtual void handle_error(std::string_view function_name, + std::string_view msg) const = 0; + virtual void handle_exception(std::string_view function_name) const = 0; virtual void handle_exception(std::string_view function_name, @@ -43,6 +46,11 @@ protected: }; struct iostream_exception_handler final : i_exception_handler { + void handle_error(std::string_view function_name, + std::string_view msg) const override { + std::cerr << function_name << '|' << msg; + } + void handle_exception(std::string_view function_name) const override { std::cerr << function_name << "|exception|unknown" << std::endl; } @@ -58,12 +66,18 @@ inline const iostream_exception_handler default_exception_handler{}; extern std::atomic exception_handler; #if defined(PROJECT_ENABLE_TESTING) -[[nodiscard]] inline auto -get_exception_handler() -> const i_exception_handler * { +[[nodiscard]] inline auto get_exception_handler() + -> const i_exception_handler * { return exception_handler; } #endif // defined(PROJECT_ENABLE_TESTING) +[[nodiscard]] auto create_error_message(std::string_view function_name, + std::vector items) + -> std::string; + +void handle_error(std::string_view function_name, std::string_view msg); + void handle_exception(std::string_view function_name); void handle_exception(std::string_view function_name, const std::exception &ex); diff --git a/support/include/utils/windows.hpp b/support/include/utils/windows.hpp index a46cf45d..5050e14d 100644 --- a/support/include/utils/windows.hpp +++ b/support/include/utils/windows.hpp @@ -26,6 +26,10 @@ #include "utils/config.hpp" namespace repertory::utils { +void create_console(); + +void free_console(); + [[nodiscard]] auto get_local_app_data_directory() -> const std::string &; [[nodiscard]] auto get_last_error_code() -> DWORD; diff --git a/support/src/utils/db/sqlite/db_delete.cpp b/support/src/utils/db/sqlite/db_delete.cpp index c59a589f..bed2c3c3 100644 --- a/support/src/utils/db/sqlite/db_delete.cpp +++ b/support/src/utils/db/sqlite/db_delete.cpp @@ -24,11 +24,6 @@ #if defined(PROJECT_ENABLE_SQLITE) namespace repertory::utils::db::sqlite { -void db_delete::context::clear() { - where.reset(); - where_values.clear(); -} - auto db_delete::context::db_delete_op_t::dump() const -> std::string { return db_delete{ctx}.dump(); } @@ -41,9 +36,9 @@ auto db_delete::dump() const -> std::string { std::stringstream query; query << "DELETE FROM \"" << context_->table_name << "\""; - if (context_->where.has_value()) { + if (context_->where_data) { std::int32_t idx{}; - query << " WHERE " << context_->where->dump(idx); + query << " WHERE " << context_->where_data->base.dump(idx); } query << ';'; @@ -65,8 +60,13 @@ auto db_delete::go() const -> db_result { return {context_, res}; } + if (not context_->where_data) { + return {context_, res}; + } + for (std::int32_t idx = 0; - idx < static_cast(context_->where_values.size()); idx++) { + idx < static_cast(context_->where_data->values.size()); + idx++) { res = std::visit( overloaded{ [this, &idx](std::int64_t data) -> std::int32_t { @@ -77,7 +77,7 @@ auto db_delete::go() const -> db_result { data.c_str(), -1, nullptr); }, }, - context_->where_values.at(static_cast(idx))); + context_->where_data->values.at(static_cast(idx))); if (res != SQLITE_OK) { return {context_, res}; } @@ -87,19 +87,23 @@ auto db_delete::go() const -> db_result { } auto db_delete::group(context::w_t::group_func_t func) -> context::w_t::wn_t { - if (not context_->where.has_value()) { - context_->where = context::w_t{0U, context_}; + if (not context_->where_data) { + context_->where_data = std::make_unique(context::wd_t{ + context::w_t{0U, context_}, + }); } - return context_->where->group(std::move(func)); + return context_->where_data->base.group(std::move(func)); } auto db_delete::where(std::string column_name) const -> context::w_t::cn_t { - if (not context_->where.has_value()) { - context_->where = context::w_t{0U, context_}; + if (not context_->where_data) { + context_->where_data = std::make_unique(context::wd_t{ + context::w_t{0U, context_}, + }); } - return context_->where->where(column_name); + return context_->where_data->base.where(column_name); } } // namespace repertory::utils::db::sqlite diff --git a/support/src/utils/db/sqlite/db_select.cpp b/support/src/utils/db/sqlite/db_select.cpp index 7032f93b..f9a72ddb 100644 --- a/support/src/utils/db/sqlite/db_select.cpp +++ b/support/src/utils/db/sqlite/db_select.cpp @@ -24,16 +24,6 @@ #if defined(PROJECT_ENABLE_SQLITE) namespace repertory::utils::db::sqlite { -void db_select::context::clear() { - columns.clear(); - count_columns.clear(); - limit.reset(); - offset.reset(); - order_by.reset(); - where.reset(); - where_values.clear(); -} - auto db_select::context::db_select_op_t::dump() const -> std::string { return db_select{ctx}.dump(); } @@ -72,8 +62,8 @@ auto db_select::column(std::string column_name) -> db_select & { return *this; } -auto db_select::count(std::string column_name, - std::string as_column_name) -> db_select & { +auto db_select::count(std::string column_name, std::string as_column_name) + -> db_select & { context_->count_columns[column_name] = as_column_name; return *this; } @@ -108,9 +98,9 @@ auto db_select::dump() const -> std::string { } query << " FROM \"" << context_->table_name << "\""; - if (context_->where.has_value()) { + if (context_->where_data) { std::int32_t idx{}; - query << " WHERE " << context_->where->dump(idx); + query << " WHERE " << context_->where_data->base.dump(idx); } if (not context_->group_by.empty()) { @@ -156,8 +146,13 @@ auto db_select::go() const -> db_result { return {context_, res}; } + if (not context_->where_data) { + return {context_, res}; + } + for (std::int32_t idx = 0; - idx < static_cast(context_->where_values.size()); idx++) { + idx < static_cast(context_->where_data->values.size()); + idx++) { res = std::visit( overloaded{ [this, &idx](std::int64_t data) -> std::int32_t { @@ -168,7 +163,7 @@ auto db_select::go() const -> db_result { data.c_str(), -1, nullptr); }, }, - context_->where_values.at(static_cast(idx))); + context_->where_data->values.at(static_cast(idx))); if (res != SQLITE_OK) { return {context_, res}; } @@ -178,11 +173,13 @@ auto db_select::go() const -> db_result { } auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t { - if (not context_->where.has_value()) { - context_->where = context::w_t{0U, context_}; + if (not context_->where_data) { + context_->where_data = std::make_unique(context::wd_t{ + context::w_t{0U, context_}, + }); } - return context_->where->group(std::move(func)); + return context_->where_data->base.group(std::move(func)); } auto db_select::group_by(std::string column_name) -> db_select & { @@ -200,18 +197,20 @@ auto db_select::offset(std::int32_t value) -> db_select & { return *this; } -auto db_select::order_by(std::string column_name, - bool ascending) -> db_select & { +auto db_select::order_by(std::string column_name, bool ascending) + -> db_select & { context_->order_by = {column_name, ascending}; return *this; } auto db_select::where(std::string column_name) const -> context::w_t::cn_t { - if (not context_->where.has_value()) { - context_->where = context::w_t{0U, context_}; + if (not context_->where_data) { + context_->where_data = std::make_unique(context::wd_t{ + context::w_t{0U, context_}, + }); } - return context_->where->where(column_name); + return context_->where_data->base.where(column_name); } } // namespace repertory::utils::db::sqlite diff --git a/support/src/utils/db/sqlite/db_update.cpp b/support/src/utils/db/sqlite/db_update.cpp index 445683f7..d4ccc369 100644 --- a/support/src/utils/db/sqlite/db_update.cpp +++ b/support/src/utils/db/sqlite/db_update.cpp @@ -24,14 +24,6 @@ #if defined(PROJECT_ENABLE_SQLITE) namespace repertory::utils::db::sqlite { -void db_update::context::clear() { - column_values.clear(); - limit.reset(); - order_by.reset(); - where.reset(); - where_values.clear(); -} - auto db_update::context::db_update_op_t::dump() const -> std::string { return db_update{ctx}.dump(); } @@ -53,8 +45,8 @@ auto db_update::context::db_update_op_t::order_by(std::string column_name, return *this; } -auto db_update::column_value(std::string column_name, - db_types_t value) -> db_update & { +auto db_update::column_value(std::string column_name, db_types_t value) + -> db_update & { context_->column_values[column_name] = value; return *this; } @@ -73,9 +65,9 @@ auto db_update::dump() const -> std::string { query << '"' << column->first << "\"=?" + std::to_string(idx + 1); } - if (context_->where.has_value()) { + if (context_->where_data) { auto idx{static_cast(context_->column_values.size())}; - query << " WHERE " << context_->where->dump(idx); + query << " WHERE " << context_->where_data->base.dump(idx); } if (context_->order_by.has_value()) { @@ -124,29 +116,34 @@ auto db_update::go() const -> db_result { } } + if (not context_->where_data) { + return {context_, res}; + } + for (std::int32_t idx = 0; - idx < static_cast(context_->where_values.size()); idx++) { - res = std::visit(overloaded{ - [this, &idx](std::int64_t data) -> std::int32_t { - return sqlite3_bind_int64( - context_->stmt.get(), - idx + - static_cast( - context_->column_values.size()) + - 1, - data); - }, - [this, &idx](const std::string &data) -> std::int32_t { - return sqlite3_bind_text( - context_->stmt.get(), - idx + - static_cast( - context_->column_values.size()) + - 1, - data.c_str(), -1, nullptr); - }, - }, - context_->where_values.at(static_cast(idx))); + idx < static_cast(context_->where_data->values.size()); + idx++) { + res = std::visit( + overloaded{ + [this, &idx](std::int64_t data) -> std::int32_t { + return sqlite3_bind_int64( + context_->stmt.get(), + idx + + static_cast( + context_->column_values.size()) + + 1, + data); + }, + [this, &idx](const std::string &data) -> std::int32_t { + return sqlite3_bind_text(context_->stmt.get(), + idx + + static_cast( + context_->column_values.size()) + + 1, + data.c_str(), -1, nullptr); + }, + }, + context_->where_data->values.at(static_cast(idx))); if (res != SQLITE_OK) { return {context_, res}; } @@ -156,11 +153,13 @@ auto db_update::go() const -> db_result { } auto db_update::group(context::w_t::group_func_t func) -> context::w_t::wn_t { - if (not context_->where.has_value()) { - context_->where = context::w_t{0U, context_}; + if (not context_->where_data) { + context_->where_data = std::make_unique(context::wd_t{ + context::w_t{0U, context_}, + }); } - return context_->where->group(std::move(func)); + return context_->where_data->base.group(std::move(func)); } auto db_update::limit(std::int32_t value) -> db_update & { @@ -168,18 +167,20 @@ auto db_update::limit(std::int32_t value) -> db_update & { return *this; } -auto db_update::order_by(std::string column_name, - bool ascending) -> db_update & { +auto db_update::order_by(std::string column_name, bool ascending) + -> db_update & { context_->order_by = {column_name, ascending}; return *this; } auto db_update::where(std::string column_name) const -> context::w_t::cn_t { - if (not context_->where.has_value()) { - context_->where = context::w_t{0U, context_}; + if (not context_->where_data) { + context_->where_data = std::make_unique(context::wd_t{ + context::w_t{0U, context_}, + }); } - return context_->where->where(column_name); + return context_->where_data->base.where(column_name); } } // namespace repertory::utils::db::sqlite diff --git a/support/src/utils/error.cpp b/support/src/utils/error.cpp index 095e8945..4392dd07 100644 --- a/support/src/utils/error.cpp +++ b/support/src/utils/error.cpp @@ -25,6 +25,27 @@ namespace repertory::utils::error { std::atomic exception_handler{ &default_exception_handler}; +auto create_error_message(std::string_view function_name, + std::vector items) -> std::string { + std::stringstream stream{}; + stream << function_name; + for (auto &&item : items) { + stream << '|' << item; + } + + return stream.str(); +} + +void handle_error(std::string_view function_name, std::string_view msg) { + const i_exception_handler *handler{exception_handler}; + if (handler != nullptr) { + handler->handle_error(function_name, msg); + return; + } + + default_exception_handler.handle_error(function_name, msg); +} + void handle_exception(std::string_view function_name) { const i_exception_handler *handler{exception_handler}; if (handler != nullptr) { diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index 44a6595c..514c6d90 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -33,7 +33,7 @@ namespace { file_size = 0U; #if defined(_WIN32) - struct _stat64 st {}; + struct _stat64 st{}; auto res = _stat64(std::string{path}.c_str(), &st); if (res != 0) { return false; @@ -52,10 +52,10 @@ namespace { auto abs_path = repertory::utils::path::absolute(path); #if defined(_WIN32) - return (::PathFileExistsA(abs_path.c_str()) && - not ::PathIsDirectoryA(abs_path.c_str())); + return ((::PathFileExistsA(abs_path.c_str()) != 0) && + (::PathIsDirectoryA(abs_path.c_str()) == 0)); #else // !defined(_WIN32) - struct stat64 st {}; + struct stat64 st{}; return (stat64(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode)); #endif // defined(_WIN32) } @@ -119,11 +119,15 @@ void file::open() { } #if defined(_WIN32) - file_ = file_t(_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO), - file_deleter()); + file_ = file_t{ + _fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO), + file_deleter(), + }; #else // !defined(_WIN32) - file_ = - file_t(fopen(path_.c_str(), read_only_ ? "rb" : "rb+"), file_deleter()); + file_ = file_t{ + fopen(path_.c_str(), read_only_ ? "rb" : "rb+"), + file_deleter(), + }; #endif // defined(_WIN32) } @@ -150,8 +154,8 @@ auto file::open_file(std::string_view path, bool read_only) -> fs_file_t { return new_file; } -auto file::open_or_create_file(std::string_view path, - bool read_only) -> fs_file_t { +auto file::open_or_create_file(std::string_view path, bool read_only) + -> fs_file_t { auto abs_path = utils::path::absolute(path); if (not is_file(abs_path)) { #if defined(_WIN32) @@ -196,7 +200,7 @@ auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool { #if defined(_WIN32) return ::CopyFileA(path_.c_str(), to_path.c_str(), - overwrite ? TRUE : FALSE); + overwrite ? TRUE : FALSE) != 0; #else // !defined(_WIN32) return std::filesystem::copy_file( path_, to_path, @@ -264,8 +268,8 @@ auto file::move_to(std::string_view path) -> bool { auto success{false}; #if defined(_WIN32) - success = !!::MoveFileExA(path_.c_str(), abs_path.c_str(), - MOVEFILE_REPLACE_EXISTING); + success = ::MoveFileExA(path_.c_str(), abs_path.c_str(), + MOVEFILE_REPLACE_EXISTING) != 0; #else // !// defined(_WIN32) std::error_code ec{}; std::filesystem::rename(path_, abs_path, ec); @@ -415,7 +419,7 @@ auto file::remove() -> bool { return utils::retry_action([this]() -> bool { #if defined(_WIN32) - return ::DeleteFileA(path_.c_str()); + return ::DeleteFileA(path_.c_str()) != 0; #else // !defined(_WIN32) std::error_code ec{}; return std::filesystem::remove(path_, ec); diff --git a/support/src/utils/windows.cpp b/support/src/utils/windows.cpp index eb01fd02..8c02d65b 100644 --- a/support/src/utils/windows.cpp +++ b/support/src/utils/windows.cpp @@ -26,6 +26,39 @@ #include "utils/string.hpp" namespace repertory::utils { +void create_console() { + if (AllocConsole() == 0) { + return; + } + + FILE *dummy{nullptr}; + freopen_s(&dummy, "CONOUT$", "w", stdout); + freopen_s(&dummy, "CONOUT$", "w", stderr); + freopen_s(&dummy, "CONIN$", "r", stdin); + std::cout.clear(); + std::clog.clear(); + std::cerr.clear(); + std::cin.clear(); + + auto *out_w = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + auto *in_w = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + SetStdHandle(STD_OUTPUT_HANDLE, out_w); + SetStdHandle(STD_ERROR_HANDLE, out_w); + SetStdHandle(STD_INPUT_HANDLE, in_w); + std::wcout.clear(); + std::wclog.clear(); + std::wcerr.clear(); + std::wcin.clear(); +} + +void free_console() { + FreeConsole(); +} + auto get_last_error_code() -> DWORD { return ::GetLastError(); } auto get_local_app_data_directory() -> const std::string & { diff --git a/support/test/src/test.cpp b/support/test/src/test.cpp index d5a1e9e0..735b3143 100644 --- a/support/test/src/test.cpp +++ b/support/test/src/test.cpp @@ -29,19 +29,16 @@ static std::vector> static void delete_generated_files() { repertory::recur_mutex_lock lock{file_mtx}; - std::optional parent_path; + std::map parent_paths; for (auto &&path : generated_files) { - if (parent_path->empty()) { - parent_path = repertory::utils::path::get_parent_path(path->get_path()); - } - - [[maybe_unused]] auto removed = path->remove(); + parent_paths[repertory::utils::path::get_parent_path(path->get_path())] = + true; } generated_files.clear(); - if (parent_path.has_value()) { + for (auto &&entry : parent_paths) { EXPECT_TRUE( - repertory::utils::file::directory(*parent_path).remove_recursively()); + repertory::utils::file::directory(entry.first).remove_recursively()); } } @@ -49,7 +46,9 @@ struct file_deleter final { ~file_deleter() { delete_generated_files(); } }; -static auto deleter{std::make_unique()}; +static auto deleter{ + std::make_unique(), +}; } // namespace namespace repertory::test { diff --git a/support/test/src/utils/error_test.cpp b/support/test/src/utils/error_test.cpp index ccb710cb..1ca56d25 100644 --- a/support/test/src/utils/error_test.cpp +++ b/support/test/src/utils/error_test.cpp @@ -37,7 +37,11 @@ TEST(utils_error, check_default_exception_handler) { } TEST(utils_error, can_override_exception_handler) { - struct my_exc_handler : public utils::error::i_exception_handler { + struct my_exc_handler final : public utils::error::i_exception_handler { + MOCK_METHOD(void, handle_error, + (std::string_view function_name, std::string_view msg), + (const, override)); + MOCK_METHOD(void, handle_exception, (std::string_view function_name), (const, override)); @@ -49,6 +53,9 @@ TEST(utils_error, can_override_exception_handler) { my_exc_handler handler{}; utils::error::set_exception_handler(&handler); + EXPECT_CALL(handler, handle_error("test_func", "error")).WillOnce(Return()); + utils::error::handle_error("test_func", "error"); + EXPECT_CALL(handler, handle_exception("test_func")).WillOnce(Return()); utils::error::handle_exception("test_func"); diff --git a/support/test/src/utils/file_test.cpp b/support/test/src/utils/file_test.cpp index 1db2f1fd..a24847b0 100644 --- a/support/test/src/utils/file_test.cpp +++ b/support/test/src/utils/file_test.cpp @@ -26,7 +26,7 @@ static constexpr const auto file_type_count{1U}; } namespace repertory { -TEST(utils_file, can_create_file) { +TEST(utils_file, can_create_and_remove_file) { for (auto idx = 0U; idx < file_type_count; ++idx) { auto path = test::generate_test_file_name("utils_file"); EXPECT_FALSE(utils::file::file(path).exists() || @@ -37,6 +37,12 @@ TEST(utils_file, can_create_file) { EXPECT_TRUE(*file); EXPECT_TRUE(utils::file::file(path).exists()); + EXPECT_TRUE(file->exists()); + + EXPECT_TRUE(file->remove()); + + EXPECT_FALSE(utils::file::file(path).exists()); + EXPECT_FALSE(file->exists()); } }