Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang format workflow #1920

Merged
merged 20 commits into from
Mar 8, 2024
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AllowAllConstructorInitializersOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
BinPackParameters: false
BinPackArguments: false
BreakBeforeBraces: Allman
ColumnLimit: 120
DerivePointerAlignment: false
Expand All @@ -36,6 +37,7 @@ AllowAllConstructorInitializersOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
BinPackParameters: false
BinPackArguments: false
BreakBeforeBraces: Allman
ColumnLimit: 120
DerivePointerAlignment: false
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Clang Format

on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Clang Format
run: |
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh
chmod +x /tmp/llvm.sh
sudo /tmp/llvm.sh 18
sudo apt-get install -y clang-format-18
rm /tmp/llvm.sh

- name: Clang format version
run: clang-format-18 --version

- name: Run Clang Format
run: |
find . -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.mm" | xargs clang-format-18 --style=file --fallback-style=none --Werror --dry-run
find cpp -name "*.m" | xargs clang-format-18 --style=file --fallback-style=none --Werror --dry-run
externl marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 6 additions & 2 deletions cpp/include/Ice/IconvStringConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ namespace IceInternal
if (count == size_t(-1))
{
throw Ice::IllegalConversionException(
__FILE__, __LINE__, errno == 0 ? "Unknown error" : IceUtilInternal::errorToString(errno));
__FILE__,
__LINE__,
errno == 0 ? "Unknown error" : IceUtilInternal::errorToString(errno));
}
return reinterpret_cast<std::uint8_t*>(outbuf);
}
Expand Down Expand Up @@ -260,7 +262,9 @@ namespace IceInternal
if (count == size_t(-1))
{
throw Ice::IllegalConversionException(
__FILE__, __LINE__, errno == 0 ? "Unknown error" : IceUtilInternal::errorToString(errno));
__FILE__,
__LINE__,
errno == 0 ? "Unknown error" : IceUtilInternal::errorToString(errno));
}

target.resize(target.size() - (outbytesleft / sizeof(charT)));
Expand Down
5 changes: 3 additions & 2 deletions cpp/include/Ice/InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,9 @@ namespace Ice
void read(std::int32_t tag, std::optional<T>& v)
{
if (readOptional(
tag, StreamOptionalHelper<
T, StreamableTraits<T>::helper, StreamableTraits<T>::fixedLength>::optionalFormat))
tag,
StreamOptionalHelper<T, StreamableTraits<T>::helper, StreamableTraits<T>::fixedLength>::
optionalFormat))
{
v.emplace();
StreamOptionalHelper<T, StreamableTraits<T>::helper, StreamableTraits<T>::fixedLength>::read(this, *v);
Expand Down
21 changes: 14 additions & 7 deletions cpp/include/Ice/MetricsAdminI.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ namespace IceInternal
assert(_object->total > 0);
for (typename std::map<std::string, std::pair<MetricsMapIPtr, SubMapMember>>::const_iterator p =
_subMaps.begin();
p != _subMaps.end(); ++p)
p != _subMaps.end();
++p)
{
p->second.first->destroy(); // Break cyclic reference counts.
}
Expand Down Expand Up @@ -201,7 +202,8 @@ namespace IceInternal
TPtr metrics = std::dynamic_pointer_cast<T>(_object->ice_clone());
for (typename std::map<std::string, std::pair<MetricsMapIPtr, SubMapMember>>::const_iterator p =
_subMaps.begin();
p != _subMaps.end(); ++p)
p != _subMaps.end();
++p)
{
metrics.get()->*p->second.second = p->second.first->getMetrics();
}
Expand Down Expand Up @@ -251,7 +253,8 @@ namespace IceInternal
}
}
_subMaps.insert(std::make_pair(
p->first, std::make_pair(p->second.first, p->second.second->create(subMapPrefix, properties))));
p->first,
std::make_pair(p->second.first, p->second.second->create(subMapPrefix, properties))));
}
}

Expand Down Expand Up @@ -318,7 +321,8 @@ namespace IceInternal
if (p != _subMaps.end())
{
return std::pair<MetricsMapIPtr, SubMapMember>(
p->second.second->clone()->shared_from_this(), p->second.first);
p->second.second->clone()->shared_from_this(),
p->second.first);
}
return std::pair<MetricsMapIPtr, SubMapMember>(MetricsMapIPtr(nullptr), static_cast<SubMapMember>(0));
}
Expand Down Expand Up @@ -359,7 +363,8 @@ namespace IceInternal
std::ostringstream os;
std::vector<std::string>::const_iterator q = _groupBySeparators.begin();
for (std::vector<std::string>::const_iterator p = _groupByAttributes.begin();
p != _groupByAttributes.end(); ++p)
p != _groupByAttributes.end();
++p)
{
os << helper(*p);
if (q != _groupBySeparators.end())
Expand Down Expand Up @@ -398,7 +403,8 @@ namespace IceInternal

p = _objects
.insert(typename std::map<std::string, EntryTPtr>::value_type(
key, std::make_shared<EntryT>(shared_from_this(), t, _detachedQueue.end())))
key,
std::make_shared<EntryT>(shared_from_this(), t, _detachedQueue.end())))
.first;
}
p->second->attach(helper);
Expand Down Expand Up @@ -485,7 +491,8 @@ namespace IceInternal
void registerSubMap(const std::string& subMap, IceMX::MetricsMap MetricsType::*member)
{
_subMaps[subMap] = std::pair<IceMX::MetricsMap MetricsType::*, MetricsMapFactoryPtr>(
member, std::make_shared<MetricsMapFactoryT<SubMapMetricsType>>(nullptr));
member,
std::make_shared<MetricsMapFactoryT<SubMapMetricsType>>(nullptr));
}

private:
Expand Down
18 changes: 12 additions & 6 deletions cpp/include/Ice/MetricsObserverI.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace IceMX
~AttributeResolverT()
{
for (typename std::map<std::string, Resolver*>::iterator p = _attributes.begin();
p != _attributes.end(); ++p)
p != _attributes.end();
++p)
{
delete p->second;
}
Expand Down Expand Up @@ -83,27 +84,31 @@ namespace IceMX
template<typename Y> void add(const std::string& name, Y Helper::*member)
{
_attributes.insert(typename std::map<std::string, Resolver*>::value_type(
name, new HelperMemberResolver<Y>(name, member)));
name,
new HelperMemberResolver<Y>(name, member)));
}

template<typename Y> void add(const std::string& name, Y (Helper::*memberFn)() const)
{
_attributes.insert(typename std::map<std::string, Resolver*>::value_type(
name, new HelperMemberFunctionResolver<Y>(name, memberFn)));
name,
new HelperMemberFunctionResolver<Y>(name, memberFn)));
}

template<typename I, typename O, typename Y>
void add(const std::string& name, O (Helper::*getFn)() const, Y I::*member)
{
_attributes.insert(typename std::map<std::string, Resolver*>::value_type(
name, new MemberResolver<I, O, Y>(name, getFn, member)));
name,
new MemberResolver<I, O, Y>(name, getFn, member)));
}

template<typename I, typename O, typename Y>
void add(const std::string& name, O (Helper::*getFn)() const, Y (I::*memberFn)() const)
{
_attributes.insert(typename std::map<std::string, Resolver*>::value_type(
name, new MemberFunctionResolver<I, O, Y>(name, getFn, memberFn)));
name,
new MemberFunctionResolver<I, O, Y>(name, getFn, memberFn)));
}

//
Expand All @@ -114,7 +119,8 @@ namespace IceMX
void add(const std::string& name, O (Helper::*getFn)() const, Y (I::*memberFn)() const noexcept)
{
_attributes.insert(typename std::map<std::string, Resolver*>::value_type(
name, new MemberFunctionResolver<I, O, Y>(name, getFn, memberFn)));
name,
new MemberFunctionResolver<I, O, Y>(name, getFn, memberFn)));
}

private:
Expand Down
5 changes: 3 additions & 2 deletions cpp/include/Ice/OutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ namespace Ice
}

if (writeOptional(
tag, StreamOptionalHelper<
T, StreamableTraits<T>::helper, StreamableTraits<T>::fixedLength>::optionalFormat))
tag,
StreamOptionalHelper<T, StreamableTraits<T>::helper, StreamableTraits<T>::fixedLength>::
optionalFormat))
{
StreamOptionalHelper<T, StreamableTraits<T>::helper, StreamableTraits<T>::fixedLength>::write(this, *v);
}
Expand Down
38 changes: 29 additions & 9 deletions cpp/src/Glacier2/Blobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ Glacier2::Blobject::invoke(
bool override;
try
{
override = _requestQueue->addRequest(make_shared<Request>(
proxy, inParams, current, _forwardContext, _context, std::move(response), exception));
override = _requestQueue->addRequest(
make_shared<
Request>(proxy, inParams, current, _forwardContext, _context, std::move(response), exception));
}
catch (const ObjectNotExistException&)
{
Expand Down Expand Up @@ -271,28 +272,47 @@ Glacier2::Blobject::invoke(
Context ctx = current.ctx;
ctx.insert(_context.begin(), _context.end());
proxy->ice_invokeAsync(
current.operation, current.mode, inParams, std::move(amiResponse), std::move(exception),
std::move(amiSent), ctx);
current.operation,
current.mode,
inParams,
std::move(amiResponse),
std::move(exception),
std::move(amiSent),
ctx);
}
else
{
proxy->ice_invokeAsync(
current.operation, current.mode, inParams, std::move(amiResponse), std::move(exception),
std::move(amiSent), current.ctx);
current.operation,
current.mode,
inParams,
std::move(amiResponse),
std::move(exception),
std::move(amiSent),
current.ctx);
}
}
else
{
if (_context.size() > 0)
{
proxy->ice_invokeAsync(
current.operation, current.mode, inParams, std::move(amiResponse), std::move(exception),
std::move(amiSent), _context);
current.operation,
current.mode,
inParams,
std::move(amiResponse),
std::move(exception),
std::move(amiSent),
_context);
}
else
{
proxy->ice_invokeAsync(
current.operation, current.mode, inParams, std::move(amiResponse), std::move(exception),
current.operation,
current.mode,
inParams,
std::move(amiResponse),
std::move(exception),
std::move(amiSent));
}
}
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/Glacier2/FilterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,8 @@ Glacier2::FilterManager::create(shared_ptr<Instance> instance, const string& use
auto identityFilter = make_shared<Glacier2::IdentitySetI>(allowIdSeq);

return make_shared<Glacier2::FilterManager>(
std::move(instance), std::move(categoryFilter), std::move(adapterIdFilter), std::move(identityFilter));
std::move(instance),
std::move(categoryFilter),
std::move(adapterIdFilter),
std::move(identityFilter));
}
8 changes: 6 additions & 2 deletions cpp/src/Glacier2/Glacier2Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ RouterService::start(int argc, char* argv[], int& status)
}

_sessionRouter = make_shared<SessionRouterI>(
_instance, std::move(verifier), std::move(sessionManager), std::move(sslVerifier),
_instance,
std::move(verifier),
std::move(sessionManager),
std::move(sslVerifier),
std::move(sslSessionManager));

//
Expand Down Expand Up @@ -442,7 +445,8 @@ RouterService::initializeCommunicator(
"Glacier2CryptPermissionsVerifier:createCryptPermissionsVerifier");

initData.properties->setProperty(
"Glacier2CryptPermissionsVerifier.Glacier2.PermissionsVerifier", cryptPasswords);
"Glacier2CryptPermissionsVerifier.Glacier2.PermissionsVerifier",
cryptPasswords);
}
}

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/Glacier2/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Glacier2::Instance::Instance(
if (o)
{
const_cast<shared_ptr<Instrumentation::RouterObserver>&>(_observer) = make_shared<RouterObserverI>(
o->getFacet(), _properties->getPropertyWithDefault("Glacier2.InstanceName", "Glacier2"));
o->getFacet(),
_properties->getPropertyWithDefault("Glacier2.InstanceName", "Glacier2"));
}
}

Expand Down
28 changes: 24 additions & 4 deletions cpp/src/Glacier2/RequestQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ Glacier2::Request::invoke(
Ice::Context ctx = _current.ctx;
ctx.insert(_sslContext.begin(), _sslContext.end());
_proxy->ice_invokeAsync(
_current.operation, _current.mode, inPair, std::move(response), std::move(exception), std::move(sent),
_current.operation,
_current.mode,
inPair,
std::move(response),
std::move(exception),
std::move(sent),
ctx);
}
else
{
_proxy->ice_invokeAsync(
_current.operation, _current.mode, inPair, std::move(response), std::move(exception), std::move(sent),
_current.operation,
_current.mode,
inPair,
std::move(response),
std::move(exception),
std::move(sent),
_current.ctx);
}
}
Expand All @@ -72,13 +82,23 @@ Glacier2::Request::invoke(
if (_sslContext.size() > 0)
{
_proxy->ice_invokeAsync(
_current.operation, _current.mode, inPair, std::move(response), std::move(exception), std::move(sent),
_current.operation,
_current.mode,
inPair,
std::move(response),
std::move(exception),
std::move(sent),
_sslContext);
}
else
{
_proxy->ice_invokeAsync(
_current.operation, _current.mode, inPair, std::move(response), std::move(exception), std::move(sent));
_current.operation,
_current.mode,
inPair,
std::move(response),
std::move(exception),
std::move(sent));
}
}
}
Expand Down
Loading
Loading