Update to newest spdlog and fmt (#309)
This commit is contained in:
parent
a277541354
commit
8716b8e992
libs
src
tests
benchmark
concurrent
manual
unit
@ -107,12 +107,13 @@ import_external_library(benchmark STATIC
|
||||
# Skip testing. The tests don't compile with Clang 8.
|
||||
CMAKE_ARGS -DBENCHMARK_ENABLE_TESTING=OFF)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# setup fmt format
|
||||
import_external_library(fmt STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fmt/${CMAKE_INSTALL_LIBDIR}/libfmt.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fmt/include
|
||||
# Skip testing.
|
||||
CMAKE_ARGS -DFMT_TEST=OFF)
|
||||
FetchContent_Declare(fmt
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fmt)
|
||||
|
||||
FetchContent_MakeAvailable(fmt)
|
||||
|
||||
# setup rapidcheck (it cannot be external, since it doesn't have install
|
||||
# target)
|
||||
@ -225,10 +226,11 @@ add_external_project(mgconsole
|
||||
add_custom_target(mgconsole DEPENDS mgconsole-proj)
|
||||
|
||||
# Setup spdlog
|
||||
import_external_library(spdlog STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spdlog/${CMAKE_INSTALL_LIBDIR}/libspdlog.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spdlog/include
|
||||
BUILD_COMMAND $(MAKE) spdlog)
|
||||
set(SPDLOG_FMT_EXTERNAL ON)
|
||||
FetchContent_Declare(spdlog
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spdlog)
|
||||
|
||||
FetchContent_MakeAvailable(spdlog)
|
||||
|
||||
include(jemalloc.cmake)
|
||||
|
||||
|
@ -178,7 +178,7 @@ cppitertools_ref="cb3635456bdb531121b82b4d2e3afc7ae1f56d47"
|
||||
repo_clone_try_double "${primary_urls[cppitertools]}" "${secondary_urls[cppitertools]}" "cppitertools" "$cppitertools_ref"
|
||||
|
||||
# fmt
|
||||
fmt_tag="7.1.3" # (2020-11-25)
|
||||
fmt_tag="8.0.1" # (2021-07-03)
|
||||
repo_clone_try_double "${primary_urls[fmt]}" "${secondary_urls[fmt]}" "fmt" "$fmt_tag" true
|
||||
|
||||
# rapidcheck
|
||||
@ -241,7 +241,7 @@ repo_clone_try_double "${primary_urls[pymgclient]}" "${secondary_urls[pymgclient
|
||||
mgconsole_tag="v1.1.0" # (2021-10-07)
|
||||
repo_clone_try_double "${primary_urls[mgconsole]}" "${secondary_urls[mgconsole]}" "mgconsole" "$mgconsole_tag" true
|
||||
|
||||
spdlog_tag="v1.8.2" # (2020-12-01)
|
||||
spdlog_tag="v1.9.2" # (2021-08-12)
|
||||
repo_clone_try_double "${primary_urls[spdlog]}" "${secondary_urls[spdlog]}" "spdlog" "$spdlog_tag" true
|
||||
|
||||
jemalloc_tag="ea6b3e973b477b8061e0076bb257dbd7f3faa756" # (2021-02-11)
|
||||
|
@ -37,7 +37,7 @@ set(mg_single_node_v2_sources
|
||||
)
|
||||
|
||||
set(mg_single_node_v2_libs stdc++fs Threads::Threads
|
||||
telemetry_lib mg-query mg-communication mg-memory mg-utils mg-auth)
|
||||
telemetry_lib mg-query mg-communication mg-memory mg-utils mg-auth mg-license mg-settings)
|
||||
if (MG_ENTERPRISE)
|
||||
# These are enterprise subsystems
|
||||
set(mg_single_node_v2_libs ${mg_single_node_v2_libs} mg-audit)
|
||||
|
@ -1,5 +1,5 @@
|
||||
set(audit_src_files log.cpp)
|
||||
|
||||
add_library(mg-audit STATIC ${audit_src_files})
|
||||
target_link_libraries(mg-audit json gflags fmt)
|
||||
target_link_libraries(mg-audit json gflags fmt::fmt)
|
||||
target_link_libraries(mg-audit mg-utils mg-storage-v2)
|
||||
|
@ -7,7 +7,7 @@ set(auth_src_files
|
||||
find_package(Seccomp REQUIRED)
|
||||
|
||||
add_library(mg-auth STATIC ${auth_src_files})
|
||||
target_link_libraries(mg-auth json libbcrypt gflags fmt)
|
||||
target_link_libraries(mg-auth json libbcrypt gflags fmt::fmt)
|
||||
target_link_libraries(mg-auth mg-utils mg-kvstore)
|
||||
|
||||
target_link_libraries(mg-auth ${Seccomp_LIBRARIES})
|
||||
|
@ -7,7 +7,7 @@ set(communication_src_files
|
||||
init.cpp)
|
||||
|
||||
add_library(mg-communication STATIC ${communication_src_files})
|
||||
target_link_libraries(mg-communication Threads::Threads mg-utils mg-io fmt gflags)
|
||||
target_link_libraries(mg-communication Threads::Threads mg-utils mg-io fmt::fmt gflags)
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
target_link_libraries(mg-communication ${OPENSSL_LIBRARIES})
|
||||
|
@ -5,4 +5,4 @@ set(io_src_files
|
||||
network/utils.cpp)
|
||||
|
||||
add_library(mg-io STATIC ${io_src_files})
|
||||
target_link_libraries(mg-io stdc++fs Threads::Threads fmt mg-utils)
|
||||
target_link_libraries(mg-io stdc++fs Threads::Threads fmt::fmt mg-utils)
|
||||
|
@ -46,7 +46,7 @@ add_library(mg-query STATIC ${mg_query_sources})
|
||||
add_dependencies(mg-query generate_lcp_query)
|
||||
target_include_directories(mg-query PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
||||
target_link_libraries(mg-query dl cppitertools Boost::headers)
|
||||
target_link_libraries(mg-query mg-integrations-pulsar mg-integrations-kafka mg-storage-v2 mg-utils mg-kvstore mg-memory)
|
||||
target_link_libraries(mg-query mg-integrations-pulsar mg-integrations-kafka mg-storage-v2 mg-license mg-utils mg-kvstore mg-memory)
|
||||
if("${MG_PYTHON_VERSION}" STREQUAL "")
|
||||
find_package(Python3 3.5 REQUIRED COMPONENTS Development)
|
||||
else()
|
||||
|
@ -4,5 +4,5 @@ set(requests_src_files
|
||||
find_package(CURL REQUIRED)
|
||||
|
||||
add_library(mg-requests STATIC ${requests_src_files})
|
||||
target_link_libraries(mg-requests spdlog fmt gflags json ${CURL_LIBRARIES})
|
||||
target_link_libraries(mg-requests mg-utils spdlog::spdlog fmt::fmt gflags json ${CURL_LIBRARIES})
|
||||
target_include_directories(mg-requests PRIVATE ${CURL_INCLUDE_DIRS})
|
||||
|
@ -4,5 +4,5 @@ set(rpc_src_files
|
||||
server.cpp)
|
||||
|
||||
add_library(mg-rpc STATIC ${rpc_src_files})
|
||||
target_link_libraries(mg-rpc Threads::Threads mg-communication mg-utils mg-io fmt gflags)
|
||||
target_link_libraries(mg-rpc Threads::Threads mg-communication mg-utils mg-io fmt::fmt gflags)
|
||||
target_link_libraries(mg-rpc mg-slk)
|
||||
|
@ -5,11 +5,9 @@ set(utils_src_files
|
||||
csv_parsing.cpp
|
||||
file.cpp
|
||||
file_locker.cpp
|
||||
license.cpp
|
||||
memory.cpp
|
||||
memory_tracker.cpp
|
||||
readable_size.cpp
|
||||
settings.cpp
|
||||
signals.cpp
|
||||
sysinfo/memory.cpp
|
||||
temporal.cpp
|
||||
@ -17,5 +15,20 @@ set(utils_src_files
|
||||
thread_pool.cpp
|
||||
uuid.cpp)
|
||||
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
add_library(mg-utils STATIC ${utils_src_files})
|
||||
target_link_libraries(mg-utils mg-kvstore mg-slk stdc++fs Threads::Threads spdlog fmt gflags uuid rt)
|
||||
target_link_libraries(mg-utils PUBLIC Boost::headers fmt::fmt spdlog::spdlog)
|
||||
target_link_libraries(mg-utils PRIVATE stdc++fs Threads::Threads gflags uuid rt)
|
||||
|
||||
set(settings_src_files
|
||||
settings.cpp)
|
||||
|
||||
add_library(mg-settings STATIC ${settings_src_files})
|
||||
target_link_libraries(mg-settings mg-kvstore mg-slk mg-utils)
|
||||
|
||||
set(license_src_files
|
||||
license.cpp)
|
||||
add_library(mg-license STATIC ${license_src_files})
|
||||
target_link_libraries(mg-license mg-settings mg-utils)
|
||||
|
||||
|
@ -45,7 +45,7 @@ std::optional<utils::pmr::string> Reader::GetNextLine(utils::MemoryResource *mem
|
||||
|
||||
Reader::ParsingResult Reader::ParseHeader() {
|
||||
// header must be the very first line in the file
|
||||
MG_ASSERT(line_count_ == 1, fmt::format("Invalid use of {}", __func__));
|
||||
MG_ASSERT(line_count_ == 1, "Invalid use of {}", __func__);
|
||||
return ParseRow(memory_);
|
||||
}
|
||||
|
||||
|
@ -38,28 +38,11 @@ namespace utils {
|
||||
*/
|
||||
class BasicException : public std::exception {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor (C strings).
|
||||
*
|
||||
* @param message C-style string error message.
|
||||
* The string contents are copied upon construction.
|
||||
* Hence, responsibility for deleting the `char*` lies
|
||||
* with the caller.
|
||||
*/
|
||||
explicit BasicException(const char *message) noexcept : msg_(message) {}
|
||||
|
||||
/**
|
||||
* @brief Constructor (C++ STL strings).
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
explicit BasicException(const std::string &message) noexcept : msg_(message) {}
|
||||
|
||||
/**
|
||||
* @brief Constructor (C++ STL string_view).
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
explicit BasicException(const std::string_view message) noexcept : msg_(message) {}
|
||||
|
||||
/**
|
||||
@ -69,20 +52,8 @@ class BasicException : public std::exception {
|
||||
* @param args Arguments for format string.
|
||||
*/
|
||||
template <class... Args>
|
||||
explicit BasicException(const std::string &format, Args &&...args) noexcept
|
||||
: BasicException(fmt::format(format, std::forward<Args>(args)...)) {}
|
||||
|
||||
/**
|
||||
* @brief Constructor with format string (C strings).
|
||||
*
|
||||
* @param format The error format message. The string contents are copied upon
|
||||
* construction. Hence, the responsibility for deleting `char*` lies with the
|
||||
* caller.
|
||||
* @param args Arguments for format string.
|
||||
*/
|
||||
template <class... Args>
|
||||
explicit BasicException(const char *format, Args &&...args) noexcept
|
||||
: BasicException(fmt::format(std::string(format), std::forward<Args>(args)...)) {}
|
||||
explicit BasicException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||
: msg_(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||
|
||||
/**
|
||||
* @brief Virtual destructor to allow for subclassing.
|
||||
@ -119,22 +90,12 @@ class BasicException : public std::exception {
|
||||
*/
|
||||
class StacktraceException : public std::exception {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor (C strings).
|
||||
*
|
||||
* @param message C-style string error message.
|
||||
* The string contents are copied upon construction.
|
||||
* Hence, responsibility for deleting the `char*` lies
|
||||
* with the caller.
|
||||
*/
|
||||
explicit StacktraceException(const char *message) noexcept : message_(message), stacktrace_(Stacktrace().dump()) {}
|
||||
|
||||
/**
|
||||
* @brief Constructor (C++ STL strings).
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
explicit StacktraceException(const std::string &message) noexcept
|
||||
explicit StacktraceException(const std::string_view message) noexcept
|
||||
: message_(message), stacktrace_(Stacktrace().dump()) {}
|
||||
|
||||
/**
|
||||
@ -144,20 +105,8 @@ class StacktraceException : public std::exception {
|
||||
* @param args Arguments for format string.
|
||||
*/
|
||||
template <class... Args>
|
||||
explicit StacktraceException(const std::string &format, Args &&...args) noexcept
|
||||
: StacktraceException(fmt::format(format, std::forward<Args>(args)...)) {}
|
||||
|
||||
/**
|
||||
* @brief Constructor with format string (C strings).
|
||||
*
|
||||
* @param format The error format message. The string contents are copied upon
|
||||
* construction. Hence, the responsibility for deleting `char*` lies with the
|
||||
* caller.
|
||||
* @param args Arguments for format string.
|
||||
*/
|
||||
template <class... Args>
|
||||
explicit StacktraceException(const char *format, Args &&...args) noexcept
|
||||
: StacktraceException(fmt::format(std::string(format), std::forward<Args>(args)...)) {}
|
||||
explicit StacktraceException(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||
: StacktraceException(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||
|
||||
/**
|
||||
* @brief Virtual destructor to allow for subclassing.
|
||||
@ -195,8 +144,8 @@ class NotYetImplemented final : public BasicException {
|
||||
explicit NotYetImplemented(const std::string &what) noexcept : BasicException("Not yet implemented: " + what) {}
|
||||
|
||||
template <class... Args>
|
||||
explicit NotYetImplemented(const std::string &format, Args &&...args) noexcept
|
||||
: NotYetImplemented(fmt::format(format, std::forward<Args>(args)...)) {}
|
||||
explicit NotYetImplemented(fmt::format_string<Args...> fmt, Args &&...args) noexcept
|
||||
: NotYetImplemented(fmt::format(fmt, std::forward<Args>(args)...)) {}
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
@ -22,31 +22,33 @@
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <spdlog/fmt/ostr.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <boost/preprocessor/comparison/equal.hpp>
|
||||
#include <boost/preprocessor/control/if.hpp>
|
||||
#include <boost/preprocessor/variadic/size.hpp>
|
||||
|
||||
namespace logging {
|
||||
|
||||
// TODO (antonio2368): Replace with std::source_location when it's supported by
|
||||
// compilers
|
||||
template <typename... Args>
|
||||
void AssertFailed(const char *file_name, int line_num, const char *expr, const Args &...msg_args) {
|
||||
std::optional<std::string> message;
|
||||
if constexpr (sizeof...(msg_args) > 0) {
|
||||
message.emplace(fmt::format(msg_args...));
|
||||
}
|
||||
|
||||
inline void AssertFailed(const char *file_name, int line_num, const char *expr, const std::string &message) {
|
||||
spdlog::critical(
|
||||
"\nAssertion failed in file {} at line {}."
|
||||
"\n\tExpression: '{}'"
|
||||
"{}",
|
||||
file_name, line_num, expr, message ? fmt::format("\n\tMessage: '{}'", *message) : "");
|
||||
file_name, line_num, expr, !message.empty() ? fmt::format("\n\tMessage: '{}'", message) : "");
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
#define GET_MESSAGE(...) \
|
||||
BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 0), "", fmt::format(__VA_ARGS__))
|
||||
|
||||
#define MG_ASSERT(expr, ...) \
|
||||
[[likely]] !!(expr) ? (void)0 : ::logging::AssertFailed(__FILE__, __LINE__, #expr, ##__VA_ARGS__)
|
||||
[[likely]] !!(expr) ? (void)0 : ::logging::AssertFailed(__FILE__, __LINE__, #expr, GET_MESSAGE(__VA_ARGS__))
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define DMG_ASSERT(expr, ...) MG_ASSERT(expr, __VA_ARGS__)
|
||||
|
@ -16,8 +16,9 @@
|
||||
namespace utils {
|
||||
|
||||
template <typename... Args>
|
||||
std::string MessageWithLink(const std::string_view format, Args &&...args) {
|
||||
return fmt::format(fmt::format("{} For more details, visit {{}}.", format), std::forward<Args>(args)...);
|
||||
std::string MessageWithLink(fmt::format_string<Args...> fmt, Args &&...args) {
|
||||
return fmt::format(fmt::runtime(fmt::format(fmt::runtime("{} For more details, visit {{}}."), fmt)),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
@ -69,7 +69,7 @@ class Timestamp final {
|
||||
}
|
||||
|
||||
const std::string ToString(const std::string &format = fiso8601) const {
|
||||
return fmt::format(format, Year(), Month(), Day(), Hour(), Min(), Sec(), Usec());
|
||||
return fmt::format(fmt::runtime(format), Year(), Month(), Day(), Hour(), Min(), Sec(), Usec());
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Timestamp &ts) { return stream << ts.ToIso8601(); }
|
||||
|
@ -11,7 +11,7 @@ function(add_benchmark test_cpp)
|
||||
# used to help create two targets of the same name even though CMake
|
||||
# requires unique logical target names
|
||||
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${exec_name})
|
||||
target_link_libraries(${target_name} benchmark)
|
||||
target_link_libraries(${target_name} benchmark gflags)
|
||||
# register test
|
||||
add_test(${target_name} ${exec_name})
|
||||
add_dependencies(memgraph__benchmark ${target_name})
|
||||
@ -53,7 +53,7 @@ add_benchmark(skip_list_vs_stl.cpp)
|
||||
target_link_libraries(${test_prefix}skip_list_vs_stl mg-utils)
|
||||
|
||||
add_benchmark(expansion.cpp ${CMAKE_SOURCE_DIR}/src/glue/communication.cpp)
|
||||
target_link_libraries(${test_prefix}expansion mg-query mg-communication)
|
||||
target_link_libraries(${test_prefix}expansion mg-query mg-communication mg-license)
|
||||
|
||||
add_benchmark(storage_v2_gc.cpp)
|
||||
target_link_libraries(${test_prefix}storage_v2_gc mg-storage-v2)
|
||||
|
@ -27,7 +27,7 @@ add_concurrent_test(network_session_leak.cpp)
|
||||
target_link_libraries(${test_prefix}network_session_leak mg-communication)
|
||||
|
||||
add_concurrent_test(stack.cpp)
|
||||
target_link_libraries(${test_prefix}stack mg-utils)
|
||||
target_link_libraries(${test_prefix}stack mg-utils gflags)
|
||||
|
||||
add_concurrent_test(skip_list_insert.cpp)
|
||||
target_link_libraries(${test_prefix}skip_list_insert mg-utils)
|
||||
|
@ -43,7 +43,7 @@ add_manual_test(expression_pretty_printer.cpp)
|
||||
target_link_libraries(${test_prefix}expression_pretty_printer mg-query)
|
||||
|
||||
add_manual_test(single_query.cpp ${CMAKE_SOURCE_DIR}/src/glue/communication.cpp)
|
||||
target_link_libraries(${test_prefix}single_query mg-query mg-communication)
|
||||
target_link_libraries(${test_prefix}single_query mg-query mg-communication mg-license)
|
||||
|
||||
add_manual_test(stripped_timing.cpp)
|
||||
target_link_libraries(${test_prefix}stripped_timing mg-query)
|
||||
|
@ -270,10 +270,10 @@ add_unit_test(utils_async_timer.cpp)
|
||||
target_link_libraries(${test_prefix}utils_async_timer mg-utils)
|
||||
|
||||
add_unit_test(utils_license.cpp)
|
||||
target_link_libraries(${test_prefix}utils_license mg-utils)
|
||||
target_link_libraries(${test_prefix}utils_license mg-utils mg-license)
|
||||
|
||||
add_unit_test(utils_settings.cpp)
|
||||
target_link_libraries(${test_prefix}utils_settings mg-utils)
|
||||
target_link_libraries(${test_prefix}utils_settings mg-utils mg-settings)
|
||||
|
||||
add_unit_test(utils_temporal utils_temporal.cpp)
|
||||
target_link_libraries(${test_prefix}utils_temporal mg-utils)
|
||||
@ -326,7 +326,7 @@ target_link_libraries(${test_prefix}storage_v2_isolation_level mg-storage-v2)
|
||||
|
||||
if (MG_ENTERPRISE)
|
||||
add_unit_test(auth.cpp)
|
||||
target_link_libraries(${test_prefix}auth mg-auth)
|
||||
target_link_libraries(${test_prefix}auth mg-auth mg-license)
|
||||
endif()
|
||||
|
||||
|
||||
|
@ -3476,7 +3476,7 @@ TEST_P(CypherMainVisitorTest, CreateTriggers) {
|
||||
TestInvalidQuery("CREATE TRIGGER trigger ON UPDTE AFTER COMMIT EXECUTE a", ast_generator);
|
||||
TestInvalidQuery("CREATE TRIGGER trigger ON UPDATE COMMIT EXECUTE a", ast_generator);
|
||||
|
||||
const auto *query_template = "CREATE TRIGGER trigger {} {} COMMIT EXECUTE {}";
|
||||
constexpr std::string_view query_template = "CREATE TRIGGER trigger {} {} COMMIT EXECUTE {}";
|
||||
|
||||
constexpr std::array events{std::pair{"", query::TriggerQuery::EventType::ANY},
|
||||
std::pair{"ON CREATE", query::TriggerQuery::EventType::CREATE},
|
||||
|
@ -434,7 +434,7 @@ TEST_F(InterpreterTest, Bfs) {
|
||||
TEST_F(InterpreterTest, ShortestPath) {
|
||||
const auto test_shortest_path = [this](const bool use_duration) {
|
||||
const auto get_weight = [use_duration](const auto value) {
|
||||
return fmt::format(use_duration ? "DURATION('PT{}S')" : "{}", value);
|
||||
return fmt::format(fmt::runtime(use_duration ? "DURATION('PT{}S')" : "{}"), value);
|
||||
};
|
||||
|
||||
Interpret(
|
||||
|
@ -234,7 +234,8 @@ TEST(TemporalTest, DateParsing) {
|
||||
TEST(TemporalTest, LocalTimeParsing) {
|
||||
for (const auto &[string, local_time_parameters] : parsing_test_local_time_extended) {
|
||||
ASSERT_EQ(utils::ParseLocalTimeParameters(string).first, local_time_parameters) << ToString(local_time_parameters);
|
||||
ASSERT_EQ(utils::ParseLocalTimeParameters(fmt::format("T{}", string)).first, local_time_parameters)
|
||||
const auto time_string = fmt::format("T{}", string);
|
||||
ASSERT_EQ(utils::ParseLocalTimeParameters(time_string).first, local_time_parameters)
|
||||
<< ToString(local_time_parameters);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user