prefer std::format over fmt
Use std::format or stdplus::print and eliminate the fmt dependency.
Change-Id: Ide14b682949914f09f749141196cdb210fe1239e
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/src/rde/external_storer_file.cpp b/src/rde/external_storer_file.cpp
index 7f4ac05..6a162ed 100644
--- a/src/rde/external_storer_file.cpp
+++ b/src/rde/external_storer_file.cpp
@@ -1,10 +1,10 @@
#include "rde/external_storer_file.hpp"
-#include <fmt/format.h>
-
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
+#include <stdplus/print.hpp>
+#include <format>
#include <fstream>
#include <string_view>
@@ -20,7 +20,8 @@
{
if (!std::filesystem::create_directories(path))
{
- fmt::print(stderr, "Failed to create a folder at {}\n", folderPath);
+ stdplus::print(stderr, "Failed to create a folder at {}\n",
+ folderPath);
return false;
}
}
@@ -40,7 +41,7 @@
std::ofstream output(path);
output << jsonPdr;
output.close();
- fmt::print(stderr, "Created: {}\n", path.string());
+ stdplus::print(stderr, "Created: {}\n", path.string());
return true;
}
@@ -61,7 +62,7 @@
}
catch (nlohmann::json::parse_error& e)
{
- fmt::print(stderr, "JSON parse error: \n{}\n", e.what());
+ stdplus::print(stderr, "JSON parse error: \n{}\n", e.what());
return false;
}
@@ -69,8 +70,8 @@
// output.
if (!jsonDecoded.contains("@odata.type"))
{
- fmt::print(stderr, "@odata.type field doesn't exist in:\n {}\n",
- jsonDecoded.dump(4));
+ stdplus::print(stderr, "@odata.type field doesn't exist in:\n {}\n",
+ jsonDecoded.dump(4));
return false;
}
@@ -112,13 +113,14 @@
// https://github.com/openbmc/bios-bmc-smm-error-logger/issues/1.
if (logServiceId.empty())
{
- fmt::print(stderr, "First need a LogService PDR with a new UUID.\n");
+ stdplus::print(stderr,
+ "First need a LogService PDR with a new UUID.\n");
return false;
}
std::string id = boost::uuids::to_string(randomGen());
std::string fullPath =
- fmt::format("{}/redfish/v1/Systems/system/LogServices/{}/Entries/{}",
+ std::format("{}/redfish/v1/Systems/system/LogServices/{}/Entries/{}",
rootPath, logServiceId, id);
// Populate the "Id" with the UUID we generated.
@@ -129,8 +131,9 @@
if (!fileHandler->createFile(fullPath, logEntry))
{
- fmt::print(stderr, "Failed to create a file for log entry path: {}\n",
- fullPath);
+ stdplus::print(stderr,
+ "Failed to create a file for log entry path: {}\n",
+ fullPath);
return false;
}
@@ -143,15 +146,15 @@
{
if (!logService.contains("@odata.id"))
{
- fmt::print(stderr, "@odata.id field doesn't exist in:\n {}\n",
- logService.dump(4));
+ stdplus::print(stderr, "@odata.id field doesn't exist in:\n {}\n",
+ logService.dump(4));
return false;
}
if (!logService.contains("Id"))
{
- fmt::print(stderr, "Id field doesn't exist in:\n {}\n",
- logService.dump(4));
+ stdplus::print(stderr, "Id field doesn't exist in:\n {}\n",
+ logService.dump(4));
return false;
}
@@ -159,8 +162,9 @@
if (!createFile(logService["@odata.id"].get<std::string>(), logService))
{
- fmt::print(stderr, "Failed to create LogService index file for:\n{}\n",
- logService.dump(4));
+ stdplus::print(stderr,
+ "Failed to create LogService index file for:\n{}\n",
+ logService.dump(4));
return false;
}
// ExternalStorer needs a .../Entries/index.json file with no data.
@@ -174,8 +178,8 @@
{
if (!jsonPdr.contains("@odata.id"))
{
- fmt::print(stderr, "@odata.id field doesn't exist in:\n {}\n",
- jsonPdr.dump(4));
+ stdplus::print(stderr, "@odata.id field doesn't exist in:\n {}\n",
+ jsonPdr.dump(4));
return false;
}
return createFile(jsonPdr["@odata.id"].get<std::string>(), jsonPdr);
diff --git a/src/rde/meson.build b/src/rde/meson.build
index 456c807..3e73226 100644
--- a/src/rde/meson.build
+++ b/src/rde/meson.build
@@ -1,10 +1,11 @@
rde_pre = declare_dependency(
include_directories: [rde_inc],
dependencies: [
- dependency('nlohmann_json', include_type: 'system'),
dependency('libbej'),
+ dependency('nlohmann_json', include_type: 'system'),
dependency('phosphor-dbus-interfaces'),
dependency('sdbusplus'),
+ dependency('stdplus'),
]
)
diff --git a/src/rde/rde_dictionary_manager.cpp b/src/rde/rde_dictionary_manager.cpp
index c3567fb..0904fad 100644
--- a/src/rde/rde_dictionary_manager.cpp
+++ b/src/rde/rde_dictionary_manager.cpp
@@ -1,6 +1,8 @@
#include "rde/rde_dictionary_manager.hpp"
-#include <fmt/format.h>
+#include <stdplus/print.hpp>
+
+#include <format>
namespace bios_bmc_smm_error_logger
{
@@ -36,7 +38,7 @@
auto itemIt = dictionaries.find(resourceId);
if (itemIt == dictionaries.end())
{
- fmt::print(stderr, "Resource ID {} not found.\n", resourceId);
+ stdplus::print(stderr, "Resource ID {} not found.\n", resourceId);
return false;
}
validateDictionaryEntry(*itemIt->second);
@@ -49,7 +51,7 @@
auto itemIt = dictionaries.find(resourceId);
if (itemIt == dictionaries.end())
{
- fmt::print(stderr, "Resource ID {} not found.\n", resourceId);
+ stdplus::print(stderr, "Resource ID {} not found.\n", resourceId);
return false;
}
// Since we are modifying an existing entry, invalidate the existing entry.
@@ -65,15 +67,15 @@
auto itemIt = dictionaries.find(resourceId);
if (itemIt == dictionaries.end())
{
- fmt::print(stderr, "Resource ID {} not found.\n", resourceId);
+ stdplus::print(stderr, "Resource ID {} not found.\n", resourceId);
return std::nullopt;
}
if (!itemIt->second->valid)
{
- fmt::print(stderr,
- "Requested an incomplete dictionary. Resource ID {}\n",
- resourceId);
+ stdplus::print(stderr,
+ "Requested an incomplete dictionary. Resource ID {}\n",
+ resourceId);
return std::nullopt;
}
return itemIt->second->data;
diff --git a/src/rde/rde_handler.cpp b/src/rde/rde_handler.cpp
index d020b63..fd8ed0a 100644
--- a/src/rde/rde_handler.cpp
+++ b/src/rde/rde_handler.cpp
@@ -1,7 +1,8 @@
#include "rde/rde_handler.hpp"
-#include <fmt/format.h>
+#include <stdplus/print.hpp>
+#include <format>
#include <iostream>
namespace bios_bmc_smm_error_logger
@@ -38,7 +39,7 @@
return operationInitRequest(rdeCommand);
}
- fmt::print(stderr, "Invalid command type\n");
+ stdplus::print(stderr, "Invalid command type\n");
return RdeDecodeStatus::RdeInvalidCommand;
}
@@ -61,29 +62,30 @@
if (header->operationType !=
static_cast<uint8_t>(RdeOperationInitType::RdeOpInitOperationUpdate))
{
- fmt::print(stderr, "Operation not supported\n");
+ stdplus::print(stderr, "Operation not supported\n");
return RdeDecodeStatus::RdeUnsupportedOperation;
}
// OperationInit payload overflows are not suported.
if (header->sendDataTransferHandle != 0)
{
- fmt::print(stderr, "Payload should fit in within the request\n");
+ stdplus::print(stderr, "Payload should fit in within the request\n");
return RdeDecodeStatus::RdePayloadOverflow;
}
auto schemaDictOrErr = dictionaryManager.getDictionary(header->resourceID);
if (!schemaDictOrErr)
{
- fmt::print(stderr, "Schema Dictionary not found for resourceId: {}\n",
- header->resourceID);
+ stdplus::print(stderr,
+ "Schema Dictionary not found for resourceId: {}\n",
+ header->resourceID);
return RdeDecodeStatus::RdeNoDictionary;
}
auto annotationDictOrErr = dictionaryManager.getAnnotationDictionary();
if (!annotationDictOrErr)
{
- fmt::print(stderr, "Annotation dictionary not found\n");
+ stdplus::print(stderr, "Annotation dictionary not found\n");
return RdeDecodeStatus::RdeNoDictionary;
}
@@ -105,14 +107,14 @@
header->requestPayloadLength)) !=
0)
{
- fmt::print(stderr, "BEJ decoding failed.\n");
+ stdplus::print(stderr, "BEJ decoding failed.\n");
return RdeDecodeStatus::RdeBejDecodingError;
}
// Post the output.
if (!exStorer->publishJson(decoder.getOutput()))
{
- fmt::print(stderr, "Failed to write to ExternalStorer.\n");
+ stdplus::print(stderr, "Failed to write to ExternalStorer.\n");
return RdeDecodeStatus::RdeExternalStorerError;
}
return RdeDecodeStatus::RdeOk;
@@ -152,8 +154,8 @@
ret = handleFlagStartAndEnd(rdeCommand, header, data, resourceId);
break;
default:
- fmt::print(stderr, "Invalid transfer flag: {}\n",
- header->transferFlag);
+ stdplus::print(stderr, "Invalid transfer flag: {}\n",
+ header->transferFlag);
ret = RdeDecodeStatus::RdeInvalidCommand;
}
@@ -203,8 +205,8 @@
if (finalChecksum() != checksum)
{
- fmt::print(stderr, "Checksum failed. Ex: {} Calculated: {}\n", checksum,
- finalChecksum());
+ stdplus::print(stderr, "Checksum failed. Ex: {} Calculated: {}\n",
+ checksum, finalChecksum());
dictionaryManager.invalidateDictionaries();
return RdeDecodeStatus::RdeInvalidChecksum;
}
@@ -231,7 +233,7 @@
{
if (flagState != RdeDictTransferFlagState::RdeStateStartRecvd)
{
- fmt::print(
+ stdplus::print(
stderr,
"Invalid dictionary packet order. Need start before middle.\n");
return RdeDecodeStatus::RdeInvalidPktOrder;
@@ -251,9 +253,9 @@
// dictionary.
if (!dictionaryManager.addDictionaryData(resourceId, dataS))
{
- fmt::print(stderr,
- "Failed to add dictionary data: ResourceId: {}\n",
- resourceId);
+ stdplus::print(stderr,
+ "Failed to add dictionary data: ResourceId: {}\n",
+ resourceId);
return RdeDecodeStatus::RdeDictionaryError;
}
}
@@ -269,7 +271,7 @@
{
if (flagState != RdeDictTransferFlagState::RdeStateStartRecvd)
{
- fmt::print(
+ stdplus::print(
stderr,
"Invalid dictionary packet order. Need start before middle.\n");
return RdeDecodeStatus::RdeInvalidPktOrder;
@@ -288,9 +290,9 @@
{
if (!dictionaryManager.addDictionaryData(resourceId, dataS))
{
- fmt::print(stderr,
- "Failed to add dictionary data: ResourceId: {}\n",
- resourceId);
+ stdplus::print(stderr,
+ "Failed to add dictionary data: ResourceId: {}\n",
+ resourceId);
return RdeDecodeStatus::RdeDictionaryError;
}
}