Skip to content

Commit

Permalink
prefer std::format over fmt
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: I4c8af58966fb7330dee20fb13ae2ef11d8a823c7
  • Loading branch information
williamspatrick committed Feb 14, 2024
1 parent 47fb49a commit 6412993
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
5 changes: 2 additions & 3 deletions fan_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,7 +41,7 @@ uint64_t FanPwm::target(uint64_t value)
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());

Expand Down
8 changes: 4 additions & 4 deletions fan_speed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,7 +41,7 @@ uint64_t FanSpeed::target(uint64_t value)
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());

Expand Down Expand Up @@ -77,7 +77,7 @@ void FanSpeed::enable()
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());

Expand Down
7 changes: 3 additions & 4 deletions mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -302,7 +301,7 @@ std::optional<ObjectStateData>
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);
Expand Down Expand Up @@ -618,7 +617,7 @@ void MainLoop::read()
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());

Expand Down
8 changes: 3 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ project(
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'))
Expand All @@ -22,14 +20,15 @@ conf.set10('UPDATE_FUNCTIONAL_ON_FAIL', get_option('update-functional-on-fail'))
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,
Expand All @@ -39,7 +38,6 @@ sysfs_dep = declare_dependency(
hwmon_headers = include_directories('.')

hwmon_deps = [
fmt,
dependency('gpioplus'),
dependency('phosphor-dbus-interfaces'),
dependency('phosphor-logging'),
Expand Down
5 changes: 2 additions & 3 deletions sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -19,6 +17,7 @@
#include <cmath>
#include <cstring>
#include <filesystem>
#include <format>
#include <future>
#include <thread>

Expand Down Expand Up @@ -246,7 +245,7 @@ std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info)
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());
}
Expand Down
9 changes: 5 additions & 4 deletions sysfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -231,9 +232,9 @@ std::string findHwmonFromDevPath(const std::string& devPath)
}
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;
}
Expand Down
5 changes: 2 additions & 3 deletions targets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,7 +154,7 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
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());
}
Expand Down

0 comments on commit 6412993

Please sign in to comment.