clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: Iabfeec3ff53427c317ef9c0b5bf06326ab9a1e17
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index d43e884..28e3328 100644
--- a/.clang-format
+++ b/.clang-format
@@ -87,7 +87,7 @@
IndentWrappedFunctionNames: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
-LambdaBodyIndentation: OuterScope
+LambdaBodyIndentation: Signature
LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
@@ -98,13 +98,14 @@
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 25
-PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakBeforeFirstCallParameter: 50
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
-PenaltyIndentedWhitespace: 0
+PenaltyIndentedWhitespace: 1
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Left
diff --git a/average.cpp b/average.cpp
index 7b12d70..2cc5240 100644
--- a/average.cpp
+++ b/average.cpp
@@ -20,10 +20,9 @@
_previousAverageMap[sensorKey] = sensorValue;
}
-std::optional<int64_t> Average::calcAverage(int64_t preAverage,
- int64_t preInterval,
- int64_t curAverage,
- int64_t curInterval)
+std::optional<int64_t>
+ Average::calcAverage(int64_t preAverage, int64_t preInterval,
+ int64_t curAverage, int64_t curInterval)
{
int64_t value = 0;
// Estimate that the interval will overflow about 292471
@@ -43,9 +42,9 @@
// (a2*i2-a1*i1)/(i2-i1) =
// (a2*(i1+delta)-a1*i1)/delta =
// (a2-a1)(i1/delta)+a2
- value = (curAverage - preAverage) *
- (static_cast<double>(preInterval) / delta) +
- curAverage;
+ value =
+ (curAverage - preAverage) * (static_cast<double>(preInterval) / delta) +
+ curAverage;
return value;
}
diff --git a/average.hpp b/average.hpp
index cf2afd3..bf91404 100644
--- a/average.hpp
+++ b/average.hpp
@@ -60,10 +60,9 @@
* return {}, if curInterval-preInterval=0
* return new calculated average value, if curInterval-preInterval>0
*/
- static std::optional<int64_t> calcAverage(int64_t preAverage,
- int64_t preInterval,
- int64_t curAverage,
- int64_t curInterval);
+ static std::optional<int64_t>
+ calcAverage(int64_t preAverage, int64_t preInterval, int64_t curAverage,
+ int64_t curInterval);
private:
/** @brief Store the previous average sensor map */
diff --git a/fan_pwm.cpp b/fan_pwm.cpp
index 6e903d3..2e3dc1e 100644
--- a/fan_pwm.cpp
+++ b/fan_pwm.cpp
@@ -38,8 +38,8 @@
xyz::openbmc_project::Control::Device::WriteFailure::
CALLOUT_DEVICE_PATH(_devPath.c_str()));
- auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
- empty);
+ auto file =
+ sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, empty);
log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
e.code().value())
diff --git a/mainloop.cpp b/mainloop.cpp
index 6fa74d3..52c3c64 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -217,8 +217,8 @@
const auto& [sensorSysfsType, sensorSysfsNum] = sensorSetKey;
/* Note: The sensor objects all share the same ioAccess object. */
- auto sensorObj = std::make_unique<sensor::Sensor>(sensorSetKey, _ioAccess,
- _devPath);
+ auto sensorObj =
+ std::make_unique<sensor::Sensor>(sensorSetKey, _ioAccess, _devPath);
// Get list of return codes for removing sensors on device
auto devRmRCs = env::getEnv("REMOVERCS");
@@ -274,9 +274,9 @@
}
catch (const std::system_error& e)
{
- auto file = sysfs::make_sysfs_path(_ioAccess->path(), sensorSysfsType,
- sensorSysfsNum,
- hwmon::entry::cinput);
+ auto file =
+ sysfs::make_sysfs_path(_ioAccess->path(), sensorSysfsType,
+ sensorSysfsNum, hwmon::entry::cinput);
// Check sensorAdjusts for sensor removal RCs
auto& sAdjusts = sensorObj->getAdjusts();
@@ -315,8 +315,8 @@
std::get<sensorID>(properties), sensorValue,
info, scale);
- auto target = addTarget<hwmon::FanSpeed>(sensorSetKey, _ioAccess, _devPath,
- info);
+ auto target =
+ addTarget<hwmon::FanSpeed>(sensorSetKey, _ioAccess, _devPath, info);
if (target)
{
target->enable();
@@ -339,9 +339,8 @@
const char* prefix, const char* root,
const std::string& instanceId,
const hwmonio::HwmonIOInterface* ioIntf) :
- _bus(std::move(bus)),
- _manager(_bus, root), _pathParam(param), _hwmonRoot(), _instance(),
- _devPath(devPath), _prefix(prefix), _root(root), _state(),
+ _bus(std::move(bus)), _manager(_bus, root), _pathParam(param), _hwmonRoot(),
+ _instance(), _devPath(devPath), _prefix(prefix), _root(root), _state(),
_instanceId(instanceId), _ioAccess(ioIntf),
_event(sdeventplus::Event::get_default()),
_timer(_event, std::bind(&MainLoop::read, this))
@@ -410,9 +409,9 @@
// std::tuple<SensorSet::mapped_type,
// std::string(Sensor Label),
// ObjectInfo>
- auto value = std::make_tuple(std::move(i.second),
- std::move((*object).first),
- std::move((*object).second));
+ auto value =
+ std::make_tuple(std::move(i.second), std::move((*object).first),
+ std::move((*object).second));
_state[std::move(i.first)] = std::move(value);
}
@@ -514,8 +513,8 @@
// For sensors with attribute ASYNC_READ_TIMEOUT,
// spawn a thread with timeout
- auto asyncReadTimeout = env::getEnv("ASYNC_READ_TIMEOUT",
- sensorSetKey);
+ auto asyncReadTimeout =
+ env::getEnv("ASYNC_READ_TIMEOUT", sensorSetKey);
if (!asyncReadTimeout.empty())
{
std::chrono::milliseconds asyncTimeout{
@@ -529,9 +528,9 @@
{
// Retry for up to a second if device is busy
// or has a transient error.
- value = _ioAccess->read(sensorSysfsType, sensorSysfsNum,
- input, hwmonio::retries,
- hwmonio::delay);
+ value =
+ _ioAccess->read(sensorSysfsType, sensorSysfsNum, input,
+ hwmonio::retries, hwmonio::delay);
}
// Set functional property to true if we could read sensor
@@ -679,9 +678,9 @@
input = hwmon::entry::average;
}
// Sensor object added, erase entry from removal list
- auto file = sysfs::make_sysfs_path(_ioAccess->path(),
- it->first.first,
- it->first.second, input);
+ auto file =
+ sysfs::make_sysfs_path(_ioAccess->path(), it->first.first,
+ it->first.second, input);
log<level::INFO>("Added sensor to dbus after successful read",
entry("FILE=%s", file.c_str()));
diff --git a/sensor.cpp b/sensor.cpp
index 72d7821..ff7635f 100644
--- a/sensor.cpp
+++ b/sensor.cpp
@@ -31,8 +31,8 @@
Sensor::Sensor(const SensorSet::key_type& sensor,
const hwmonio::HwmonIOInterface* ioAccess,
const std::string& devPath) :
- _sensor(sensor),
- _ioAccess(ioAccess), _devPath(devPath), _scale(0), _hasFaultFile(false)
+ _sensor(sensor), _ioAccess(ioAccess), _devPath(devPath), _scale(0),
+ _hasFaultFile(false)
{
auto chip = env::getEnv("GPIOCHIP", sensor);
auto access = env::getEnv("GPIO", sensor);
@@ -105,9 +105,9 @@
#endif
// Adjust based on gain and offset
- value = static_cast<decltype(value)>(static_cast<double>(value) *
- _sensorAdjusts.gain +
- _sensorAdjusts.offset);
+ value = static_cast<decltype(value)>(
+ static_cast<double>(value) * _sensorAdjusts.gain +
+ _sensorAdjusts.offset);
if constexpr (std::is_same<SensorValueType, double>::value)
{
@@ -117,9 +117,8 @@
return value;
}
-std::shared_ptr<ValueObject> Sensor::addValue(const RetryIO& retryIO,
- ObjectInfo& info,
- TimedoutMap& timedoutMap)
+std::shared_ptr<ValueObject> Sensor::addValue(
+ const RetryIO& retryIO, ObjectInfo& info, TimedoutMap& timedoutMap)
{
// Get the initial value for the value interface.
auto& bus = *std::get<sdbusplus::bus_t*>(info);
@@ -221,8 +220,8 @@
std::string entry = hwmon::entry::fault;
bool functional = true;
- auto sysfsFullPath = sysfs::make_sysfs_path(_ioAccess->path(), faultName,
- faultID, entry);
+ auto sysfsFullPath =
+ sysfs::make_sysfs_path(_ioAccess->path(), faultName, faultID, entry);
if (fs::exists(sysfsFullPath))
{
_hasFaultFile = true;
@@ -263,8 +262,8 @@
return iface;
}
-std::shared_ptr<AccuracyObject> Sensor::addAccuracy(ObjectInfo& info,
- double accuracy)
+std::shared_ptr<AccuracyObject>
+ Sensor::addAccuracy(ObjectInfo& info, double accuracy)
{
auto& objPath = std::get<std::string>(info);
auto& obj = std::get<InterfaceMap>(info);
@@ -279,8 +278,8 @@
return iface;
}
-std::shared_ptr<PriorityObject> Sensor::addPriority(ObjectInfo& info,
- size_t priority)
+std::shared_ptr<PriorityObject>
+ Sensor::addPriority(ObjectInfo& info, size_t priority)
{
auto& objPath = std::get<std::string>(info);
auto& obj = std::get<InterfaceMap>(info);
@@ -313,13 +312,12 @@
return GpioLocker(std::move(handle));
}
-SensorValueType asyncRead(const SensorSet::key_type& sensorSetKey,
- const hwmonio::HwmonIOInterface* ioAccess,
- std::chrono::milliseconds asyncTimeout,
- TimedoutMap& timedoutMap, const std::string& type,
- const std::string& id, const std::string& sensor,
- const size_t retries,
- const std::chrono::milliseconds delay)
+SensorValueType asyncRead(
+ const SensorSet::key_type& sensorSetKey,
+ const hwmonio::HwmonIOInterface* ioAccess,
+ std::chrono::milliseconds asyncTimeout, TimedoutMap& timedoutMap,
+ const std::string& type, const std::string& id, const std::string& sensor,
+ const size_t retries, const std::chrono::milliseconds delay)
{
// Default async read timeout
bool valueIsValid = false;
@@ -329,9 +327,9 @@
if (asyncIter == timedoutMap.end())
{
// If sensor not found in timedoutMap, spawn an async thread
- asyncThread = std::async(std::launch::async,
- &hwmonio::HwmonIOInterface::read, ioAccess,
- type, id, sensor, retries, delay);
+ asyncThread =
+ std::async(std::launch::async, &hwmonio::HwmonIOInterface::read,
+ ioAccess, type, id, sensor, retries, delay);
valueIsValid = true;
}
else
diff --git a/sensor.hpp b/sensor.hpp
index ac38cff..9963ed8 100644
--- a/sensor.hpp
+++ b/sensor.hpp
@@ -107,9 +107,8 @@
*
* @return - Shared pointer to the value object
*/
- std::shared_ptr<ValueObject> addValue(const RetryIO& retryIO,
- ObjectInfo& info,
- TimedoutMap& timedoutMap);
+ std::shared_ptr<ValueObject> addValue(
+ const RetryIO& retryIO, ObjectInfo& info, TimedoutMap& timedoutMap);
/**
* @brief Add status interface and functional property for sensor
@@ -134,8 +133,8 @@
*
* @return - Shared pointer to the accuracy object
*/
- std::shared_ptr<AccuracyObject> addAccuracy(ObjectInfo& info,
- double accuracy);
+ std::shared_ptr<AccuracyObject>
+ addAccuracy(ObjectInfo& info, double accuracy);
/**
* @brief Add Priority interface and priority property for sensors
@@ -147,8 +146,8 @@
* @return - Shared pointer to the priority object
*/
- std::shared_ptr<PriorityObject> addPriority(ObjectInfo& info,
- size_t priority);
+ std::shared_ptr<PriorityObject>
+ addPriority(ObjectInfo& info, size_t priority);
/**
* @brief Get the scale from the sensor.
@@ -240,11 +239,10 @@
*
* @return - SensorValueType read asynchronously, will throw if timed out
*/
-SensorValueType asyncRead(const SensorSet::key_type& sensorSetKey,
- const hwmonio::HwmonIOInterface* ioAccess,
- std::chrono::milliseconds asyncTimeout,
- TimedoutMap& timedoutMap, const std::string& type,
- const std::string& id, const std::string& sensor,
- const size_t retries,
- const std::chrono::milliseconds delay);
+SensorValueType asyncRead(
+ const SensorSet::key_type& sensorSetKey,
+ const hwmonio::HwmonIOInterface* ioAccess,
+ std::chrono::milliseconds asyncTimeout, TimedoutMap& timedoutMap,
+ const std::string& type, const std::string& id, const std::string& sensor,
+ const size_t retries, const std::chrono::milliseconds delay);
} // namespace sensor
diff --git a/sysfs.cpp b/sysfs.cpp
index d4c47aa..aae6ff3 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -220,11 +220,11 @@
}
auto dir_iter = fs::directory_iterator(path);
- auto hwmonInst = std::find_if(dir_iter, end(dir_iter),
- [](const fs::directory_entry& d) {
- return (d.path().filename().string().find("hwmon") !=
- std::string::npos);
- });
+ auto hwmonInst = std::find_if(
+ dir_iter, end(dir_iter), [](const fs::directory_entry& d) {
+ return (d.path().filename().string().find("hwmon") !=
+ std::string::npos);
+ });
if (hwmonInst != end(dir_iter))
{
return hwmonInst->path();
diff --git a/sysfs.hpp b/sysfs.hpp
index 80fb3d6..aac9c2b 100644
--- a/sysfs.hpp
+++ b/sysfs.hpp
@@ -5,10 +5,9 @@
namespace sysfs
{
-inline std::string make_sysfs_path(const std::string& path,
- const std::string& type,
- const std::string& id,
- const std::string& entry)
+inline std::string
+ make_sysfs_path(const std::string& path, const std::string& type,
+ const std::string& id, const std::string& entry)
{
using namespace std::literals;
diff --git a/targets.hpp b/targets.hpp
index 5cd82ff..4c2786f 100644
--- a/targets.hpp
+++ b/targets.hpp
@@ -98,8 +98,8 @@
entry = empty;
}
- sysfsFullPath = sysfs::make_sysfs_path(ioAccess->path(), targetName,
- targetId, entry);
+ sysfsFullPath =
+ sysfs::make_sysfs_path(ioAccess->path(), targetName, targetId, entry);
if (fs::exists(sysfsFullPath))
{
auto useTarget = true;
diff --git a/test/fanpwm_unittest.cpp b/test/fanpwm_unittest.cpp
index 66910c3..8f12b19 100644
--- a/test/fanpwm_unittest.cpp
+++ b/test/fanpwm_unittest.cpp
@@ -37,9 +37,9 @@
StrEq(intf), NotNull()))
.WillOnce(Invoke(
[=](sd_bus*, const char*, const char*, const char** names) {
- EXPECT_STREQ(property.c_str(), names[0]);
- return 0;
- }));
+ EXPECT_STREQ(property.c_str(), names[0]);
+ return 0;
+ }));
}
return;
@@ -137,9 +137,9 @@
IsNull(), StrEq("asdf"), StrEq(FanPwmIntf), NotNull()))
.WillOnce(
Invoke([&](sd_bus*, const char*, const char*, const char** names) {
- EXPECT_EQ(0, strncmp("Target", names[0], 6));
- return 0;
- }));
+ EXPECT_EQ(0, strncmp("Target", names[0], 6));
+ return 0;
+ }));
EXPECT_EQ(target, f.target(target));
}
diff --git a/test/hwmonio_mock.hpp b/test/hwmonio_mock.hpp
index 6caa67e..0edcf52 100644
--- a/test/hwmonio_mock.hpp
+++ b/test/hwmonio_mock.hpp
@@ -10,7 +10,7 @@
class HwmonIOMock : public HwmonIOInterface
{
public:
- virtual ~HwmonIOMock(){};
+ virtual ~HwmonIOMock() {};
MOCK_CONST_METHOD5(read, int64_t(const std::string&, const std::string&,
const std::string&, size_t,
diff --git a/test/sensor_unittest.cpp b/test/sensor_unittest.cpp
index dd57595..b40cdae 100644
--- a/test/sensor_unittest.cpp
+++ b/test/sensor_unittest.cpp
@@ -62,8 +62,8 @@
EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
.WillOnce(Return(""));
- auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
- hwmonio_mock.get(), path);
+ auto sensor =
+ std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
EXPECT_FALSE(sensor == nullptr);
}
@@ -90,8 +90,8 @@
EXPECT_CALL(gMock, build(StrEq("chipA"), StrEq("5")))
.WillOnce(Invoke([&](const std::string&, const std::string&) {
- return std::move(handleMock);
- }));
+ return std::move(handleMock);
+ }));
/* Always calls GAIN and OFFSET, can use ON_CALL instead of EXPECT_CALL */
EXPECT_CALL(env::mockEnv, get(StrEq("GAIN_temp5"))).WillOnce(Return(""));
@@ -99,8 +99,8 @@
EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
.WillOnce(Return(""));
- auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
- hwmonio_mock.get(), path);
+ auto sensor =
+ std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
EXPECT_FALSE(sensor == nullptr);
}
@@ -126,8 +126,8 @@
EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
.WillOnce(Return(""));
- auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
- hwmonio_mock.get(), path);
+ auto sensor =
+ std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
EXPECT_FALSE(sensor == nullptr);
double startingValue = 1.0;