updated build system
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
Scott E. Graves 2025-02-19 16:12:13 -06:00
parent 99e12cec30
commit c5bdea0c8a
6 changed files with 206 additions and 24 deletions

View File

@ -58,6 +58,10 @@ if(PROJECT_IS_MINGW)
endif() endif()
endif() endif()
if (PROJECT_ENABLE_V2_ERRORS)
add_definitions(-DPROJECT_ENABLE_V2_ERRORS)
endif()
include(cmake/settings.cmake) include(cmake/settings.cmake)
include(cmake/flags.cmake) include(cmake/flags.cmake)
@ -143,6 +147,7 @@ endif()
-DPROJECT_COPYRIGHT=${PROJECT_COPYRIGHT} -DPROJECT_COPYRIGHT=${PROJECT_COPYRIGHT}
-DPROJECT_DESC=${PROJECT_DESC} -DPROJECT_DESC=${PROJECT_DESC}
-DPROJECT_DIST_DIR=${PROJECT_DIST_DIR} -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_WIN32_LONG_PATH_NAMES=${PROJECT_ENABLE_WIN32_LONG_PATH_NAMES}
-DPROJECT_ENABLE_BOOST=${PROJECT_ENABLE_BOOST} -DPROJECT_ENABLE_BOOST=${PROJECT_ENABLE_BOOST}
-DPROJECT_ENABLE_CPP_HTTPLIB=${PROJECT_ENABLE_CPP_HTTPLIB} -DPROJECT_ENABLE_CPP_HTTPLIB=${PROJECT_ENABLE_CPP_HTTPLIB}

View File

@ -42,6 +42,7 @@ done
PROJECT_APP_LIST=() PROJECT_APP_LIST=()
PROJECT_CMAKE_OPTS="" PROJECT_CMAKE_OPTS=""
PROJECT_ENABLE_WIN32_LONG_PATH_NAMES=OFF PROJECT_ENABLE_WIN32_LONG_PATH_NAMES=OFF
PROJECT_ENABLE_V2_ERRORS=OFF
PROJECT_IS_ALPINE=0 PROJECT_IS_ALPINE=0
PROJECT_IS_ARM64=0 PROJECT_IS_ARM64=0
PROJECT_MINGW64_COPY_DEPENDENCIES=() PROJECT_MINGW64_COPY_DEPENDENCIES=()
@ -234,6 +235,7 @@ 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_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_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_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_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_EXTERNAL_BUILD_ROOT=${PROJECT_EXTERNAL_BUILD_ROOT} ${PROJECT_CMAKE_OPTS}"
PROJECT_CMAKE_OPTS="-DPROJECT_GIT_REV=${PROJECT_GIT_REV} ${PROJECT_CMAKE_OPTS}" PROJECT_CMAKE_OPTS="-DPROJECT_GIT_REV=${PROJECT_GIT_REV} ${PROJECT_CMAKE_OPTS}"
@ -305,6 +307,7 @@ export PROJECT_COPYRIGHT
export PROJECT_DESC export PROJECT_DESC
export PROJECT_DIST_DIR export PROJECT_DIST_DIR
export PROJECT_ENABLE_WIN32_LONG_PATH_NAMES export PROJECT_ENABLE_WIN32_LONG_PATH_NAMES
export PROJECT_ENABLE_V2_ERRORS
export PROJECT_FILE_PART export PROJECT_FILE_PART
export PROJECT_GIT_REV export PROJECT_GIT_REV
export PROJECT_IS_ALPINE export PROJECT_IS_ALPINE

View File

@ -25,12 +25,16 @@
#include "utils/config.hpp" #include "utils/config.hpp"
namespace repertory::utils::error { namespace repertory::utils::error {
[[nodiscard]] auto [[nodiscard]] auto create_error_message(std::vector<std::string_view> items)
create_error_message(std::vector<std::string_view> items) -> std::string; -> std::string;
[[nodiscard]] auto [[nodiscard]] auto create_error_message(std::string_view function_name,
create_exception(std::string_view function_name, std::vector<std::string_view> items)
std::vector<std::string_view> items) -> std::runtime_error; -> std::string;
[[nodiscard]] auto create_exception(std::string_view function_name,
std::vector<std::string_view> items)
-> std::runtime_error;
struct i_exception_handler { struct i_exception_handler {
virtual ~i_exception_handler() {} virtual ~i_exception_handler() {}
@ -40,6 +44,11 @@ struct i_exception_handler {
auto operator=(const i_exception_handler &) noexcept = delete; auto operator=(const i_exception_handler &) noexcept = delete;
auto operator=(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, virtual void handle_error(std::string_view function_name,
std::string_view msg) const = 0; std::string_view msg) const = 0;
@ -48,56 +57,128 @@ struct i_exception_handler {
virtual void handle_exception(std::string_view function_name, virtual void handle_exception(std::string_view function_name,
const std::exception &ex) const = 0; 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: protected:
i_exception_handler() = default; i_exception_handler() = default;
}; };
struct iostream_exception_handler final : i_exception_handler { 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, void handle_error(std::string_view function_name,
std::string_view msg) const override { std::string_view msg) const override {
std::cerr << create_error_message({ std::cerr << create_error_message(function_name,
function_name, {
msg, "error",
}) msg,
})
<< std::endl; << std::endl;
} }
void handle_exception(std::string_view function_name) const override { void handle_exception(std::string_view function_name) const override {
std::cerr << create_error_message({ std::cerr << create_error_message(function_name,
function_name, {
"exception", "error",
"unknown", "exception",
}) "unknown",
})
<< std::endl; << std::endl;
} }
void handle_exception(std::string_view function_name, void handle_exception(std::string_view function_name,
const std::exception &ex) const override { const std::exception &ex) const override {
std::cerr << create_error_message({ std::cerr << create_error_message(
function_name, function_name,
"exception", {
(ex.what() == nullptr ? "unknown" : ex.what()), "error",
}) "exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
})
<< std::endl; << 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{}; inline const iostream_exception_handler default_exception_handler{};
extern std::atomic<const i_exception_handler *> exception_handler; extern std::atomic<const i_exception_handler *> exception_handler;
#if defined(PROJECT_ENABLE_TESTING) #if defined(PROJECT_ENABLE_TESTING)
[[nodiscard]] inline auto [[nodiscard]] inline auto get_exception_handler()
get_exception_handler() -> const i_exception_handler * { -> const i_exception_handler * {
return exception_handler; return exception_handler;
} }
#endif // defined(PROJECT_ENABLE_TESTING) #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_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);
void handle_exception(std::string_view function_name, const std::exception &ex); 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); void set_exception_handler(const i_exception_handler *handler);
} // namespace repertory::utils::error } // namespace repertory::utils::error

View File

@ -38,13 +38,30 @@ auto create_error_message(std::vector<std::string_view> items) -> std::string {
return stream.str(); return stream.str();
} }
auto create_error_message(std::string_view function_name,
std::vector<std::string_view> items) -> std::string {
items.insert(items.begin(), function_name);
return create_error_message(items);
}
auto create_exception(std::string_view function_name, auto create_exception(std::string_view function_name,
std::vector<std::string_view> items) std::vector<std::string_view> items)
-> std::runtime_error { -> std::runtime_error {
items.insert(items.begin(), function_name); return std::runtime_error(create_error_message(function_name, items));
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) { void handle_error(std::string_view function_name, std::string_view msg) {
const i_exception_handler *handler{exception_handler}; const i_exception_handler *handler{exception_handler};
if (handler != nullptr) { if (handler != nullptr) {
@ -76,6 +93,38 @@ void handle_exception(std::string_view function_name,
default_exception_handler.handle_exception(function_name, ex); 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) { void set_exception_handler(const i_exception_handler *handler) {
exception_handler = handler; exception_handler = handler;
} }

View File

@ -41,8 +41,16 @@ auto change_to_process_directory() -> bool {
::GetModuleFileNameA(nullptr, file_name.data(), ::GetModuleFileNameA(nullptr, file_name.data(),
static_cast<DWORD>(file_name.size() - 1U)); static_cast<DWORD>(file_name.size() - 1U));
auto path = utils::path::strip_to_file_name(file_name.c_str()); auto path = utils::path::get_parent_path(file_name.c_str());
::SetCurrentDirectoryA(path.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,
});
}
#else // !defined(_WIN32) #else // !defined(_WIN32)
std::string path; std::string path;
path.resize(PATH_MAX + 1); path.resize(PATH_MAX + 1);

View File

@ -38,6 +38,12 @@ TEST(utils_error, check_default_exception_handler) {
TEST(utils_error, can_override_exception_handler) { TEST(utils_error, can_override_exception_handler) {
struct my_exc_handler final : public utils::error::i_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, MOCK_METHOD(void, handle_error,
(std::string_view function_name, std::string_view msg), (std::string_view function_name, std::string_view msg),
(const, override)); (const, override));
@ -48,11 +54,30 @@ TEST(utils_error, can_override_exception_handler) {
MOCK_METHOD(void, handle_exception, MOCK_METHOD(void, handle_exception,
(std::string_view function_name, const std::exception &ex), (std::string_view function_name, const std::exception &ex),
(const, override)); (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{}; my_exc_handler handler{};
utils::error::set_exception_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()); EXPECT_CALL(handler, handle_error("test_func", "error")).WillOnce(Return());
utils::error::handle_error("test_func", "error"); utils::error::handle_error("test_func", "error");
@ -68,6 +93,17 @@ TEST(utils_error, can_override_exception_handler) {
}); });
utils::error::handle_exception("test_func_ex", ex); 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); utils::error::set_exception_handler(&utils::error::default_exception_handler);
} }
} // namespace repertory } // namespace repertory