diff --git a/MODULE.bazel b/MODULE.bazel index 9484cb6abbc1..2ce469cfe458 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -25,7 +25,6 @@ bazel_dep(name = "rules_shell", version = "0.10.0") bazel_dep(name = "bazel_skylib", version = "1.9.2") bazel_dep(name = "abseil-cpp", version = "20260817.0", repo_name = "absl") bazel_dep(name = "nlohmann_json", version = "3.12.0.bcr.2", repo_name = "json") -bazel_dep(name = "fmt", version = "12.2.0.bcr.1-codeql.1") bazel_dep(name = "rules_kotlin", version = "2.4.21-codeql.1") bazel_dep(name = "gazelle", version = "0.54.0") bazel_dep(name = "rules_dotnet") diff --git a/shared/cpp/BUILD.bazel b/shared/cpp/BUILD.bazel index f78c4ede92fa..69ac613daf2c 100644 --- a/shared/cpp/BUILD.bazel +++ b/shared/cpp/BUILD.bazel @@ -7,7 +7,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ "@absl//absl/strings", - "@fmt", "@json", ], ) diff --git a/shared/cpp/Diagnostics.cpp b/shared/cpp/Diagnostics.cpp index 7d2734c396cb..70c2c8c9a52f 100644 --- a/shared/cpp/Diagnostics.cpp +++ b/shared/cpp/Diagnostics.cpp @@ -1,7 +1,6 @@ #include "Diagnostics.h" -#include -#include +#include #include "absl/strings/str_join.h" #include "absl/strings/str_cat.h" @@ -41,7 +40,7 @@ nlohmann::json Diagnostic::json(const std::chrono::system_clock::time_point& tim }}, {"severity", severityToString(severity)}, {"markdownMessage", absl::StrCat(message, "\n\n", action)}, - {"timestamp", fmt::format("{:%FT%T%z}", timestamp)}, + {"timestamp", std::format("{:%FT%T%z}", timestamp)}, }; if (location) { ret["location"] = location->json(); diff --git a/shared/cpp/Diagnostics.h b/shared/cpp/Diagnostics.h index fd2ffc4322f6..42b397ce24e3 100644 --- a/shared/cpp/Diagnostics.h +++ b/shared/cpp/Diagnostics.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/swift/logging/BUILD.bazel b/swift/logging/BUILD.bazel index e72a7071d069..6b771ba5bf3d 100644 --- a/swift/logging/BUILD.bazel +++ b/swift/logging/BUILD.bazel @@ -9,7 +9,6 @@ cc_library( "//shared/cpp:extractor_shared", "@absl//absl/strings", "@binlog", - "@fmt", "@json", ], ) diff --git a/swift/logging/SwiftLogging.h b/swift/logging/SwiftLogging.h index 16275858203c..d9d48359a326 100644 --- a/swift/logging/SwiftLogging.h +++ b/swift/logging/SwiftLogging.h @@ -1,15 +1,16 @@ #pragma once #include +#include +#include #include #include #include +#include +#include +#include #include -#include -#include -#include - #include #include #include @@ -20,6 +21,31 @@ #include "swift/logging/SwiftDiagnostics.h" +namespace codeql::detail { + +template +const T& diagnosticFormatArg(const T& value) { + return value; +} + +// C++23 has no formatters for paths or error codes. +inline std::string diagnosticFormatArg(const std::filesystem::path& value) { + return value.string(); +} + +inline std::string diagnosticFormatArg(const std::error_code& value) { + return std::format("{}:{}", value.category().name(), value.value()); +} + +template +std::string formatDiagnostic( + std::format_string()))...> format, + const Args&... args) { + return std::format(format, diagnosticFormatArg(args)...); +} + +} // namespace codeql::detail + // Logging macros. These will call `logger()` to get a Logger instance, picking up any `logger` // defined in the current scope. Domain-specific loggers can be added or used by either: // * providing a class field called `logger` (as `Logger::operator()()` returns itself) @@ -52,7 +78,7 @@ // Emit errors with a specified SwiftDiagnostic object. These will be both logged and outputted as // JSON DB diagnostics. The format must be appliable to the following arguments both as binlog and -// as fmt::format formatting. +// as std::format formatting. // Beware that contrary to LOG_* macros, arguments right of the format will be evaluated twice. ID // is evaluated once though. #define DIAGNOSE_ERROR(ID, ...) DIAGNOSE_WITH_LEVEL(error, ID, __VA_ARGS__) @@ -63,8 +89,9 @@ do { \ auto _now = ::binlog::clockNow(); \ const ::codeql::Diagnostic& _id = ID; \ - ::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \ - fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \ + ::codeql::Log::diagnose( \ + _id, std::chrono::nanoseconds{_now}, \ + ::codeql::detail::formatDiagnostic(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \ LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \ _id.abbreviation() __VA_OPT__(, ) __VA_ARGS__); \ } while (false)