prefer std::format over fmt
Since C++20, std::format has existed so prefer that. For the single
fmt::print call we can use stdplus::print until GCC supports the std
one.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I4c8af58966fb7330dee20fb13ae2ef11d8a823c7
diff --git a/fan_pwm.cpp b/fan_pwm.cpp
index 253515d..6e903d3 100644
--- a/fan_pwm.cpp
+++ b/fan_pwm.cpp
@@ -6,12 +6,11 @@
#include "sensorset.hpp"
#include "sysfs.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Control/Device/error.hpp>
#include <filesystem>
+#include <format>
#include <string>
using namespace phosphor::logging;
@@ -42,7 +41,7 @@
auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
empty);
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}", file,
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
e.code().value())
.c_str());
diff --git a/fan_speed.cpp b/fan_speed.cpp
index 9ce625b..067e882 100644
--- a/fan_speed.cpp
+++ b/fan_speed.cpp
@@ -6,11 +6,11 @@
#include "sensorset.hpp"
#include "sysfs.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Control/Device/error.hpp>
+#include <format>
+
using namespace phosphor::logging;
namespace hwmon
@@ -41,7 +41,7 @@
auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
entry::target);
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}",
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
file, e.code().value())
.c_str());
@@ -77,7 +77,7 @@
auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
_id, entry::enable);
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}",
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
fullPath, e.code().value())
.c_str());
diff --git a/mainloop.cpp b/mainloop.cpp
index cfc5b5e..6fa74d3 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -29,13 +29,12 @@
#include "thresholds.hpp"
#include "util.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Sensor/Device/error.hpp>
#include <cassert>
#include <cstdlib>
+#include <format>
#include <functional>
#include <future>
#include <iostream>
@@ -302,7 +301,7 @@
xyz::openbmc_project::Sensor::Device::ReadFailure::
CALLOUT_DEVICE_PATH(_devPath.c_str()));
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}", file,
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
e.code().value())
.c_str());
exit(EXIT_FAILURE);
@@ -618,7 +617,7 @@
xyz::openbmc_project::Sensor::Device::ReadFailure::
CALLOUT_DEVICE_PATH(_devPath.c_str()));
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}",
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
file, e.code().value())
.c_str());
diff --git a/meson.build b/meson.build
index 7a1b810..28d4b1b 100644
--- a/meson.build
+++ b/meson.build
@@ -11,8 +11,6 @@
meson_version: '>=1.1.1',
)
-fmt = dependency('fmt')
-
conf = configuration_data()
conf.set_quoted('BUSNAME_PREFIX', get_option('busname-prefix'))
conf.set_quoted('SENSOR_ROOT', get_option('sensor-root'))
@@ -22,14 +20,15 @@
sysfs_headers = include_directories('.')
sysfs_deps = [
- fmt,
+ dependency('stdplus'),
]
sysfs_lib = static_library(
'sysfs',
'sysfs.cpp',
include_directories: sysfs_headers,
- dependencies: sysfs_deps)
+ dependencies: sysfs_deps,
+)
sysfs_dep = declare_dependency(
dependencies: sysfs_deps,
@@ -39,7 +38,6 @@
hwmon_headers = include_directories('.')
hwmon_deps = [
- fmt,
dependency('gpioplus'),
dependency('phosphor-dbus-interfaces'),
dependency('phosphor-logging'),
diff --git a/sensor.cpp b/sensor.cpp
index 0b3ca66..72d7821 100644
--- a/sensor.cpp
+++ b/sensor.cpp
@@ -8,8 +8,6 @@
#include "sensorset.hpp"
#include "sysfs.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Sensor/Device/error.hpp>
@@ -19,6 +17,7 @@
#include <cmath>
#include <cstring>
#include <filesystem>
+#include <format>
#include <future>
#include <thread>
@@ -246,7 +245,7 @@
metadata::CALLOUT_ERRNO(e.code().value()),
metadata::CALLOUT_DEVICE_PATH(_devPath.c_str()));
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno {}",
+ log<level::INFO>(std::format("Failing sysfs file: {} errno {}",
sysfsFullPath, e.code().value())
.c_str());
}
diff --git a/sysfs.cpp b/sysfs.cpp
index 644763e..d4c47aa 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -15,12 +15,13 @@
*/
#include "sysfs.hpp"
-#include <fmt/format.h>
+#include <stdplus/print.hpp>
#include <algorithm>
#include <cerrno>
#include <cstdlib>
#include <filesystem>
+#include <format>
#include <fstream>
#include <string>
@@ -231,9 +232,9 @@
}
catch (const std::exception& e)
{
- fmt::print(stderr,
- "Unable to find hwmon directory from the dev path: {}\n",
- devPath.c_str());
+ stdplus::print(stderr,
+ "Unable to find hwmon directory from the dev path: {}\n",
+ devPath.c_str());
}
return emptyString;
}
diff --git a/targets.hpp b/targets.hpp
index 515bf2e..5cd82ff 100644
--- a/targets.hpp
+++ b/targets.hpp
@@ -5,13 +5,12 @@
#include "fan_speed.hpp"
#include "hwmonio.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Sensor/Device/error.hpp>
#include <filesystem>
+#include <format>
#include <memory>
enum class targetType
@@ -155,7 +154,7 @@
metadata::CALLOUT_ERRNO(e.code().value()),
metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));
- log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}",
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
sysfsFullPath, e.code().value())
.c_str());
}