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/include/dbus/file_notifier.hpp b/include/dbus/file_notifier.hpp
index 83c92f9..da37158 100644
--- a/include/dbus/file_notifier.hpp
+++ b/include/dbus/file_notifier.hpp
@@ -1,10 +1,9 @@
#pragma once
-#include <fmt/format.h>
-
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Common/FilePath/server.hpp>
+#include <format>
#include <string>
namespace bios_bmc_smm_error_logger
@@ -47,7 +46,7 @@
*/
std::string generatePath(uint64_t entry)
{
- return fmt::format("{}/entry{}", cperBasePath, entry);
+ return std::format("{}/entry{}", cperBasePath, entry);
}
};
diff --git a/src/buffer.cpp b/src/buffer.cpp
index dad8278..c6cec94 100644
--- a/src/buffer.cpp
+++ b/src/buffer.cpp
@@ -4,8 +4,6 @@
#include "pci_handler.hpp"
-#include <fmt/format.h>
-
#include <boost/endian/arithmetic.hpp>
#include <boost/endian/conversion.hpp>
@@ -13,6 +11,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
+#include <format>
#include <memory>
#include <numeric>
#include <span>
@@ -31,7 +30,7 @@
const size_t memoryRegionSize = dataInterface->getMemoryRegionSize();
if (queueSize > memoryRegionSize)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[initialize] Proposed queue size '{}' is bigger than the "
"BMC's allocated MMIO region of '{}'",
queueSize, memoryRegionSize));
@@ -43,7 +42,7 @@
if (byteWritten != queueSize)
{
throw std::runtime_error(
- fmt::format("[initialize] Only erased '{}'", byteWritten));
+ std::format("[initialize] Only erased '{}'", byteWritten));
}
// Create an initial buffer header and write to it
@@ -68,7 +67,7 @@
initializationHeaderSize));
if (byteWritten != initializationHeaderSize)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[initialize] Only wrote '{}' bytes of the header", byteWritten));
}
cachedBufferHeader = initializationHeader;
@@ -83,7 +82,7 @@
if (bytesRead.size() != headerSize)
{
throw std::runtime_error(
- fmt::format("Buffer header read only read '{}', expected '{}'",
+ std::format("Buffer header read only read '{}', expected '{}'",
bytesRead.size(), headerSize));
}
@@ -112,7 +111,7 @@
truncatedReadPtrPtr + sizeof(truncatedReadPtr)});
if (writtenSize != sizeof(truncatedReadPtr))
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[updateReadPtr] Wrote '{}' bytes, instead of expected '{}'",
writtenSize, sizeof(truncatedReadPtr)));
}
@@ -135,7 +134,7 @@
littleNewBmcFlagPtr + sizeof(little_uint32_t)});
if (writtenSize != sizeof(little_uint32_t))
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[updateBmcFlags] Wrote '{}' bytes, instead of expected '{}'",
writtenSize, sizeof(little_uint32_t)));
}
@@ -150,13 +149,13 @@
if (relativeOffset > maxOffset)
{
throw std::runtime_error(
- fmt::format("[wraparoundRead] relativeOffset '{}' was bigger "
+ std::format("[wraparoundRead] relativeOffset '{}' was bigger "
"than maxOffset '{}'",
relativeOffset, maxOffset));
}
if (length > maxOffset)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[wraparoundRead] length '{}' was bigger than maxOffset '{}'",
length, maxOffset));
}
@@ -177,7 +176,7 @@
if (bytesRead.size() != numBytesToReadTillQueueEnd)
{
throw std::runtime_error(
- fmt::format("[wraparoundRead] Read '{}' which was not "
+ std::format("[wraparoundRead] Read '{}' which was not "
"the requested length of '{}'",
bytesRead.size(), numBytesToReadTillQueueEnd));
}
@@ -197,7 +196,7 @@
dataInterface->read(queueOffset, numWraparoundBytesToRead);
if (numWraparoundBytesToRead != wrappedBytesRead.size())
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[wraparoundRead] Buffer wrapped around but read '{}' which "
"was not the requested lenght of '{}'",
wrappedBytesRead.size(), numWraparoundBytesToRead));
@@ -244,7 +243,7 @@
if (checksum != 0)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[readEntry] Checksum was '{}', expected '0'", checksum));
}
@@ -261,7 +260,7 @@
boost::endian::little_to_native(cachedBufferHeader.biosWritePtr);
if (currentBiosWritePtr > maxOffset)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[readErrorLogs] currentBiosWritePtr was '{}' which was bigger "
"than maxOffset '{}'",
currentBiosWritePtr, maxOffset));
@@ -270,7 +269,7 @@
boost::endian::little_to_native(cachedBufferHeader.bmcReadPtr);
if (currentReadPtr > maxOffset)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[readErrorLogs] currentReadPtr was '{}' which was bigger "
"than maxOffset '{}'",
currentReadPtr, maxOffset));
@@ -309,7 +308,7 @@
}
if (currentBiosWritePtr != currentReadPtr)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[readErrorLogs] biosWritePtr '{}' and bmcReaddPtr '{}' "
"are not identical after reading through all the logs",
currentBiosWritePtr, currentReadPtr));
@@ -326,14 +325,14 @@
if (queueSize != QUEUE_REGION_SIZE)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[{}] runtime queueSize '{}' did not match compile-time queueSize "
"'{}'. This indicates that the buffer was corrupted",
__FUNCTION__, queueSize, QUEUE_REGION_SIZE));
}
if (ueRegionSize != UE_REGION_SIZE)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[{}] runtime ueRegionSize '{}' did not match compile-time "
"ueRegionSize '{}'. This indicates that the buffer was corrupted",
__FUNCTION__, ueRegionSize, UE_REGION_SIZE));
@@ -349,7 +348,7 @@
if (ueRegionSize != UE_REGION_SIZE)
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"[{}] runtime ueRegionSize '{}' did not match compile-time "
"ueRegionSize '{}'. This indicates that the buffer was corrupted",
__FUNCTION__, ueRegionSize, UE_REGION_SIZE));
diff --git a/src/main.cpp b/src/main.cpp
index 2c94340..31d6b03 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,17 +6,17 @@
#include "rde/external_storer_interface.hpp"
#include "rde/rde_handler.hpp"
-#include <fmt/format.h>
-
#include <boost/asio.hpp>
#include <boost/endian/conversion.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/impl.hpp>
#include <stdplus/fd/managed.hpp>
+#include <stdplus/print.hpp>
#include <chrono>
#include <filesystem>
+#include <format>
#include <fstream>
#include <functional>
#include <memory>
@@ -43,13 +43,13 @@
{
if (error)
{
- fmt::print(stderr, "Async wait failed {}\n", error.message());
+ stdplus::print(stderr, "Async wait failed {}\n", error.message());
return;
}
std::vector<EntryPair> entryPairs = bufferInterface->readErrorLogs();
for (const auto& [entryHeader, entry] : entryPairs)
{
- fmt::print(stderr, "Read an entry of '{}' bytes\n", entry.size());
+ stdplus::print(stderr, "Read an entry of '{}' bytes\n", entry.size());
rde::RdeDecodeStatus rdeDecodeStatus =
rdeCommandHandler->decodeRdeCommand(
diff --git a/src/meson.build b/src/meson.build
index 8e5a8ff..0c2f205 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,22 +1,6 @@
-fmt_dep = dependency('fmt', required: false)
-if not fmt_dep.found()
- fmt_opts = import('cmake').subproject_options()
- fmt_opts.add_cmake_defines({
- 'CMAKE_POSITION_INDEPENDENT_CODE': 'ON',
- 'MASTER_PROJECT': 'OFF',
- })
- fmt_proj = import('cmake').subproject(
- 'fmt',
- options: fmt_opts,
- required: false)
- assert(fmt_proj.found(), 'fmtlib is required')
- fmt_dep = fmt_proj.dependency('fmt')
-endif
-
bios_bmc_smm_error_logger_pre = declare_dependency(
include_directories: [root_inc, bios_bmc_smm_error_logger_inc],
dependencies: [
- fmt_dep,
dependency('threads'),
dependency('stdplus'),
])
diff --git a/src/pci_handler.cpp b/src/pci_handler.cpp
index 201be8f..368b403 100644
--- a/src/pci_handler.cpp
+++ b/src/pci_handler.cpp
@@ -1,13 +1,14 @@
#include "pci_handler.hpp"
#include <fcntl.h>
-#include <fmt/format.h>
#include <stdplus/fd/managed.hpp>
#include <stdplus/fd/mmap.hpp>
+#include <stdplus/print.hpp>
#include <cstdint>
#include <cstring>
+#include <format>
#include <memory>
#include <span>
#include <vector>
@@ -29,10 +30,10 @@
{
if (offset > regionSize || length == 0)
{
- fmt::print(stderr,
- "[read] Offset [{}] was bigger than regionSize [{}] "
- "OR length [{}] was equal to 0\n",
- offset, regionSize, length);
+ stdplus::print(stderr,
+ "[read] Offset [{}] was bigger than regionSize [{}] "
+ "OR length [{}] was equal to 0\n",
+ offset, regionSize, length);
return {};
}
@@ -51,10 +52,10 @@
const size_t length = bytes.size();
if (offset > regionSize || length == 0)
{
- fmt::print(stderr,
- "[write] Offset [{}] was bigger than regionSize [{}] "
- "OR length [{}] was equal to 0\n",
- offset, regionSize, length);
+ stdplus::print(stderr,
+ "[write] Offset [{}] was bigger than regionSize [{}] "
+ "OR length [{}] was equal to 0\n",
+ offset, regionSize, length);
return 0;
}
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;
}
}
diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap
deleted file mode 100644
index 6847ae5..0000000
--- a/subprojects/fmt.wrap
+++ /dev/null
@@ -1,3 +0,0 @@
-[wrap-git]
-url = https://github.com/fmtlib/fmt
-revision = HEAD
diff --git a/test/meson.build b/test/meson.build
index 6528b92..8dc31c3 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -4,7 +4,6 @@
gtest_opt = import('cmake').subproject_options()
gtest_opt.append_compile_args('c++', ['-DCMAKE_CXX_FLAGS=-Wno-pedantic'])
gtest_proj = cmake.subproject('googletest', options: gtest_opt, required: false)
- fmt_depj.dependency('fmt')
if gtest_proj.found()
gtest = declare_dependency(