From 98ea85ec6a4a06a59f13429c39afc5ee069bf2d5 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 25 Feb 2025 07:18:27 -0500 Subject: [PATCH 01/26] Add ystdlib-cpp submodule --- .gitmodules | 3 +++ components/core/submodules/ystdlib-cpp | 1 + 2 files changed, 4 insertions(+) create mode 160000 components/core/submodules/ystdlib-cpp diff --git a/.gitmodules b/.gitmodules index 99ef5f0943..ce4b1ba1e5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -32,3 +32,6 @@ [submodule "components/core/submodules/utfcpp"] path = components/core/submodules/utfcpp url = https://github.com/nemtrif/utfcpp.git +[submodule "components/core/submodules/ystdlib-cpp"] + path = components/core/submodules/ystdlib-cpp + url = https://github.com/Bill-hbrhbr/ystdlib-cpp.git diff --git a/components/core/submodules/ystdlib-cpp b/components/core/submodules/ystdlib-cpp new file mode 160000 index 0000000000..88a4c3eea3 --- /dev/null +++ b/components/core/submodules/ystdlib-cpp @@ -0,0 +1 @@ +Subproject commit 88a4c3eea3f893b74b0f39c355d489d2d4ae5867 From 208622367b3ec34a72d06555eafba1f7a7b1b268 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 25 Feb 2025 07:39:11 -0500 Subject: [PATCH 02/26] Migrate --- components/core/.clang-format | 3 +- components/core/CMakeLists.txt | 10 +- .../core/src/clp/GlobalMetadataDBConfig.hpp | 1 + .../core/src/clp/error_handling/ErrorCode.hpp | 148 ----------------- .../src/clp/ffi/ir_stream/IrErrorCode.cpp | 5 +- .../src/clp/ffi/ir_stream/IrErrorCode.hpp | 6 +- .../core/src/glt/GlobalMetadataDBConfig.hpp | 1 + components/core/tests/test-error_handling.cpp | 156 ------------------ 8 files changed, 19 insertions(+), 311 deletions(-) delete mode 100644 components/core/src/clp/error_handling/ErrorCode.hpp delete mode 100644 components/core/tests/test-error_handling.cpp diff --git a/components/core/.clang-format b/components/core/.clang-format index 4d0d3a87ce..bcd2660465 100644 --- a/components/core/.clang-format +++ b/components/core/.clang-format @@ -5,7 +5,8 @@ IncludeCategories: # Library headers. Update when adding new libraries. # NOTE: clang-format retains leading white-space on a line in violation of the YAML spec. - Regex: "<(absl|antlr4|archive|boost|bsoncxx|catch2|curl|date|fmt|json|log_surgeon|lzma|mongocxx\ -|msgpack|mysql|openssl|outcome|regex_utils|simdjson|spdlog|sqlite3|string_utils|yaml-cpp|zstd)" +|msgpack|mysql|openssl|outcome|regex_utils|simdjson|spdlog|sqlite3|string_utils|yaml-cpp|ystdlib\ +|zstd)" Priority: 3 # C system headers - Regex: "^<.+\\.h>" diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index d8b0352a45..629ed238ec 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -216,6 +216,13 @@ find_package(Threads REQUIRED) # Add yaml-cpp add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) +# Add ystdlib-cpp +block() + # Create local scope for YStdlib-cpp CMake build options. + set(BUILD_TESTING OFF) + add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) +endblock() + # Find and setup ZStd Library if(CLP_USE_STATIC_LIBS) set(ZStd_USE_STATIC_LIBS ON) @@ -436,7 +443,6 @@ set(SOURCE_FILES_unitTest src/clp/DictionaryEntry.hpp src/clp/DictionaryReader.hpp src/clp/DictionaryWriter.hpp - src/clp/error_handling/ErrorCode.hpp src/clp/EncodedVariableInterpreter.cpp src/clp/EncodedVariableInterpreter.hpp src/clp/ErrorCode.hpp @@ -632,7 +638,6 @@ set(SOURCE_FILES_unitTest tests/test-clp_s-search.cpp tests/test-EncodedVariableInterpreter.cpp tests/test-encoding_methods.cpp - tests/test-error_handling.cpp tests/test-ffi_IrUnitHandlerInterface.cpp tests/test-ffi_KeyValuePairLogEvent.cpp tests/test-ffi_SchemaTree.cpp @@ -689,6 +694,7 @@ target_link_libraries(unitTest clp::regex_utils clp::string_utils yaml-cpp::yaml-cpp + ystdlib::error_handling ${LIBLZMA_LIBRARIES} ZStd::ZStd ) diff --git a/components/core/src/clp/GlobalMetadataDBConfig.hpp b/components/core/src/clp/GlobalMetadataDBConfig.hpp index a6a1e4059b..aec9ed4777 100644 --- a/components/core/src/clp/GlobalMetadataDBConfig.hpp +++ b/components/core/src/clp/GlobalMetadataDBConfig.hpp @@ -1,6 +1,7 @@ #ifndef CLP_GLOBALMETADATADBCONFIG_HPP #define CLP_GLOBALMETADATADBCONFIG_HPP +#include #include namespace clp { diff --git a/components/core/src/clp/error_handling/ErrorCode.hpp b/components/core/src/clp/error_handling/ErrorCode.hpp deleted file mode 100644 index bc309adcd6..0000000000 --- a/components/core/src/clp/error_handling/ErrorCode.hpp +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef CLP_ERROR_HANDLING_ERRORCODE_HPP -#define CLP_ERROR_HANDLING_ERRORCODE_HPP - -#include -#include -#include -#include - -namespace clp::error_handling { -/** - * Concept that defines a template parameter of an integer-based error code enumeration. - * @tparam Type - */ -template -concept ErrorCodeEnumType = std::is_enum_v && requires(Type type) { - { - static_cast>(type) - } -> std::convertible_to; -}; - -/** - * Template that defines a `std::error_category` of the given set of error code enumeration. - * @tparam ErrorCodeEnum - */ -template -class ErrorCategory : public std::error_category { -public: - // Methods implementing `std::error_category` - /** - * Gets the error category name. - * Note: A specialization must be explicitly implemented for each valid `ErrorCodeEnum`. - * @return The name of the error category. - */ - [[nodiscard]] auto name() const noexcept -> char const* override; - - /** - * Gets the descriptive message associated with the given error. - * @param error_num - * @return The descriptive message for the error. - */ - [[nodiscard]] auto message(int error_num) const -> std::string override { - return message(static_cast(error_num)); - } - - /** - * @param error_num - * @param condition - * @return Whether the error condition of the given error matches the given condition. - */ - [[nodiscard]] auto - equivalent(int error_num, std::error_condition const& condition) const noexcept - -> bool override { - return equivalent(static_cast(error_num), condition); - } - - // Methods - /** - * Gets the descriptive message associated with the given error. - * Note: A specialization must be explicitly implemented for each valid `ErrorCodeEnum`. - * @param error_enum. - * @return The descriptive message for the error. - */ - [[nodiscard]] auto message(ErrorCodeEnum error_enum) const -> std::string; - - /** - * Note: A specialization can be implemented to create error enum to error condition mappings. - * @param error_num - * @param condition - * @return Whether the error condition of the given error matches the given condition. - */ - [[nodiscard]] auto - equivalent(ErrorCodeEnum error_enum, std::error_condition const& condition) const noexcept - -> bool; -}; - -/** - * Template class that defines an error code. An error code is represented by a error enum value and - * the associated error category. This template class is designed to be `std::error_code` - * compatible, meaning that every instance of this class can be used to construct a corresponded - * `std::error_code` instance, or compare with a `std::error_code` instance to inspect a specific - * error. - * @tparam ErrorCodeEnum - */ -template -class ErrorCode { -public: - // Constructor - ErrorCode(ErrorCodeEnum error) : m_error{error} {} - - /** - * @return The underlying error code enum. - */ - [[nodiscard]] auto get_error() const -> ErrorCodeEnum { return m_error; } - - /** - * @return The error code as an error number. - */ - [[nodiscard]] auto get_error_num() const -> int { return static_cast(m_error); } - - /** - * @return The reference to the singleton of the corresponded error category. - */ - [[nodiscard]] constexpr static auto get_category() -> ErrorCategory const& { - return cCategory; - } - -private: - static inline ErrorCategory const cCategory; - - ErrorCodeEnum m_error; -}; - -/** - * @tparam ErrorCodeEnum - * @param error - * @return Constructed `std::error_code` from the given `ErrorCode` instance. - */ -template -[[nodiscard]] auto make_error_code(ErrorCode error) -> std::error_code; - -template -auto ErrorCategory::equivalent( - ErrorCodeEnum error_enum, - std::error_condition const& condition -) const noexcept -> bool { - return std::error_category::default_error_condition(static_cast(error_enum)) == condition; -} - -template -auto make_error_code(ErrorCode error) -> std::error_code { - return {error.get_error_num(), ErrorCode::get_category()}; -} -} // namespace clp::error_handling - -/** - * The macro to create a specialization of `std::is_error_code_enum` for a given type T. Only types - * that are marked with this macro will be considered as a valid CLP error code enum, and thus used - * to specialize `ErrorCode` and `ErrorCategory` templates. - */ -// NOLINTBEGIN(bugprone-macro-parentheses, cppcoreguidelines-macro-usage) -#define CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(T) \ - template <> \ - struct std::is_error_code_enum> : std::true_type { \ - static_assert(std::is_enum_v); \ - }; -// NOLINTEND(bugprone-macro-parentheses, cppcoreguidelines-macro-usage) - -#endif // CLP_ERROR_HANDLING_ERRORCODE_HPP diff --git a/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp b/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp index f9a00ca1eb..dbca3bd61a 100644 --- a/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp +++ b/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp @@ -2,7 +2,10 @@ #include -using IrErrorCategory = clp::error_handling::ErrorCategory; +#include + +using IrErrorCategory + = ystdlib::error_handling::ErrorCategory; using clp::ffi::ir_stream::IrErrorCodeEnum; template <> diff --git a/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp b/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp index 8eaad4e16b..e384f369f1 100644 --- a/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp +++ b/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp @@ -3,7 +3,7 @@ #include -#include "../../error_handling/ErrorCode.hpp" +#include namespace clp::ffi::ir_stream { /** @@ -16,9 +16,9 @@ enum class IrErrorCodeEnum : uint8_t { IncompleteStream, }; -using IrErrorCode = clp::error_handling::ErrorCode; +using IrErrorCode = ystdlib::error_handling::ErrorCode; } // namespace clp::ffi::ir_stream -CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(clp::ffi::ir_stream::IrErrorCodeEnum); +YSTDLIB_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(clp::ffi::ir_stream::IrErrorCodeEnum); #endif // CLP_IRERRORCODE_HPP diff --git a/components/core/src/glt/GlobalMetadataDBConfig.hpp b/components/core/src/glt/GlobalMetadataDBConfig.hpp index 184a98f324..35519e7d61 100644 --- a/components/core/src/glt/GlobalMetadataDBConfig.hpp +++ b/components/core/src/glt/GlobalMetadataDBConfig.hpp @@ -1,6 +1,7 @@ #ifndef GLT_GLOBALMETADATADBCONFIG_HPP #define GLT_GLOBALMETADATADBCONFIG_HPP +#include #include namespace glt { diff --git a/components/core/tests/test-error_handling.cpp b/components/core/tests/test-error_handling.cpp deleted file mode 100644 index 44327c8332..0000000000 --- a/components/core/tests/test-error_handling.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "../src/clp/error_handling/ErrorCode.hpp" -#include "../src/clp/ffi/ir_stream/IrErrorCode.hpp" - -using clp::error_handling::ErrorCategory; -using clp::error_handling::ErrorCode; -using std::string; -using std::string_view; - -namespace { -enum class AlwaysSuccessErrorCodeEnum : uint8_t { - Success = 0 -}; - -enum class BinaryErrorCodeEnum : uint8_t { - Success = 0, - Failure -}; - -using AlwaysSuccessErrorCode = ErrorCode; -using AlwaysSuccessErrorCategory = ErrorCategory; -using BinaryErrorCode = ErrorCode; -using BinaryErrorCategory = ErrorCategory; - -constexpr string_view cAlwaysSuccessErrorCategoryName{"Always Success Error Code"}; -constexpr string_view cBinaryTestErrorCategoryName{"Binary Error Code"}; -constexpr string_view cSuccessErrorMsg{"Success"}; -constexpr string_view cFailureErrorMsg{"Failure"}; -constexpr string_view cUnrecognizedErrorCode{"Unrecognized Error Code"}; -constexpr std::array cFailureConditions{std::errc::not_connected, std::errc::timed_out}; -constexpr std::array cNoneFailureConditions{std::errc::broken_pipe, std::errc::address_in_use}; -} // namespace - -CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(AlwaysSuccessErrorCodeEnum); -CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(BinaryErrorCodeEnum); - -template <> -auto AlwaysSuccessErrorCategory::name() const noexcept -> char const* { - return cAlwaysSuccessErrorCategoryName.data(); -} - -template <> -auto AlwaysSuccessErrorCategory::message(AlwaysSuccessErrorCodeEnum error_enum) const -> string { - switch (error_enum) { - case AlwaysSuccessErrorCodeEnum::Success: - return string{cSuccessErrorMsg}; - default: - return string{cUnrecognizedErrorCode}; - } -} - -template <> -auto BinaryErrorCategory::name() const noexcept -> char const* { - return cBinaryTestErrorCategoryName.data(); -} - -template <> -auto BinaryErrorCategory::message(BinaryErrorCodeEnum error_enum) const -> string { - switch (error_enum) { - case BinaryErrorCodeEnum::Success: - return string{cSuccessErrorMsg}; - case BinaryErrorCodeEnum::Failure: - return string{cFailureErrorMsg}; - default: - return string{cUnrecognizedErrorCode}; - } -} - -template <> -auto BinaryErrorCategory::equivalent( - BinaryErrorCodeEnum error_enum, - std::error_condition const& condition -) const noexcept -> bool { - switch (error_enum) { - case BinaryErrorCodeEnum::Failure: - return std::any_of( - cFailureConditions.cbegin(), - cFailureConditions.cend(), - [&](auto failure_condition) -> bool { return condition == failure_condition; } - ); - default: - return false; - } -} - -TEST_CASE("test_error_code_implementation", "[error_handling][ErrorCode]") { - // Test error codes within the same error category - BinaryErrorCode const success{BinaryErrorCodeEnum::Success}; - std::error_code const success_error_code{success}; - REQUIRE((success == success_error_code)); - REQUIRE((cSuccessErrorMsg == success_error_code.message())); - REQUIRE((BinaryErrorCode::get_category() == success_error_code.category())); - REQUIRE((cBinaryTestErrorCategoryName == success_error_code.category().name())); - - BinaryErrorCode const failure{BinaryErrorCodeEnum::Failure}; - std::error_code const failure_error_code{failure}; - REQUIRE((failure == failure_error_code)); - REQUIRE((cFailureErrorMsg == failure_error_code.message())); - REQUIRE((BinaryErrorCode::get_category() == failure_error_code.category())); - REQUIRE((cBinaryTestErrorCategoryName == failure_error_code.category().name())); - std::for_each( - cFailureConditions.cbegin(), - cFailureConditions.cend(), - [&](auto failure_condition) { REQUIRE((failure_error_code == failure_condition)); } - ); - std::for_each( - cNoneFailureConditions.cbegin(), - cNoneFailureConditions.cend(), - [&](auto none_failure_condition) { - REQUIRE((failure_error_code != none_failure_condition)); - } - ); - - REQUIRE((success_error_code != failure_error_code)); - REQUIRE((success_error_code.category() == failure_error_code.category())); - - AlwaysSuccessErrorCode const always_success{AlwaysSuccessErrorCodeEnum::Success}; - std::error_code const always_success_error_code{always_success}; - REQUIRE((always_success_error_code == always_success)); - REQUIRE((cSuccessErrorMsg == always_success_error_code.message())); - REQUIRE((AlwaysSuccessErrorCode::get_category() == always_success_error_code.category())); - REQUIRE((cAlwaysSuccessErrorCategoryName == always_success_error_code.category().name())); - - // Compare error codes from different error category - // Error codes that have the same value or message won't be the same with each other if they are - // from different error categories. - REQUIRE((success_error_code.value() == always_success_error_code.value())); - REQUIRE((success_error_code.message() == always_success_error_code.message())); - REQUIRE((success_error_code.category() != always_success_error_code.category())); - REQUIRE((success_error_code != always_success_error_code)); - REQUIRE((AlwaysSuccessErrorCode{AlwaysSuccessErrorCodeEnum::Success} != success_error_code)); - REQUIRE((BinaryErrorCode{BinaryErrorCodeEnum::Success} != always_success_error_code)); -} - -TEST_CASE("test_ir_error_code", "[error_handling][ErrorCode][IrErrorCode]") { - using clp::ffi::ir_stream::IrErrorCode; - using clp::ffi::ir_stream::IrErrorCodeEnum; - - auto assert_error_code_matches_error_code_enum = [](IrErrorCodeEnum error_code_enum) -> bool { - std::error_code const error_code{IrErrorCode{error_code_enum}}; - return error_code == IrErrorCode{error_code_enum}; - }; - - REQUIRE(assert_error_code_matches_error_code_enum(IrErrorCodeEnum::DecodingMethodFailure)); - REQUIRE(assert_error_code_matches_error_code_enum(IrErrorCodeEnum::EndOfStream)); - REQUIRE(assert_error_code_matches_error_code_enum(IrErrorCodeEnum::IncompleteStream)); -} From f1b3f251f4ad4c7ee3a4632dc3d68e3f92618ceb Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 25 Feb 2025 08:01:52 -0500 Subject: [PATCH 03/26] Fix cmake build flag --- components/core/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 629ed238ec..f0fc52ffd6 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -217,11 +217,9 @@ find_package(Threads REQUIRED) add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) # Add ystdlib-cpp -block() - # Create local scope for YStdlib-cpp CMake build options. - set(BUILD_TESTING OFF) - add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) -endblock() +set(BUILD_TESTING OFF) +add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) +set(BUILD_TESTING ON) # Find and setup ZStd Library if(CLP_USE_STATIC_LIBS) From 70b14a4014c2a50cccb05674b0b0b835cfb2e083 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Wed, 26 Feb 2025 17:32:22 -0500 Subject: [PATCH 04/26] Update CMake option on ystdlib-cpp unit test building --- components/core/CMakeLists.txt | 2 -- components/core/submodules/ystdlib-cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index f0fc52ffd6..68ebf12379 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -217,9 +217,7 @@ find_package(Threads REQUIRED) add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) # Add ystdlib-cpp -set(BUILD_TESTING OFF) add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) -set(BUILD_TESTING ON) # Find and setup ZStd Library if(CLP_USE_STATIC_LIBS) diff --git a/components/core/submodules/ystdlib-cpp b/components/core/submodules/ystdlib-cpp index 88a4c3eea3..5dee7c45e1 160000 --- a/components/core/submodules/ystdlib-cpp +++ b/components/core/submodules/ystdlib-cpp @@ -1 +1 @@ -Subproject commit 88a4c3eea3f893b74b0f39c355d489d2d4ae5867 +Subproject commit 5dee7c45e1a7f83efc10e98a09c64eea253b390c From 4770e5e1c1b547d6994a9b3699a5c23bab53894c Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 11:08:48 -0500 Subject: [PATCH 05/26] Update ystdlib-cpp path --- .gitmodules | 2 +- components/core/submodules/ystdlib-cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index ce4b1ba1e5..7e88cfe1b9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,4 +34,4 @@ url = https://github.com/nemtrif/utfcpp.git [submodule "components/core/submodules/ystdlib-cpp"] path = components/core/submodules/ystdlib-cpp - url = https://github.com/Bill-hbrhbr/ystdlib-cpp.git + url = https://github.com/y-scope/ystdlib-cpp.git diff --git a/components/core/submodules/ystdlib-cpp b/components/core/submodules/ystdlib-cpp index 5dee7c45e1..95d89d1483 160000 --- a/components/core/submodules/ystdlib-cpp +++ b/components/core/submodules/ystdlib-cpp @@ -1 +1 @@ -Subproject commit 5dee7c45e1a7f83efc10e98a09c64eea253b390c +Subproject commit 95d89d148312c7c447f4164766ad35dd7996b1cc From f1dade5aeeafc449a4778bf6b700eccb4c9a730f Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 11:18:10 -0500 Subject: [PATCH 06/26] Update dependency taskfiles --- deps-tasks.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/deps-tasks.yml b/deps-tasks.yml index 55be37cda8..4832448f98 100644 --- a/deps-tasks.yml +++ b/deps-tasks.yml @@ -20,6 +20,7 @@ vars: G_UTFCPP_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/deps#utfcpp.md5" G_YAML_CPP_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/deps#yaml-cpp.md5" G_YSCOPE_LOG_VIEWER_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/deps#yscope-log-viewer.md5" + G_YSTDLIB_CPP_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/deps#ystdlib-cpp.md5" tasks: default: @@ -41,6 +42,7 @@ tasks: - "{{.G_SQLITE3_CHECKSUM_FILE}}" - "{{.G_UTFCPP_CHECKSUM_FILE}}" - "{{.G_YAML_CPP_CHECKSUM_FILE}}" + - "{{.G_YSTDLIB_CPP_CHECKSUM_FILE}}" generates: ["{{.G_DEPS_CORE_CHECKSUM_FILE}}"] deps: ["all-internal-deps"] cmds: @@ -57,6 +59,7 @@ tasks: "{{.G_SQLITE3_CHECKSUM_FILE}}" "{{.G_UTFCPP_CHECKSUM_FILE}}" "{{.G_YAML_CPP_CHECKSUM_FILE}}" + "{{.G_YSTDLIB_CPP_CHECKSUM_FILE}}" >> "{{.G_DEPS_CORE_CHECKSUM_FILE}}" log-viewer: @@ -99,6 +102,7 @@ tasks: - task: "utfcpp" - task: "yaml-cpp" - task: "yscope-log-viewer" + - task: "ystdlib-cpp" abseil-cpp: internal: true @@ -463,6 +467,37 @@ tasks: CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" INCLUDE_PATTERNS: ["{{.DEST}}"] + ystdlib-cpp: + internal: true + vars: + CHECKSUM_FILE: "{{.G_YSTDLIB_CPP_CHECKSUM_FILE}}" + DEST: "{{.G_CORE_COMPONENT_SUBMODULES_DIR}}/ystdlib-cpp" + sources: + - "{{.G_DEP_DOWNLOAD_SCRIPT}}" + - "{{.G_UTILS_TASKFILE}}" + - "{{.ROOT_DIR}}/Taskfile.yml" + - "{{.TASKFILE}}" + generates: ["{{.CHECKSUM_FILE}}"] + deps: + - ":init" + - task: ":utils:validate-checksum" + vars: + CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" + INCLUDE_PATTERNS: ["{{.DEST}}"] + cmds: + - task: "download-dependency" + vars: + DEST: "{{.DEST}}" + FLAGS: "--extract" + SRC_NAME: "ystdlib-cpp-95d89d148312c7c447f4164766ad35dd7996b1cc" + SRC_URL: "https://github.com/y-scope/ystdlib-cpp/archive/95d89d1.zip" + # This command must be last + - task: ":utils:compute-checksum" + vars: + CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" + INCLUDE_PATTERNS: ["{{.DEST}}"] + + download-dependency: internal: true label: "{{.TASK}}-{{.SRC_NAME}}" From 7bdb0a4ac765c9a96dc95ccf327ec805cc0c1945 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 11:18:54 -0500 Subject: [PATCH 07/26] Turn of unit test building --- components/core/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 68ebf12379..3568c4fb72 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -217,6 +217,7 @@ find_package(Threads REQUIRED) add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) # Add ystdlib-cpp +option(YSTDLIB_CPP_BUILD_TESTING "" OFF) add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) # Find and setup ZStd Library From 82ac7da76b66db1f630654bd4b0076b3d5cc35e7 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 11:21:59 -0500 Subject: [PATCH 08/26] Remove unrelated changes --- components/core/src/clp/GlobalMetadataDBConfig.hpp | 1 - components/core/src/glt/GlobalMetadataDBConfig.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/components/core/src/clp/GlobalMetadataDBConfig.hpp b/components/core/src/clp/GlobalMetadataDBConfig.hpp index aec9ed4777..a6a1e4059b 100644 --- a/components/core/src/clp/GlobalMetadataDBConfig.hpp +++ b/components/core/src/clp/GlobalMetadataDBConfig.hpp @@ -1,7 +1,6 @@ #ifndef CLP_GLOBALMETADATADBCONFIG_HPP #define CLP_GLOBALMETADATADBCONFIG_HPP -#include #include namespace clp { diff --git a/components/core/src/glt/GlobalMetadataDBConfig.hpp b/components/core/src/glt/GlobalMetadataDBConfig.hpp index 35519e7d61..184a98f324 100644 --- a/components/core/src/glt/GlobalMetadataDBConfig.hpp +++ b/components/core/src/glt/GlobalMetadataDBConfig.hpp @@ -1,7 +1,6 @@ #ifndef GLT_GLOBALMETADATADBCONFIG_HPP #define GLT_GLOBALMETADATADBCONFIG_HPP -#include #include namespace glt { From 11fa69029467787a1efbefc93e339214b4f6a6bc Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 11:52:01 -0500 Subject: [PATCH 09/26] fix task name --- deps-tasks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps-tasks.yml b/deps-tasks.yml index 61e91e0c4b..3d014cbada 100644 --- a/deps-tasks.yml +++ b/deps-tasks.yml @@ -480,7 +480,7 @@ tasks: generates: ["{{.CHECKSUM_FILE}}"] deps: - ":init" - - task: ":utils:validate-checksum" + - task: ":utils:checksum:validate" vars: CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" INCLUDE_PATTERNS: ["{{.DEST}}"] From 635ce2c70addc6ed09a20e4395ccbda3aaeb0187 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 11:53:46 -0500 Subject: [PATCH 10/26] fix task name --- deps-tasks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps-tasks.yml b/deps-tasks.yml index 3d014cbada..582ed63b04 100644 --- a/deps-tasks.yml +++ b/deps-tasks.yml @@ -492,7 +492,7 @@ tasks: SRC_NAME: "ystdlib-cpp-95d89d148312c7c447f4164766ad35dd7996b1cc" SRC_URL: "https://github.com/y-scope/ystdlib-cpp/archive/95d89d1.zip" # This command must be last - - task: ":utils:compute-checksum" + - task: ":utils:checksum:compute" vars: CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" INCLUDE_PATTERNS: ["{{.DEST}}"] From 2fc45675a8f9721632ba3e0f44d11f4d7018e80b Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:07:21 -0500 Subject: [PATCH 11/26] Remove focal workflows --- .github/workflows/clp-core-build.yaml | 136 -------------------------- 1 file changed, 136 deletions(-) diff --git a/.github/workflows/clp-core-build.yaml b/.github/workflows/clp-core-build.yaml index 20b305f8d9..b72341b1e2 100644 --- a/.github/workflows/clp-core-build.yaml +++ b/.github/workflows/clp-core-build.yaml @@ -40,7 +40,6 @@ jobs: runs-on: "ubuntu-latest" outputs: centos_stream_9_image_changed: "${{steps.filter.outputs.centos_stream_9_image}}" - ubuntu_focal_image_changed: "${{steps.filter.outputs.ubuntu_focal_image}}" ubuntu_jammy_image_changed: "${{steps.filter.outputs.ubuntu_jammy_image}}" clp_changed: "${{steps.filter.outputs.clp}}" steps: @@ -72,12 +71,6 @@ jobs: - "components/core/tools/scripts/lib_install/*.sh" - "components/core/tools/docker-images/clp-env-base-centos-stream-9/**" - "components/core/tools/scripts/lib_install/centos-stream-9/**" - ubuntu_focal_image: - - ".github/actions/**" - - ".github/workflows/clp-core-build.yaml" - - "components/core/tools/scripts/lib_install/*.sh" - - "components/core/tools/docker-images/clp-env-base-ubuntu-focal/**" - - "components/core/tools/scripts/lib_install/ubuntu-focal/**" ubuntu_jammy_image: - ".github/actions/**" - ".github/workflows/clp-core-build.yaml" @@ -122,31 +115,6 @@ jobs: ${{github.event_name != 'pull_request' && github.ref == 'refs/heads/main'}} token: "${{secrets.GITHUB_TOKEN}}" - ubuntu-focal-deps-image: - if: "needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed == 'true'" - needs: "filter-relevant-changes" - runs-on: "ubuntu-latest" - steps: - - uses: "actions/checkout@v4" - with: - submodules: "recursive" - - - name: "Work around actions/runner-images/issues/6775" - run: "chown $(id -u):$(id -g) -R ." - shell: "bash" - - - uses: "./.github/actions/clp-core-build-containers" - env: - OS_NAME: "ubuntu-focal" - with: - image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}" - docker_context: "components/core" - docker_file: "components/core/tools/docker-images/clp-env-base-${{env.OS_NAME}}\ - /Dockerfile" - push_deps_image: >- - ${{github.event_name != 'pull_request' && github.ref == 'refs/heads/main'}} - token: "${{secrets.GITHUB_TOKEN}}" - ubuntu-jammy-deps-image: if: "needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'true'" needs: "filter-relevant-changes" @@ -206,45 +174,6 @@ jobs: || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}} upload_binaries: "false" - ubuntu-focal-binaries: - # Run if the ancestor jobs succeeded OR they were skipped and clp was changed. - if: >- - success() - || (!cancelled() && !failure() && needs.filter-relevant-changes.outputs.clp_changed == 'true') - needs: - - "filter-relevant-changes" - - "ubuntu-focal-deps-image" - strategy: - matrix: - include: - - use_shared_libs: true - upload_binaries: false - - use_shared_libs: false - upload_binaries: true - name: "ubuntu-focal-${{matrix.use_shared_libs && 'dynamic' || 'static'}}-linked-bins" - continue-on-error: true - runs-on: "ubuntu-latest" - steps: - - uses: "actions/checkout@v4" - with: - submodules: "recursive" - - - name: "Work around actions/runner-images/issues/6775" - run: "chown $(id -u):$(id -g) -R ." - shell: "bash" - - - uses: "./.github/actions/clp-core-build" - env: - OS_NAME: "ubuntu-focal" - with: - image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}" - use_shared_libs: "${{matrix.use_shared_libs}}" - use_published_image: >- - ${{needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed == 'false' - || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}} - upload_binaries: "${{matrix.upload_binaries}}" - binaries_artifact_name: "${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" - ubuntu-jammy-binaries: # Run if the ancestor jobs succeeded OR they were skipped and clp was changed. if: >- @@ -278,68 +207,3 @@ jobs: ${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}} upload_binaries: "false" - - ubuntu-focal-binaries-image: - # Run if the ancestor jobs were successful/skipped, building clp was successful, and this is a - # push to `main`. - if: >- - !cancelled() - && !failure() - && needs.ubuntu-focal-binaries.result == 'success' - && github.event_name == 'push' - && github.ref == 'refs/heads/main' - needs: "ubuntu-focal-binaries" - runs-on: "ubuntu-latest" - env: - OS_NAME: "ubuntu-focal" - TMP_OUTPUT_DIR: "/tmp" - steps: - - uses: "actions/checkout@v4" - with: - submodules: "recursive" - - - name: "Work around actions/runner-images/issues/6775" - run: "chown $(id -u):$(id -g) -R ." - shell: "bash" - - - uses: "actions/download-artifact@v4" - with: - name: "${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" - path: "${{env.TMP_OUTPUT_DIR}}/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" - - - name: "Untar binaries" - working-directory: >- - ${{env.TMP_OUTPUT_DIR}}/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}} - run: |- - tar xf clp.tar - rm clp.tar - - - uses: "docker/login-action@v3" - with: - registry: "ghcr.io" - username: "${{github.actor}}" - password: "${{secrets.GITHUB_TOKEN}}" - - - name: "Sanitize the repo's name" - id: "sanitize_repo_name" - run: |- - # Docker doesn't support repository names with uppercase characters, so we convert to - # lowercase here. - lowercase_repo=$(echo '${{github.repository}}' | tr '[:upper:]' '[:lower:]') - echo "repository=${lowercase_repo}" >> "$GITHUB_OUTPUT" - shell: "bash" - - - id: "core_image_meta" - uses: "docker/metadata-action@v5" - with: - images: >- - ghcr.io/${{steps.sanitize_repo_name.outputs.repository}}/clp-core-x86-${{env.OS_NAME}} - tags: "type=raw,value=${{github.ref_name}}" - - - uses: "docker/build-push-action@v5" - with: - context: "${{env.TMP_OUTPUT_DIR}}/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" - file: "components/core/tools/docker-images/clp-core-${{env.OS_NAME}}/Dockerfile" - push: true - tags: "${{steps.core_image_meta.outputs.tags}}" - labels: "${{steps.core_image_meta.outputs.labels}}" From 06b90fb60d457e5627ee392d64e2cd558bfc554f Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:10:46 -0500 Subject: [PATCH 12/26] Upgrade macos to use appleclang16 --- .github/workflows/clp-core-build-macos.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index 8196e75d80..156a634fb0 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -58,6 +58,11 @@ jobs: rm -f /usr/local/bin/pydoc3* rm -f /usr/local/bin/python3* + - name: "Install coreutils (for md5sum) and Apple Clang 16 (for C++20)" + run: |- + brew install coreutils + brew install llvm@16 + - name: "Install dependencies" run: "./components/core/tools/scripts/lib_install/macos/install-all.sh" @@ -68,6 +73,9 @@ jobs: shell: "bash" - name: "Build CLP-core and run unit tests" + env: + "CC": "/opt/homebrew/opt/llvm@16/bin/clang" + "CXX": "/opt/homebrew/opt/llvm@16/bin/clang++" shell: "bash" working-directory: "./components/core" # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow From e7b55eb1e3f9d7a2df43d6eaeb6db1324af26920 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:17:43 -0500 Subject: [PATCH 13/26] Update for macos-13 --- .github/workflows/clp-core-build-macos.yaml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index 156a634fb0..24a48cc1d2 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -73,9 +73,20 @@ jobs: shell: "bash" - name: "Build CLP-core and run unit tests" - env: - "CC": "/opt/homebrew/opt/llvm@16/bin/clang" + env: >- + ${{ + 'macos-14' == matrix.os + && fromJson('{ + "CC": "/opt/homebrew/opt/llvm@16/bin/clang", "CXX": "/opt/homebrew/opt/llvm@16/bin/clang++" + }') + || 'macos-13' == matrix.os + && fromJson('{ + "CC": "/usr/local/opt/llvm@16/bin/clang", + "CXX": "/user/local/opt/llvm@16/bin/clang++" + }') + || fromJson('{}') + }} shell: "bash" working-directory: "./components/core" # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow From f04c65ff03b05781bc68dd843602546024e72813 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:22:41 -0500 Subject: [PATCH 14/26] Move envs to deps:core --- .github/workflows/clp-core-build-macos.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index 24a48cc1d2..dc493d1c1a 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -70,9 +70,6 @@ jobs: shell: "bash" - run: "task deps:core" - shell: "bash" - - - name: "Build CLP-core and run unit tests" env: >- ${{ 'macos-14' == matrix.os @@ -88,6 +85,9 @@ jobs: || fromJson('{}') }} shell: "bash" + + - name: "Build CLP-core and run unit tests" + shell: "bash" working-directory: "./components/core" # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow run: >- From 1c94f17c25b9f32d6ca52e4c30ac8959d469e216 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:29:43 -0500 Subject: [PATCH 15/26] Allow env vars to pass in python scripts --- .github/workflows/clp-core-build-macos.yaml | 6 +++--- .../core/tools/scripts/utils/build-and-run-unit-tests.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index dc493d1c1a..24a48cc1d2 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -70,6 +70,9 @@ jobs: shell: "bash" - run: "task deps:core" + shell: "bash" + + - name: "Build CLP-core and run unit tests" env: >- ${{ 'macos-14' == matrix.os @@ -85,9 +88,6 @@ jobs: || fromJson('{}') }} shell: "bash" - - - name: "Build CLP-core and run unit tests" - shell: "bash" working-directory: "./components/core" # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow run: >- diff --git a/components/core/tools/scripts/utils/build-and-run-unit-tests.py b/components/core/tools/scripts/utils/build-and-run-unit-tests.py index 7c4b136171..3f52ff7dbf 100644 --- a/components/core/tools/scripts/utils/build-and-run-unit-tests.py +++ b/components/core/tools/scripts/utils/build-and-run-unit-tests.py @@ -1,5 +1,6 @@ import argparse import logging +import os import subprocess import sys from pathlib import Path @@ -31,7 +32,7 @@ def _config_cmake_project(src_dir: Path, build_dir: Path, use_shared_libs: bool) ] if use_shared_libs: cmd.append("-DCLP_USE_STATIC_LIBS=OFF") - subprocess.run(cmd, check=True) + subprocess.run(cmd, check=True, env=os.environ) def _build_project(build_dir: Path, num_jobs: Optional[int]): @@ -48,7 +49,7 @@ def _build_project(build_dir: Path, num_jobs: Optional[int]): ] if num_jobs is not None: cmd.append(str(num_jobs)) - subprocess.run(cmd, check=True) + subprocess.run(cmd, check=True, env=os.environ) def _run_unit_tests(build_dir: Path, test_spec: Optional[str]): @@ -62,7 +63,7 @@ def _run_unit_tests(build_dir: Path, test_spec: Optional[str]): ] if test_spec is not None: cmd.append(test_spec) - subprocess.run(cmd, cwd=build_dir, check=True) + subprocess.run(cmd, cwd=build_dir, check=True, env=os.environ) def main(argv: List[str]) -> int: From 53ca62a7a944afb840c5ffd1970fb7d642a2d6c4 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:37:45 -0500 Subject: [PATCH 16/26] Add env var to cli --- .github/workflows/clp-core-build-macos.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index 24a48cc1d2..d6524fc0ee 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -91,6 +91,8 @@ jobs: working-directory: "./components/core" # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow run: >- + CC=$CC + CXX=$CXX python3 ./tools/scripts/utils/build-and-run-unit-tests.py ${{matrix.use_shared_libs == 'true' && '--use-shared-libs' || ''}} --source-dir . From 0d0d25f50b7bd89d1b90a47ca33b2c4d7cb60702 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Tue, 4 Mar 2025 12:44:47 -0500 Subject: [PATCH 17/26] Update .github/workflows/clp-core-build-macos.yaml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/clp-core-build-macos.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index d6524fc0ee..d93b918e7b 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -75,15 +75,15 @@ jobs: - name: "Build CLP-core and run unit tests" env: >- ${{ - 'macos-14' == matrix.os + 'macos-14' == matrix.runner && fromJson('{ "CC": "/opt/homebrew/opt/llvm@16/bin/clang", "CXX": "/opt/homebrew/opt/llvm@16/bin/clang++" }') - || 'macos-13' == matrix.os + || 'macos-13' == matrix.runner && fromJson('{ "CC": "/usr/local/opt/llvm@16/bin/clang", - "CXX": "/user/local/opt/llvm@16/bin/clang++" + "CXX": "/usr/local/opt/llvm@16/bin/clang++" }') || fromJson('{}') }} From af20a46f2c54c2754708f2c655d7f2e1ab80ae71 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Wed, 12 Mar 2025 13:48:50 -0400 Subject: [PATCH 18/26] Remove workflow changes --- .github/workflows/clp-core-build-macos.yaml | 44 +++--- .github/workflows/clp-core-build.yaml | 149 ++++++++++++++++-- .../workflows/clp-execution-image-build.yaml | 26 --- .github/workflows/clp-lint.yaml | 2 +- .../scripts/utils/build-and-run-unit-tests.py | 7 +- 5 files changed, 161 insertions(+), 67 deletions(-) diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index d93b918e7b..f9ec13da42 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -4,6 +4,7 @@ on: pull_request: paths: - ".github/workflows/clp-core-build-macos.yaml" + - ".gitmodules" - "components/core/cmake/**" - "components/core/CMakeLists.txt" - "components/core/src/**" @@ -17,6 +18,7 @@ on: push: paths: - ".github/workflows/clp-core-build-macos.yaml" + - ".gitmodules" - "components/core/cmake/**" - "components/core/CMakeLists.txt" - "components/core/src/**" @@ -41,12 +43,19 @@ jobs: build-macos: strategy: matrix: - runner: ["macos-13", "macos-14"] - use_shared_libs: [true, false] - runs-on: "${{matrix.runner}}" + os: + - "macos-13" + - "macos-14" + - "macos-15" + use_shared_libs: + - true + - false + runs-on: "${{matrix.os}}" steps: - uses: "actions/checkout@v4" with: + # Fetch history so that the `clang-tidy-diff` task can compare against the main branch. + fetch-depth: 0 submodules: "recursive" # See https://github.com/actions/setup-python/issues/577 @@ -58,11 +67,6 @@ jobs: rm -f /usr/local/bin/pydoc3* rm -f /usr/local/bin/python3* - - name: "Install coreutils (for md5sum) and Apple Clang 16 (for C++20)" - run: |- - brew install coreutils - brew install llvm@16 - - name: "Install dependencies" run: "./components/core/tools/scripts/lib_install/macos/install-all.sh" @@ -73,29 +77,19 @@ jobs: shell: "bash" - name: "Build CLP-core and run unit tests" - env: >- - ${{ - 'macos-14' == matrix.runner - && fromJson('{ - "CC": "/opt/homebrew/opt/llvm@16/bin/clang", - "CXX": "/opt/homebrew/opt/llvm@16/bin/clang++" - }') - || 'macos-13' == matrix.runner - && fromJson('{ - "CC": "/usr/local/opt/llvm@16/bin/clang", - "CXX": "/usr/local/opt/llvm@16/bin/clang++" - }') - || fromJson('{}') - }} shell: "bash" working-directory: "./components/core" # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow run: >- - CC=$CC - CXX=$CXX python3 ./tools/scripts/utils/build-and-run-unit-tests.py - ${{matrix.use_shared_libs == 'true' && '--use-shared-libs' || ''}} + ${{matrix.use_shared_libs == true && '--use-shared-libs' || ''}} --source-dir . --build-dir build --num-jobs $(getconf _NPROCESSORS_ONLN) --test-spec "~[Stopwatch]" + + # TODO: When enough files are passing clang-tidy, switch to a full pass on schedule only. + # - run: >- + # task lint:check-cpp-${{(github.event_name == 'schedule') && 'full' || 'diff'}} + - run: "task lint:check-cpp-full" + shell: "bash" diff --git a/.github/workflows/clp-core-build.yaml b/.github/workflows/clp-core-build.yaml index b72341b1e2..3f5d17e731 100644 --- a/.github/workflows/clp-core-build.yaml +++ b/.github/workflows/clp-core-build.yaml @@ -3,8 +3,8 @@ name: "clp-core-build" on: pull_request: paths: - - ".github/actions/clp-core-build/action.yaml" - ".github/actions/clp-core-build-containers/action.yaml" + - ".github/actions/run-on-image/action.yaml" - ".github/workflows/clp-core-build.yaml" - ".gitmodules" - "components/core/**" @@ -14,8 +14,8 @@ on: - "!components/core/tools/scripts/lib_install/macos/**" push: paths: - - ".github/actions/clp-core-build/action.yaml" - ".github/actions/clp-core-build-containers/action.yaml" + - ".github/actions/run-on-image/action.yaml" - ".github/workflows/clp-core-build.yaml" - ".gitmodules" - "components/core/**" @@ -151,7 +151,7 @@ jobs: strategy: matrix: use_shared_libs: [true, false] - name: "centos-stream-9-${{matrix.use_shared_libs && 'dynamic' || 'static'}}-linked-bins" + name: "centos-stream-9-${{matrix.use_shared_libs == true && 'dynamic' || 'static'}}-linked-bins" continue-on-error: true runs-on: "ubuntu-latest" steps: @@ -163,16 +163,21 @@ jobs: run: "chown $(id -u):$(id -g) -R ." shell: "bash" - - uses: "./.github/actions/clp-core-build" + - uses: "./.github/actions/run-on-image" env: OS_NAME: "centos-stream-9" with: image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}" - use_shared_libs: "${{matrix.use_shared_libs}}" use_published_image: >- ${{needs.filter-relevant-changes.outputs.centos_stream_9_image_changed == 'false' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}} - upload_binaries: "false" + run_command: >- + task deps:core + && python3 /mnt/repo/components/core/tools/scripts/utils/build-and-run-unit-tests.py + ${{matrix.use_shared_libs == true && '--use-shared-libs' || ''}} + --source-dir /mnt/repo/components/core + --build-dir /mnt/repo/components/core/build + --num-jobs $(getconf _NPROCESSORS_ONLN) ubuntu-jammy-binaries: # Run if the ancestor jobs succeeded OR they were skipped and clp was changed. @@ -184,8 +189,14 @@ jobs: - "ubuntu-jammy-deps-image" strategy: matrix: - use_shared_libs: [true, false] - name: "ubuntu-jammy-${{matrix.use_shared_libs && 'dynamic' || 'static'}}-linked-bins" + include: + - use_shared_libs: true + upload_binaries: false + - use_shared_libs: false + upload_binaries: true + env: + OS_NAME: "ubuntu-jammy" + name: "ubuntu-jammy-${{matrix.use_shared_libs == true && 'dynamic' || 'static'}}-linked-bins" continue-on-error: true runs-on: "ubuntu-latest" steps: @@ -197,13 +208,129 @@ jobs: run: "chown $(id -u):$(id -g) -R ." shell: "bash" - - uses: "./.github/actions/clp-core-build" + - uses: "./.github/actions/run-on-image" + with: + image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}" + use_published_image: >- + ${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false' + || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}} + run_command: >- + task deps:core + && python3 /mnt/repo/components/core/tools/scripts/utils/build-and-run-unit-tests.py + ${{matrix.use_shared_libs == true && '--use-shared-libs' || ''}} + --source-dir /mnt/repo/components/core + --build-dir /mnt/repo/components/core/build + --num-jobs $(getconf _NPROCESSORS_ONLN) + + - if: "matrix.upload_binaries == true" + id: "copy_binaries" + run: |- + output_dir="/tmp/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" + echo "output_dir=${output_dir}" >> "$GITHUB_OUTPUT" + + mkdir -p "${output_dir}" + cd "$GITHUB_WORKSPACE/components/core/build" + tar cfvv "${output_dir}/clp.tar" clg clp clp-s glt make-dictionaries-readable + shell: "bash" + + - if: "matrix.upload_binaries == true" + uses: "actions/upload-artifact@v4" + with: + name: "${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" + path: "${{steps.copy_binaries.outputs.output_dir}}" + retention-days: 1 + + ubuntu-jammy-binaries-image: + # Run if the ancestor jobs were successful/skipped and building clp was successful. + if: "!cancelled() && !failure() && needs.ubuntu-jammy-binaries.result == 'success'" + needs: "ubuntu-jammy-binaries" + runs-on: "ubuntu-latest" + env: + OS_NAME: "ubuntu-jammy" + TMP_OUTPUT_DIR: "/tmp" + steps: + - uses: "actions/checkout@v4" + with: + submodules: "recursive" + + - name: "Work around actions/runner-images/issues/6775" + run: "chown $(id -u):$(id -g) -R ." + shell: "bash" + + - uses: "actions/download-artifact@v4" + with: + name: "${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" + path: "${{env.TMP_OUTPUT_DIR}}/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" + + - name: "Untar binaries" + working-directory: >- + ${{env.TMP_OUTPUT_DIR}}/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}} + run: |- + tar xf clp.tar + rm clp.tar + + - uses: "docker/login-action@v3" + with: + registry: "ghcr.io" + username: "${{github.actor}}" + password: "${{secrets.GITHUB_TOKEN}}" + + - name: "Sanitize the repo's name" + id: "sanitize_repo_name" + run: |- + # Docker doesn't support repository names with uppercase characters, so we convert to + # lowercase here. + lowercase_repo=$(echo '${{github.repository}}' | tr '[:upper:]' '[:lower:]') + echo "repository=${lowercase_repo}" >> "$GITHUB_OUTPUT" + shell: "bash" + + - id: "core_image_meta" + uses: "docker/metadata-action@v5" + with: + images: >- + ghcr.io/${{steps.sanitize_repo_name.outputs.repository}}/clp-core-x86-${{env.OS_NAME}} + tags: "type=raw,value=${{github.ref_name}}" + + # Only publish the image if this workflow was triggered by a push to `main`. + # NOTE: We run the rest of the job to test that the binaries were uploaded correctly. + - if: "github.event_name == 'push' && github.ref == 'refs/heads/main'" + uses: "docker/build-push-action@v5" + with: + context: "${{env.TMP_OUTPUT_DIR}}/${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}" + file: "components/core/tools/docker-images/clp-core-${{env.OS_NAME}}/Dockerfile" + push: true + tags: "${{steps.core_image_meta.outputs.tags}}" + labels: "${{steps.core_image_meta.outputs.labels}}" + + ubuntu-jammy-lint: + # Run if the ancestor jobs succeeded OR they were skipped and clp was changed. + if: >- + success() + || (!cancelled() && !failure() && needs.filter-relevant-changes.outputs.clp_changed == 'true') + needs: + - "filter-relevant-changes" + - "ubuntu-jammy-deps-image" + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v4" + with: + # Fetch history so that the `clang-tidy-diff` task can compare against the main branch. + fetch-depth: 0 + submodules: "recursive" + + - name: "Work around actions/runner-images/issues/6775" + run: "chown $(id -u):$(id -g) -R ." + shell: "bash" + + - uses: "./.github/actions/run-on-image" env: OS_NAME: "ubuntu-jammy" with: image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}" - use_shared_libs: "${{matrix.use_shared_libs}}" use_published_image: >- ${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}} - upload_binaries: "false" + # TODO: When enough files are passing clang-tidy, switch to a full pass on schedule only. + # run_command: >- + # task lint:check-cpp-${{(github.event_name == 'schedule') && 'full' || 'diff'}} + run_command: "task lint:check-cpp-full" diff --git a/.github/workflows/clp-execution-image-build.yaml b/.github/workflows/clp-execution-image-build.yaml index 058e23d5f6..75e872d44e 100644 --- a/.github/workflows/clp-execution-image-build.yaml +++ b/.github/workflows/clp-execution-image-build.yaml @@ -25,7 +25,6 @@ jobs: filter-relevant-changes: runs-on: "ubuntu-latest" outputs: - ubuntu_focal_image_changed: "${{steps.filter.outputs.ubuntu_focal_image}}" ubuntu_jammy_image_changed: "${{steps.filter.outputs.ubuntu_jammy_image}}" steps: - uses: "actions/checkout@v4" @@ -42,36 +41,11 @@ jobs: with: base: "main" filters: | - ubuntu_focal_image: - - ".github/actions/clp-execution-image-build/action.yaml" - - ".github/workflows/clp-execution-image-build.yaml" - - "tools/docker-images/clp-execution-base-ubuntu-focal/**/*" ubuntu_jammy_image: - ".github/actions/clp-execution-image-build/action.yaml" - ".github/workflows/clp-execution-image-build.yaml" - "tools/docker-images/clp-execution-base-ubuntu-jammy/**/*" - ubuntu_focal_execution_image: - if: "'true' == needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed" - needs: "filter-relevant-changes" - runs-on: "ubuntu-latest" - steps: - - uses: "actions/checkout@v4" - with: - submodules: "recursive" - - - name: "Workaround actions/runner-images/issues/6775" - shell: "bash" - run: "chown $(id -u):$(id -g) -R ." - - - uses: "./.github/actions/clp-execution-image-build" - with: - image_registry: "ghcr.io" - image_registry_username: "${{github.actor}}" - image_registry_password: "${{secrets.GITHUB_TOKEN}}" - platform_id: "ubuntu" - platform_version_id: "focal" - ubuntu_jammy_execution_image: if: "'true' == needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed" needs: "filter-relevant-changes" diff --git a/.github/workflows/clp-lint.yaml b/.github/workflows/clp-lint.yaml index bbe485c5dd..b29a40e3e3 100644 --- a/.github/workflows/clp-lint.yaml +++ b/.github/workflows/clp-lint.yaml @@ -38,4 +38,4 @@ jobs: - name: "Run lint task" shell: "bash" - run: "task lint:check" + run: "task lint:check-no-cpp" diff --git a/components/core/tools/scripts/utils/build-and-run-unit-tests.py b/components/core/tools/scripts/utils/build-and-run-unit-tests.py index 3f52ff7dbf..7c4b136171 100644 --- a/components/core/tools/scripts/utils/build-and-run-unit-tests.py +++ b/components/core/tools/scripts/utils/build-and-run-unit-tests.py @@ -1,6 +1,5 @@ import argparse import logging -import os import subprocess import sys from pathlib import Path @@ -32,7 +31,7 @@ def _config_cmake_project(src_dir: Path, build_dir: Path, use_shared_libs: bool) ] if use_shared_libs: cmd.append("-DCLP_USE_STATIC_LIBS=OFF") - subprocess.run(cmd, check=True, env=os.environ) + subprocess.run(cmd, check=True) def _build_project(build_dir: Path, num_jobs: Optional[int]): @@ -49,7 +48,7 @@ def _build_project(build_dir: Path, num_jobs: Optional[int]): ] if num_jobs is not None: cmd.append(str(num_jobs)) - subprocess.run(cmd, check=True, env=os.environ) + subprocess.run(cmd, check=True) def _run_unit_tests(build_dir: Path, test_spec: Optional[str]): @@ -63,7 +62,7 @@ def _run_unit_tests(build_dir: Path, test_spec: Optional[str]): ] if test_spec is not None: cmd.append(test_spec) - subprocess.run(cmd, cwd=build_dir, check=True, env=os.environ) + subprocess.run(cmd, cwd=build_dir, check=True) def main(argv: List[str]) -> int: From 86670f4d707baa7c73055e0e937e9b4f8e79c1fb Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Wed, 12 Mar 2025 14:05:19 -0400 Subject: [PATCH 19/26] Bump ystdlib-cpp version --- components/core/submodules/ystdlib-cpp | 2 +- deps-tasks.yml | 4 ++-- tools/yscope-dev-utils | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/core/submodules/ystdlib-cpp b/components/core/submodules/ystdlib-cpp index 95d89d1483..8c30cec61e 160000 --- a/components/core/submodules/ystdlib-cpp +++ b/components/core/submodules/ystdlib-cpp @@ -1 +1 @@ -Subproject commit 95d89d148312c7c447f4164766ad35dd7996b1cc +Subproject commit 8c30cec61e194b0bbe3d50b7a5ebb57756e748a5 diff --git a/deps-tasks.yml b/deps-tasks.yml index 582ed63b04..fa59e64fe4 100644 --- a/deps-tasks.yml +++ b/deps-tasks.yml @@ -489,8 +489,8 @@ tasks: vars: DEST: "{{.DEST}}" FLAGS: "--extract" - SRC_NAME: "ystdlib-cpp-95d89d148312c7c447f4164766ad35dd7996b1cc" - SRC_URL: "https://github.com/y-scope/ystdlib-cpp/archive/95d89d1.zip" + SRC_NAME: "ystdlib-cpp-8c30cec" + SRC_URL: "https://github.com/y-scope/ystdlib-cpp/archive/8c30cec.zip" # This command must be last - task: ":utils:checksum:compute" vars: diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index e6b3f0c917..c5b2032469 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit e6b3f0c917867a49cfb712994e51e1a2b74ed561 +Subproject commit c5b2032469ca8e583cf53cf64d233ead9a5be579 From 5dee1f234dfe6e273a381027c61e6d904ab17a73 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Wed, 12 Mar 2025 14:19:39 -0400 Subject: [PATCH 20/26] Update docs --- docs/src/dev-guide/components-core/index.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/src/dev-guide/components-core/index.md b/docs/src/dev-guide/components-core/index.md index 8106a47f77..7053879ada 100644 --- a/docs/src/dev-guide/components-core/index.md +++ b/docs/src/dev-guide/components-core/index.md @@ -36,12 +36,15 @@ This will download: * [ANTLR](https://www.antlr.org) (v4.13.1) * [Catch2](https://github.com/catchorg/Catch2.git) (v2.13.7) * [date](https://github.com/HowardHinnant/date.git) (v3.0.1) -* [json](https://github.com/nlohmann/json.git) (v3.10.4) -* [log-surgeon](https://github.com/y-scope/log-surgeon) (895f464) +* [json](https://github.com/nlohmann/json.git) (v3.11.3) +* [log-surgeon](https://github.com/y-scope/log-surgeon.git) (895f464) * [outcome](https://github.com/ned14/outcome) (v2.2.9) * [simdjson](https://github.com/simdjson/simdjson) (v3.6.3) * [SQLite3](https://www.sqlite.org/download.html) (v3.36.0) +* [uftcpp](https://github.com/nemtrif/utfcpp.git) (v4.0.6) +* [yscope-log-viewer](https://github.com/y-scope/yscope-log-viewer.git) (969ff35) * [yaml-cpp](https://github.com/jbeder/yaml-cpp.git) (v0.7.0) +* [ystdlib-cpp](https://github.com/y-scope/ystdlib-cpp.git) (8c30cec) ### Environment From fbb896e008a832cad91ce2dd99c4b0354f5650c5 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Fri, 14 Mar 2025 14:40:19 -0400 Subject: [PATCH 21/26] Upgrade dev utils --- tools/yscope-dev-utils | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index c5b2032469..e6b3f0c917 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit c5b2032469ca8e583cf53cf64d233ead9a5be579 +Subproject commit e6b3f0c917867a49cfb712994e51e1a2b74ed561 From 989afcb38a3f62c896596aff37b91ef9c804e7bb Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Fri, 14 Mar 2025 14:41:41 -0400 Subject: [PATCH 22/26] Change option to set to prevent overriding --- components/core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 68898a72d9..38ba22edfe 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -225,7 +225,7 @@ find_package(Threads REQUIRED) add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) # Add ystdlib-cpp -option(YSTDLIB_CPP_BUILD_TESTING "" OFF) +set(YSTDLIB_CPP_BUILD_TESTING OFF) add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) # Find and setup ZStd Library From d2c68039f6c72a5a7e7756f0d49352682a659cd1 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Fri, 14 Mar 2025 14:43:09 -0400 Subject: [PATCH 23/26] Undo source changes --- .../core/src/clp/error_handling/ErrorCode.hpp | 148 +++++++++++++++++ .../src/clp/ffi/ir_stream/IrErrorCode.cpp | 5 +- .../src/clp/ffi/ir_stream/IrErrorCode.hpp | 6 +- components/core/tests/test-error_handling.cpp | 156 ++++++++++++++++++ 4 files changed, 308 insertions(+), 7 deletions(-) create mode 100644 components/core/src/clp/error_handling/ErrorCode.hpp create mode 100644 components/core/tests/test-error_handling.cpp diff --git a/components/core/src/clp/error_handling/ErrorCode.hpp b/components/core/src/clp/error_handling/ErrorCode.hpp new file mode 100644 index 0000000000..230fa8cb16 --- /dev/null +++ b/components/core/src/clp/error_handling/ErrorCode.hpp @@ -0,0 +1,148 @@ +#ifndef CLP_ERROR_HANDLING_ERRORCODE_HPP +#define CLP_ERROR_HANDLING_ERRORCODE_HPP + +#include +#include +#include +#include + +namespace clp::error_handling { +/** + * Concept that defines a template parameter of an integer-based error code enumeration. + * @tparam Type + */ +template +concept ErrorCodeEnumType = std::is_enum_v && requires(Type type) { + { + static_cast>(type) + } -> std::convertible_to; +}; + +/** + * Template that defines a `std::error_category` of the given set of error code enumeration. + * @tparam ErrorCodeEnum + */ +template +class ErrorCategory : public std::error_category { +public: + // Methods implementing `std::error_category` + /** + * Gets the error category name. + * Note: A specialization must be explicitly implemented for each valid `ErrorCodeEnum`. + * @return The name of the error category. + */ + [[nodiscard]] auto name() const noexcept -> char const* override; + + /** + * Gets the descriptive message associated with the given error. + * @param error_num + * @return The descriptive message for the error. + */ + [[nodiscard]] auto message(int error_num) const -> std::string override { + return message(static_cast(error_num)); + } + + /** + * @param error_num + * @param condition + * @return Whether the error condition of the given error matches the given condition. + */ + [[nodiscard]] auto + equivalent(int error_num, std::error_condition const& condition) const noexcept + -> bool override { + return equivalent(static_cast(error_num), condition); + } + + // Methods + /** + * Gets the descriptive message associated with the given error. + * Note: A specialization must be explicitly implemented for each valid `ErrorCodeEnum`. + * @param error_enum. + * @return The descriptive message for the error. + */ + [[nodiscard]] auto message(ErrorCodeEnum error_enum) const -> std::string; + + /** + * Note: A specialization can be implemented to create error enum to error condition mappings. + * @param error_num + * @param condition + * @return Whether the error condition of the given error matches the given condition. + */ + [[nodiscard]] auto + equivalent(ErrorCodeEnum error_enum, std::error_condition const& condition) const noexcept + -> bool; +}; + +/** + * Template class that defines an error code. An error code is represented by a error enum value and + * the associated error category. This template class is designed to be `std::error_code` + * compatible, meaning that every instance of this class can be used to construct a corresponded + * `std::error_code` instance, or compare with a `std::error_code` instance to inspect a specific + * error. + * @tparam ErrorCodeEnum + */ +template +class ErrorCode { +public: + // Constructor + ErrorCode(ErrorCodeEnum error) : m_error{error} {} + + /** + * @return The underlying error code enum. + */ + [[nodiscard]] auto get_error() const -> ErrorCodeEnum { return m_error; } + + /** + * @return The error code as an error number. + */ + [[nodiscard]] auto get_error_num() const -> int { return static_cast(m_error); } + + /** + * @return The reference to the singleton of the corresponded error category. + */ + [[nodiscard]] static constexpr auto get_category() -> ErrorCategory const& { + return cCategory; + } + +private: + static inline ErrorCategory const cCategory; + + ErrorCodeEnum m_error; +}; + +/** + * @tparam ErrorCodeEnum + * @param error + * @return Constructed `std::error_code` from the given `ErrorCode` instance. + */ +template +[[nodiscard]] auto make_error_code(ErrorCode error) -> std::error_code; + +template +auto ErrorCategory::equivalent( + ErrorCodeEnum error_enum, + std::error_condition const& condition +) const noexcept -> bool { + return std::error_category::default_error_condition(static_cast(error_enum)) == condition; +} + +template +auto make_error_code(ErrorCode error) -> std::error_code { + return {error.get_error_num(), ErrorCode::get_category()}; +} +} // namespace clp::error_handling + +/** + * The macro to create a specialization of `std::is_error_code_enum` for a given type T. Only types + * that are marked with this macro will be considered as a valid CLP error code enum, and thus used + * to specialize `ErrorCode` and `ErrorCategory` templates. + */ +// NOLINTBEGIN(bugprone-macro-parentheses, cppcoreguidelines-macro-usage) +#define CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(T) \ + template <> \ + struct std::is_error_code_enum> : std::true_type { \ + static_assert(std::is_enum_v); \ + }; +// NOLINTEND(bugprone-macro-parentheses, cppcoreguidelines-macro-usage) + +#endif // CLP_ERROR_HANDLING_ERRORCODE_HPP diff --git a/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp b/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp index dbca3bd61a..f9a00ca1eb 100644 --- a/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp +++ b/components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp @@ -2,10 +2,7 @@ #include -#include - -using IrErrorCategory - = ystdlib::error_handling::ErrorCategory; +using IrErrorCategory = clp::error_handling::ErrorCategory; using clp::ffi::ir_stream::IrErrorCodeEnum; template <> diff --git a/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp b/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp index e384f369f1..8eaad4e16b 100644 --- a/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp +++ b/components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp @@ -3,7 +3,7 @@ #include -#include +#include "../../error_handling/ErrorCode.hpp" namespace clp::ffi::ir_stream { /** @@ -16,9 +16,9 @@ enum class IrErrorCodeEnum : uint8_t { IncompleteStream, }; -using IrErrorCode = ystdlib::error_handling::ErrorCode; +using IrErrorCode = clp::error_handling::ErrorCode; } // namespace clp::ffi::ir_stream -YSTDLIB_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(clp::ffi::ir_stream::IrErrorCodeEnum); +CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(clp::ffi::ir_stream::IrErrorCodeEnum); #endif // CLP_IRERRORCODE_HPP diff --git a/components/core/tests/test-error_handling.cpp b/components/core/tests/test-error_handling.cpp new file mode 100644 index 0000000000..44327c8332 --- /dev/null +++ b/components/core/tests/test-error_handling.cpp @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../src/clp/error_handling/ErrorCode.hpp" +#include "../src/clp/ffi/ir_stream/IrErrorCode.hpp" + +using clp::error_handling::ErrorCategory; +using clp::error_handling::ErrorCode; +using std::string; +using std::string_view; + +namespace { +enum class AlwaysSuccessErrorCodeEnum : uint8_t { + Success = 0 +}; + +enum class BinaryErrorCodeEnum : uint8_t { + Success = 0, + Failure +}; + +using AlwaysSuccessErrorCode = ErrorCode; +using AlwaysSuccessErrorCategory = ErrorCategory; +using BinaryErrorCode = ErrorCode; +using BinaryErrorCategory = ErrorCategory; + +constexpr string_view cAlwaysSuccessErrorCategoryName{"Always Success Error Code"}; +constexpr string_view cBinaryTestErrorCategoryName{"Binary Error Code"}; +constexpr string_view cSuccessErrorMsg{"Success"}; +constexpr string_view cFailureErrorMsg{"Failure"}; +constexpr string_view cUnrecognizedErrorCode{"Unrecognized Error Code"}; +constexpr std::array cFailureConditions{std::errc::not_connected, std::errc::timed_out}; +constexpr std::array cNoneFailureConditions{std::errc::broken_pipe, std::errc::address_in_use}; +} // namespace + +CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(AlwaysSuccessErrorCodeEnum); +CLP_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(BinaryErrorCodeEnum); + +template <> +auto AlwaysSuccessErrorCategory::name() const noexcept -> char const* { + return cAlwaysSuccessErrorCategoryName.data(); +} + +template <> +auto AlwaysSuccessErrorCategory::message(AlwaysSuccessErrorCodeEnum error_enum) const -> string { + switch (error_enum) { + case AlwaysSuccessErrorCodeEnum::Success: + return string{cSuccessErrorMsg}; + default: + return string{cUnrecognizedErrorCode}; + } +} + +template <> +auto BinaryErrorCategory::name() const noexcept -> char const* { + return cBinaryTestErrorCategoryName.data(); +} + +template <> +auto BinaryErrorCategory::message(BinaryErrorCodeEnum error_enum) const -> string { + switch (error_enum) { + case BinaryErrorCodeEnum::Success: + return string{cSuccessErrorMsg}; + case BinaryErrorCodeEnum::Failure: + return string{cFailureErrorMsg}; + default: + return string{cUnrecognizedErrorCode}; + } +} + +template <> +auto BinaryErrorCategory::equivalent( + BinaryErrorCodeEnum error_enum, + std::error_condition const& condition +) const noexcept -> bool { + switch (error_enum) { + case BinaryErrorCodeEnum::Failure: + return std::any_of( + cFailureConditions.cbegin(), + cFailureConditions.cend(), + [&](auto failure_condition) -> bool { return condition == failure_condition; } + ); + default: + return false; + } +} + +TEST_CASE("test_error_code_implementation", "[error_handling][ErrorCode]") { + // Test error codes within the same error category + BinaryErrorCode const success{BinaryErrorCodeEnum::Success}; + std::error_code const success_error_code{success}; + REQUIRE((success == success_error_code)); + REQUIRE((cSuccessErrorMsg == success_error_code.message())); + REQUIRE((BinaryErrorCode::get_category() == success_error_code.category())); + REQUIRE((cBinaryTestErrorCategoryName == success_error_code.category().name())); + + BinaryErrorCode const failure{BinaryErrorCodeEnum::Failure}; + std::error_code const failure_error_code{failure}; + REQUIRE((failure == failure_error_code)); + REQUIRE((cFailureErrorMsg == failure_error_code.message())); + REQUIRE((BinaryErrorCode::get_category() == failure_error_code.category())); + REQUIRE((cBinaryTestErrorCategoryName == failure_error_code.category().name())); + std::for_each( + cFailureConditions.cbegin(), + cFailureConditions.cend(), + [&](auto failure_condition) { REQUIRE((failure_error_code == failure_condition)); } + ); + std::for_each( + cNoneFailureConditions.cbegin(), + cNoneFailureConditions.cend(), + [&](auto none_failure_condition) { + REQUIRE((failure_error_code != none_failure_condition)); + } + ); + + REQUIRE((success_error_code != failure_error_code)); + REQUIRE((success_error_code.category() == failure_error_code.category())); + + AlwaysSuccessErrorCode const always_success{AlwaysSuccessErrorCodeEnum::Success}; + std::error_code const always_success_error_code{always_success}; + REQUIRE((always_success_error_code == always_success)); + REQUIRE((cSuccessErrorMsg == always_success_error_code.message())); + REQUIRE((AlwaysSuccessErrorCode::get_category() == always_success_error_code.category())); + REQUIRE((cAlwaysSuccessErrorCategoryName == always_success_error_code.category().name())); + + // Compare error codes from different error category + // Error codes that have the same value or message won't be the same with each other if they are + // from different error categories. + REQUIRE((success_error_code.value() == always_success_error_code.value())); + REQUIRE((success_error_code.message() == always_success_error_code.message())); + REQUIRE((success_error_code.category() != always_success_error_code.category())); + REQUIRE((success_error_code != always_success_error_code)); + REQUIRE((AlwaysSuccessErrorCode{AlwaysSuccessErrorCodeEnum::Success} != success_error_code)); + REQUIRE((BinaryErrorCode{BinaryErrorCodeEnum::Success} != always_success_error_code)); +} + +TEST_CASE("test_ir_error_code", "[error_handling][ErrorCode][IrErrorCode]") { + using clp::ffi::ir_stream::IrErrorCode; + using clp::ffi::ir_stream::IrErrorCodeEnum; + + auto assert_error_code_matches_error_code_enum = [](IrErrorCodeEnum error_code_enum) -> bool { + std::error_code const error_code{IrErrorCode{error_code_enum}}; + return error_code == IrErrorCode{error_code_enum}; + }; + + REQUIRE(assert_error_code_matches_error_code_enum(IrErrorCodeEnum::DecodingMethodFailure)); + REQUIRE(assert_error_code_matches_error_code_enum(IrErrorCodeEnum::EndOfStream)); + REQUIRE(assert_error_code_matches_error_code_enum(IrErrorCodeEnum::IncompleteStream)); +} From 9927121b705f008b5dc9bad8b6425335c5f8eb39 Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Fri, 14 Mar 2025 14:44:25 -0400 Subject: [PATCH 24/26] Undo cmakelist change --- components/core/CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 38ba22edfe..ae3fa9c21f 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -224,10 +224,6 @@ find_package(Threads REQUIRED) # Add yaml-cpp add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) -# Add ystdlib-cpp -set(YSTDLIB_CPP_BUILD_TESTING OFF) -add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) - # Find and setup ZStd Library if(CLP_USE_STATIC_LIBS) set(ZStd_USE_STATIC_LIBS ON) @@ -448,6 +444,7 @@ set(SOURCE_FILES_unitTest src/clp/DictionaryEntry.hpp src/clp/DictionaryReader.hpp src/clp/DictionaryWriter.hpp + src/clp/error_handling/ErrorCode.hpp src/clp/EncodedVariableInterpreter.cpp src/clp/EncodedVariableInterpreter.hpp src/clp/ErrorCode.hpp @@ -643,6 +640,7 @@ set(SOURCE_FILES_unitTest tests/test-clp_s-search.cpp tests/test-EncodedVariableInterpreter.cpp tests/test-encoding_methods.cpp + tests/test-error_handling.cpp tests/test-ffi_IrUnitHandlerInterface.cpp tests/test-ffi_KeyValuePairLogEvent.cpp tests/test-ffi_SchemaTree.cpp @@ -699,7 +697,6 @@ target_link_libraries(unitTest clp::regex_utils clp::string_utils yaml-cpp::yaml-cpp - ystdlib::error_handling ${LIBLZMA_LIBRARIES} ZStd::ZStd ) From 631144b8a936eb9588be61c2df9401612db029ae Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Fri, 14 Mar 2025 15:03:36 -0400 Subject: [PATCH 25/26] Upgrade version --- components/core/CMakeLists.txt | 4 ++++ components/core/submodules/ystdlib-cpp | 2 +- deps-tasks.yml | 4 ++-- docs/src/dev-guide/components-core/index.md | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index ae3fa9c21f..2c3479afd8 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -224,6 +224,10 @@ find_package(Threads REQUIRED) # Add yaml-cpp add_subdirectory(submodules/yaml-cpp EXCLUDE_FROM_ALL) +# Add ystdlib-cpp +set(YSTDLIB_CPP_BUILD_TESTING OFF) +add_subdirectory(submodules/ystdlib-cpp EXCLUDE_FROM_ALL) + # Find and setup ZStd Library if(CLP_USE_STATIC_LIBS) set(ZStd_USE_STATIC_LIBS ON) diff --git a/components/core/submodules/ystdlib-cpp b/components/core/submodules/ystdlib-cpp index 8c30cec61e..d1b4ae0e6c 160000 --- a/components/core/submodules/ystdlib-cpp +++ b/components/core/submodules/ystdlib-cpp @@ -1 +1 @@ -Subproject commit 8c30cec61e194b0bbe3d50b7a5ebb57756e748a5 +Subproject commit d1b4ae0e6cc614dfbe6e4570719d41d9d4f93a3a diff --git a/deps-tasks.yml b/deps-tasks.yml index fa59e64fe4..2c1f052a4f 100644 --- a/deps-tasks.yml +++ b/deps-tasks.yml @@ -489,8 +489,8 @@ tasks: vars: DEST: "{{.DEST}}" FLAGS: "--extract" - SRC_NAME: "ystdlib-cpp-8c30cec" - SRC_URL: "https://github.com/y-scope/ystdlib-cpp/archive/8c30cec.zip" + SRC_NAME: "ystdlib-cpp-d1b4ae0" + SRC_URL: "https://github.com/y-scope/ystdlib-cpp/archive/d1b4ae0.zip" # This command must be last - task: ":utils:checksum:compute" vars: diff --git a/docs/src/dev-guide/components-core/index.md b/docs/src/dev-guide/components-core/index.md index 7053879ada..a801500e1f 100644 --- a/docs/src/dev-guide/components-core/index.md +++ b/docs/src/dev-guide/components-core/index.md @@ -44,7 +44,7 @@ This will download: * [uftcpp](https://github.com/nemtrif/utfcpp.git) (v4.0.6) * [yscope-log-viewer](https://github.com/y-scope/yscope-log-viewer.git) (969ff35) * [yaml-cpp](https://github.com/jbeder/yaml-cpp.git) (v0.7.0) -* [ystdlib-cpp](https://github.com/y-scope/ystdlib-cpp.git) (8c30cec) +* [ystdlib-cpp](https://github.com/y-scope/ystdlib-cpp.git) (d1b4ae0) ### Environment From e0e4ef64a4c8a40f741016e52638c584c1f557ce Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Sun, 16 Mar 2025 19:27:23 -0400 Subject: [PATCH 26/26] Remove extra changes --- docs/src/dev-guide/components-core/index.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/src/dev-guide/components-core/index.md b/docs/src/dev-guide/components-core/index.md index a801500e1f..f1face1c7b 100644 --- a/docs/src/dev-guide/components-core/index.md +++ b/docs/src/dev-guide/components-core/index.md @@ -36,13 +36,11 @@ This will download: * [ANTLR](https://www.antlr.org) (v4.13.1) * [Catch2](https://github.com/catchorg/Catch2.git) (v2.13.7) * [date](https://github.com/HowardHinnant/date.git) (v3.0.1) -* [json](https://github.com/nlohmann/json.git) (v3.11.3) -* [log-surgeon](https://github.com/y-scope/log-surgeon.git) (895f464) +* [json](https://github.com/nlohmann/json.git) (v3.10.4) +* [log-surgeon](https://github.com/y-scope/log-surgeon) (895f464) * [outcome](https://github.com/ned14/outcome) (v2.2.9) * [simdjson](https://github.com/simdjson/simdjson) (v3.6.3) * [SQLite3](https://www.sqlite.org/download.html) (v3.36.0) -* [uftcpp](https://github.com/nemtrif/utfcpp.git) (v4.0.6) -* [yscope-log-viewer](https://github.com/y-scope/yscope-log-viewer.git) (969ff35) * [yaml-cpp](https://github.com/jbeder/yaml-cpp.git) (v0.7.0) * [ystdlib-cpp](https://github.com/y-scope/ystdlib-cpp.git) (d1b4ae0)