From 99e12cec300961dfb58585a855645512c02a3bd5 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 19 Feb 2025 16:11:57 -0600 Subject: [PATCH] updated build system --- CMakeLists.txt | 5 -- cmake/versions.cmake | 12 +-- scripts/env.sh | 3 - support/include/utils/error.hpp | 121 +++++--------------------- support/src/utils/error.cpp | 53 +---------- support/src/utils/file.cpp | 12 +-- support/test/src/utils/error_test.cpp | 36 -------- 7 files changed, 30 insertions(+), 212 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a03a842..ec98d7be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,10 +58,6 @@ if(PROJECT_IS_MINGW) endif() endif() -if (PROJECT_ENABLE_V2_ERRORS) - add_definitions(-DPROJECT_ENABLE_V2_ERRORS) -endif() - include(cmake/settings.cmake) include(cmake/flags.cmake) @@ -147,7 +143,6 @@ endif() -DPROJECT_COPYRIGHT=${PROJECT_COPYRIGHT} -DPROJECT_DESC=${PROJECT_DESC} -DPROJECT_DIST_DIR=${PROJECT_DIST_DIR} - -DPROJECT_ENABLE_V2_ERRORS=${PROJECT_ENABLE_V2_ERRORS} -DPROJECT_ENABLE_WIN32_LONG_PATH_NAMES=${PROJECT_ENABLE_WIN32_LONG_PATH_NAMES} -DPROJECT_ENABLE_BOOST=${PROJECT_ENABLE_BOOST} -DPROJECT_ENABLE_CPP_HTTPLIB=${PROJECT_ENABLE_CPP_HTTPLIB} diff --git a/cmake/versions.cmake b/cmake/versions.cmake index 4eddf7f5..2a121d97 100644 --- a/cmake/versions.cmake +++ b/cmake/versions.cmake @@ -1,15 +1,15 @@ set(BINUTILS_VERSION 2.43) -set(BOOST_MAJOR_VERSION 1) -set(BOOST_MINOR_VERSION 87) -set(BOOST_PATCH_VERSION 0) set(BOOST2_MAJOR_VERSION 1) set(BOOST2_MINOR_VERSION 76) set(BOOST2_PATCH_VERSION 0) +set(BOOST_MAJOR_VERSION 1) +set(BOOST_MINOR_VERSION 87) +set(BOOST_PATCH_VERSION 0) set(CPP_HTTPLIB_VERSION 0.18.1) -set(CURL_VERSION 8.11.0) set(CURL2_VERSION 8_11_0) -set(EXPAT_VERSION 2.6.4) +set(CURL_VERSION 8.11.0) set(EXPAT2_VERSION 2_6_4) +set(EXPAT_VERSION 2.6.4) set(GCC_VERSION 14.2.0) set(GTEST_VERSION 1.15.2) set(ICU_VERSION 76-1) @@ -22,7 +22,7 @@ set(PKG_CONFIG_VERSION 0.29.2) set(PUGIXML_VERSION 1.14) set(ROCKSDB_VERSION 9.7.4) set(SPDLOG_VERSION 1.15.0) -set(SQLITE_VERSION 3460100) set(SQLITE2_VERSION 3.46.1) +set(SQLITE_VERSION 3460100) set(STDUUID_VERSION 1.2.3) set(ZLIB_VERSION 1.3.1) diff --git a/scripts/env.sh b/scripts/env.sh index cd0c8df3..d43bc1cd 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -42,7 +42,6 @@ done PROJECT_APP_LIST=() PROJECT_CMAKE_OPTS="" PROJECT_ENABLE_WIN32_LONG_PATH_NAMES=OFF -PROJECT_ENABLE_V2_ERRORS=OFF PROJECT_IS_ALPINE=0 PROJECT_IS_ARM64=0 PROJECT_MINGW64_COPY_DEPENDENCIES=() @@ -235,7 +234,6 @@ PROJECT_CMAKE_OPTS="-DPROJECT_BUILD_DIR=${PROJECT_BUILD_DIR} ${PROJECT_CMAKE_OPT PROJECT_CMAKE_OPTS="-DPROJECT_BUILD_SHARED_LIBS=${PROJECT_BUILD_SHARED_LIBS} ${PROJECT_CMAKE_OPTS}" PROJECT_CMAKE_OPTS="-DPROJECT_CMAKE_BUILD_TYPE=${PROJECT_CMAKE_BUILD_TYPE} ${PROJECT_CMAKE_OPTS}" PROJECT_CMAKE_OPTS="-DPROJECT_DIST_DIR=${PROJECT_DIST_DIR} ${PROJECT_CMAKE_OPTS}" -PROJECT_CMAKE_OPTS="-DPROJECT_ENABLE_V2_ERRORS=${PROJECT_ENABLE_V2_ERRORS} ${PROJECT_CMAKE_OPTS}" PROJECT_CMAKE_OPTS="-DPROJECT_ENABLE_WIN32_LONG_PATH_NAMES=${PROJECT_ENABLE_WIN32_LONG_PATH_NAMES} ${PROJECT_CMAKE_OPTS}" PROJECT_CMAKE_OPTS="-DPROJECT_EXTERNAL_BUILD_ROOT=${PROJECT_EXTERNAL_BUILD_ROOT} ${PROJECT_CMAKE_OPTS}" PROJECT_CMAKE_OPTS="-DPROJECT_GIT_REV=${PROJECT_GIT_REV} ${PROJECT_CMAKE_OPTS}" @@ -307,7 +305,6 @@ export PROJECT_COPYRIGHT export PROJECT_DESC export PROJECT_DIST_DIR export PROJECT_ENABLE_WIN32_LONG_PATH_NAMES -export PROJECT_ENABLE_V2_ERRORS export PROJECT_FILE_PART export PROJECT_GIT_REV export PROJECT_IS_ALPINE diff --git a/support/include/utils/error.hpp b/support/include/utils/error.hpp index 9ae183cb..83e153d1 100644 --- a/support/include/utils/error.hpp +++ b/support/include/utils/error.hpp @@ -25,16 +25,12 @@ #include "utils/config.hpp" namespace repertory::utils::error { -[[nodiscard]] auto create_error_message(std::vector items) - -> std::string; +[[nodiscard]] auto +create_error_message(std::vector items) -> std::string; -[[nodiscard]] auto create_error_message(std::string_view function_name, - std::vector items) - -> std::string; - -[[nodiscard]] auto create_exception(std::string_view function_name, - std::vector items) - -> std::runtime_error; +[[nodiscard]] auto +create_exception(std::string_view function_name, + std::vector items) -> std::runtime_error; struct i_exception_handler { virtual ~i_exception_handler() {} @@ -44,11 +40,6 @@ struct i_exception_handler { auto operator=(const i_exception_handler &) noexcept = delete; auto operator=(i_exception_handler &&) noexcept = delete; -#if defined(PROJECT_ENABLE_V2_ERRORS) - virtual void handle_debug(std::string_view function_name, - std::string_view msg) const = 0; -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - virtual void handle_error(std::string_view function_name, std::string_view msg) const = 0; @@ -57,128 +48,56 @@ struct i_exception_handler { virtual void handle_exception(std::string_view function_name, const std::exception &ex) const = 0; -#if defined(PROJECT_ENABLE_V2_ERRORS) - virtual void handle_info(std::string_view function_name, - std::string_view msg) const = 0; - - virtual void handle_trace(std::string_view function_name, - std::string_view msg) const = 0; - - virtual void handle_warn(std::string_view function_name, - std::string_view msg) const = 0; -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - protected: i_exception_handler() = default; }; struct iostream_exception_handler final : i_exception_handler { -#if defined(PROJECT_ENABLE_V2_ERRORS) - void handle_debug(std::string_view function_name, - std::string_view msg) const override { - std::cout << create_error_message(function_name, - { - "debug", - msg, - }) - << std::endl; - } -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - void handle_error(std::string_view function_name, std::string_view msg) const override { - std::cerr << create_error_message(function_name, - { - "error", - msg, - }) + std::cerr << create_error_message({ + function_name, + msg, + }) << std::endl; } void handle_exception(std::string_view function_name) const override { - std::cerr << create_error_message(function_name, - { - "error", - "exception", - "unknown", - }) + std::cerr << create_error_message({ + function_name, + "exception", + "unknown", + }) << std::endl; } void handle_exception(std::string_view function_name, const std::exception &ex) const override { - std::cerr << create_error_message( + std::cerr << create_error_message({ function_name, - { - "error", - "exception", - (ex.what() == nullptr ? "unknown" : ex.what()), - }) + "exception", + (ex.what() == nullptr ? "unknown" : ex.what()), + }) << std::endl; } - -#if defined(PROJECT_ENABLE_V2_ERRORS) - void handle_info(std::string_view function_name, - std::string_view msg) const override { - std::cout << create_error_message(function_name, - { - "info", - msg, - }) - << std::endl; - } - - void handle_trace(std::string_view function_name, - std::string_view msg) const override { - std::cout << create_error_message(function_name, - { - "trace", - msg, - }) - << std::endl; - } - - void handle_warn(std::string_view function_name, - std::string_view msg) const override { - std::cout << create_error_message(function_name, - { - "warn", - msg, - }) - << std::endl; - } -#endif // defined(PROJECT_ENABLE_V2_ERRORS) }; - 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) -#if defined(PROJECT_ENABLE_V2_ERRORS) -void handle_debug(std::string_view function_name, std::string_view msg); -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - 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); -#if defined(PROJECT_ENABLE_V2_ERRORS) -void handle_info(std::string_view function_name, std::string_view msg); - -void handle_trace(std::string_view function_name, std::string_view msg); - -void handle_warn(std::string_view function_name, std::string_view msg); -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - void set_exception_handler(const i_exception_handler *handler); } // namespace repertory::utils::error diff --git a/support/src/utils/error.cpp b/support/src/utils/error.cpp index b880c55a..73d573e2 100644 --- a/support/src/utils/error.cpp +++ b/support/src/utils/error.cpp @@ -38,30 +38,13 @@ auto create_error_message(std::vector items) -> std::string { return stream.str(); } -auto create_error_message(std::string_view function_name, - std::vector items) -> std::string { - items.insert(items.begin(), function_name); - return create_error_message(items); -} - auto create_exception(std::string_view function_name, std::vector items) -> std::runtime_error { - return std::runtime_error(create_error_message(function_name, items)); + items.insert(items.begin(), function_name); + return std::runtime_error(create_error_message(items)); } -#if defined(PROJECT_ENABLE_V2_ERRORS) -void handle_debug(std::string_view function_name, std::string_view msg) { - const i_exception_handler *handler{exception_handler}; - if (handler != nullptr) { - handler->handle_debug(function_name, msg); - return; - } - - default_exception_handler.handle_debug(function_name, msg); -} -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - void handle_error(std::string_view function_name, std::string_view msg) { const i_exception_handler *handler{exception_handler}; if (handler != nullptr) { @@ -93,38 +76,6 @@ void handle_exception(std::string_view function_name, default_exception_handler.handle_exception(function_name, ex); } -#if defined(PROJECT_ENABLE_V2_ERRORS) -void handle_info(std::string_view function_name, std::string_view msg) { - const i_exception_handler *handler{exception_handler}; - if (handler != nullptr) { - handler->handle_info(function_name, msg); - return; - } - - default_exception_handler.handle_info(function_name, msg); -} - -void handle_trace(std::string_view function_name, std::string_view msg) { - const i_exception_handler *handler{exception_handler}; - if (handler != nullptr) { - handler->handle_trace(function_name, msg); - return; - } - - default_exception_handler.handle_trace(function_name, msg); -} - -void handle_warn(std::string_view function_name, std::string_view msg) { - const i_exception_handler *handler{exception_handler}; - if (handler != nullptr) { - handler->handle_warn(function_name, msg); - return; - } - - default_exception_handler.handle_warn(function_name, msg); -} -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - void set_exception_handler(const i_exception_handler *handler) { exception_handler = handler; } diff --git a/support/src/utils/file.cpp b/support/src/utils/file.cpp index 8727918d..1d747156 100644 --- a/support/src/utils/file.cpp +++ b/support/src/utils/file.cpp @@ -41,16 +41,8 @@ auto change_to_process_directory() -> bool { ::GetModuleFileNameA(nullptr, file_name.data(), static_cast(file_name.size() - 1U)); - auto path = utils::path::get_parent_path(file_name.c_str()); - auto res = ::SetCurrentDirectoryA(path.c_str()) != 0; - if (not res) { - throw utils::error::create_exception( - function_name, { - "failed to set current directory", - std::to_string(utils::get_last_error_code()), - path, - }); - } + auto path = utils::path::strip_to_file_name(file_name.c_str()); + ::SetCurrentDirectoryA(path.c_str()); #else // !defined(_WIN32) std::string path; path.resize(PATH_MAX + 1); diff --git a/support/test/src/utils/error_test.cpp b/support/test/src/utils/error_test.cpp index f2cba571..1b345693 100644 --- a/support/test/src/utils/error_test.cpp +++ b/support/test/src/utils/error_test.cpp @@ -38,12 +38,6 @@ TEST(utils_error, check_default_exception_handler) { TEST(utils_error, can_override_exception_handler) { struct my_exc_handler final : public utils::error::i_exception_handler { -#if defined(PROJECT_ENABLE_V2_ERRORS) - MOCK_METHOD(void, handle_debug, - (std::string_view function_name, std::string_view msg), - (const, override)); -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - MOCK_METHOD(void, handle_error, (std::string_view function_name, std::string_view msg), (const, override)); @@ -54,30 +48,11 @@ TEST(utils_error, can_override_exception_handler) { MOCK_METHOD(void, handle_exception, (std::string_view function_name, const std::exception &ex), (const, override)); - -#if defined(PROJECT_ENABLE_V2_ERRORS) - MOCK_METHOD(void, handle_info, - (std::string_view function_name, std::string_view msg), - (const, override)); - - MOCK_METHOD(void, handle_trace, - (std::string_view function_name, std::string_view msg), - (const, override)); - - MOCK_METHOD(void, handle_warn, - (std::string_view function_name, std::string_view msg), - (const, override)); -#endif // defined(PROJECT_ENABLE_V2_ERRORS) }; my_exc_handler handler{}; utils::error::set_exception_handler(&handler); -#if defined(PROJECT_ENABLE_V2_ERRORS) - EXPECT_CALL(handler, handle_debug("test_func", "debug")).WillOnce(Return()); - utils::error::handle_debug("test_func", "debug"); -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - EXPECT_CALL(handler, handle_error("test_func", "error")).WillOnce(Return()); utils::error::handle_error("test_func", "error"); @@ -93,17 +68,6 @@ TEST(utils_error, can_override_exception_handler) { }); utils::error::handle_exception("test_func_ex", ex); -#if defined(PROJECT_ENABLE_V2_ERRORS) - EXPECT_CALL(handler, handle_info("test_func", "info")).WillOnce(Return()); - utils::error::handle_info("test_func", "info"); - - EXPECT_CALL(handler, handle_trace("test_func", "trace")).WillOnce(Return()); - utils::error::handle_trace("test_func", "trace"); - - EXPECT_CALL(handler, handle_warn("test_func", "warn")).WillOnce(Return()); - utils::error::handle_warn("test_func", "warn"); -#endif // defined(PROJECT_ENABLE_V2_ERRORS) - utils::error::set_exception_handler(&utils::error::default_exception_handler); } } // namespace repertory