Skip to content

Commit

Permalink
clang-format 18 (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm authored Jun 14, 2024
1 parent b373805 commit a1a3160
Show file tree
Hide file tree
Showing 82 changed files with 1,351 additions and 769 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ on:
jobs:
clang-format:

runs-on: ubuntu-22.04 # latest
runs-on: ubuntu-24.04 # latest

steps:
- name: Checkout Sources
uses: actions/checkout@v4

- name: clang-format lint
uses: DoozyX/[email protected]
with:
source: './include ./source ./tests'
exclude: './include/aws/crt/external ./source/external'
clangFormatVersion: 11.1.0
run: |
./format-check.py
46 changes: 46 additions & 0 deletions format-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path
import re
from subprocess import list2cmdline, run
from tempfile import NamedTemporaryFile

CLANG_FORMAT_VERSION = '18.1.6'

INCLUDE_REGEX = re.compile(r'^(include|source|tests)/.*\.(cpp|h)$')
EXCLUDE_REGEX = re.compile(r'^$')

arg_parser = argparse.ArgumentParser(description="Check with clang-format")
arg_parser.add_argument('-i', '--inplace-edit', action='store_true',
help="Edit files inplace")
args = arg_parser.parse_args()

os.chdir(Path(__file__).parent)

# create file containing list of all files to format
filepaths_file = NamedTemporaryFile(delete=False)
for dirpath, dirnames, filenames in os.walk('.'):
for filename in filenames:
# our regexes expect filepath to use forward slash
filepath = Path(dirpath, filename).as_posix()
if not INCLUDE_REGEX.match(filepath):
continue
if EXCLUDE_REGEX.match(filepath):
continue

filepaths_file.write(f"{filepath}\n".encode())
filepaths_file.close()

# use pipx to run clang-format from PyPI
# this is a simple way to run the same clang-format version regardless of OS
cmd = ['pipx', 'run', f'clang-format=={CLANG_FORMAT_VERSION}',
f'--files={filepaths_file.name}']
if args.inplace_edit:
cmd += ['-i']
else:
cmd += ['--Werror', '--dry-run']

print(f"{Path.cwd()}$ {list2cmdline(cmd)}")
if run(cmd).returncode:
exit(1)
24 changes: 0 additions & 24 deletions format-check.sh

This file was deleted.

2 changes: 1 addition & 1 deletion include/aws/crt/ImdsClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,5 @@ namespace Aws
};

} // namespace Imds
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ namespace Aws
return basic_string_view<char>(s, length);
}

inline basic_string_view<wchar_t> operator"" _sv(const wchar_t *s, size_t length) noexcept
inline basic_string_view<wchar_t> operator"" _sv(const wchar_t * s, size_t length) noexcept
{
return basic_string_view<wchar_t>(s, length);
}
Expand Down
14 changes: 10 additions & 4 deletions include/aws/crt/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ namespace Aws
{
namespace VariantDetail
{
template <typename T> constexpr const T &ConstExprMax(const T &a, const T &b) { return (a < b) ? b : a; }
template <typename T> constexpr const T &ConstExprMax(const T &a, const T &b)
{
return (a < b) ? b : a;
}

namespace ParameterPackSize
{
Expand Down Expand Up @@ -77,7 +80,10 @@ namespace Aws
}

// a case when the template parameter pack is empty (i.e. Variant<>)
template <typename T> constexpr bool ContainsType() { return false; }
template <typename T> constexpr bool ContainsType()
{
return false;
}

template <typename T, typename... Ts> struct HasType
{
Expand Down Expand Up @@ -109,8 +115,8 @@ namespace Aws
}
};
} // namespace VariantDebug
#endif /* defined(AWS_CRT_ENABLE_VARIANT_DEBUG) */
} // namespace VariantDetail
#endif /* defined(AWS_CRT_ENABLE_VARIANT_DEBUG) */
} // namespace VariantDetail

template <std::size_t Index, typename... Ts> class VariantAlternative;

Expand Down
2 changes: 1 addition & 1 deletion include/aws/crt/auth/Credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,5 @@ namespace Aws
aws_credentials_provider *m_provider;
};
} // namespace Auth
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/auth/Signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ namespace Aws
};

} // namespace Auth
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/auth/Sigv4Signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,5 @@ namespace Aws
Allocator *m_allocator;
};
} // namespace Auth
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/crypto/HMAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ namespace Aws
std::function<std::shared_ptr<ByoHMAC>(size_t digestSize, const ByteCursor &secret, Allocator *)>;

} // namespace Crypto
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/crypto/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,5 @@ namespace Aws
using CreateHashCallback = std::function<std::shared_ptr<ByoHash>(size_t digestSize, Allocator *)>;

} // namespace Crypto
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/crypto/SymmetricCipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@ namespace Aws
int m_lastError;
};
} // namespace Crypto
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/endpoints/RuleEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ namespace Aws
aws_endpoints_rule_engine *m_ruleEngine;
};
} // namespace Endpoints
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/http/HttpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,5 @@ namespace Aws
};

} // namespace Http
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/http/HttpConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ namespace Aws
friend class ManagedConnection;
};
} // namespace Http
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/http/HttpProxyStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ namespace Aws
struct aws_http_proxy_strategy *m_strategy;
};
} // namespace Http
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/http/HttpRequestResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ namespace Aws
bool SetResponseCode(int response) noexcept;
};
} // namespace Http
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/Bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ namespace Aws
bool m_enableBlockingShutdown;
};
} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
4 changes: 2 additions & 2 deletions include/aws/crt/io/ChannelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace Aws
/**
* Directs the channel handler to reset all of the internal statistics it tracks about itself.
*/
virtual void ResetStatistics(){};
virtual void ResetStatistics() {};

/**
* Adds a pointer to the handler's internal statistics (if they exist) to a list of statistics
Expand Down Expand Up @@ -234,5 +234,5 @@ namespace Aws
static void s_GatherStatistics(struct aws_channel_handler *, struct aws_array_list *statsList);
};
} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/HostResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ namespace Aws
void *user_data);
};
} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/Pkcs11.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ namespace Aws
aws_pkcs11_lib *impl = nullptr;
};
} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/SocketOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ namespace Aws
aws_socket_options options;
};
} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ namespace Aws
std::shared_ptr<Aws::Crt::Io::IStream> m_stream;
};
} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/TlsOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,5 @@ namespace Aws
Allocator *allocator)>;

} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/io/Uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ namespace Aws
AWS_CRT_CPP_API Aws::Crt::String EncodeQueryParameterValue(ByteCursor paramValue);

} // namespace Io
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/mqtt/Mqtt5Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,5 @@ namespace Aws
};

} // namespace Mqtt5
} // namespace Crt
} // namespace Crt
} // namespace Aws
10 changes: 5 additions & 5 deletions include/aws/crt/mqtt/Mqtt5Packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ namespace Aws
*/
const Crt::String &getClientId() const noexcept;

virtual ~NegotiatedSettings(){};
virtual ~NegotiatedSettings() {};
NegotiatedSettings(const NegotiatedSettings &) = delete;
NegotiatedSettings(NegotiatedSettings &&) noexcept = delete;
NegotiatedSettings &operator=(const NegotiatedSettings &) = delete;
Expand Down Expand Up @@ -1388,7 +1388,7 @@ namespace Aws
*/
const Crt::Optional<String> &getServerReference() const noexcept;

virtual ~ConnAckPacket(){};
virtual ~ConnAckPacket() {};
ConnAckPacket(const ConnAckPacket &) = delete;
ConnAckPacket(ConnAckPacket &&) noexcept = delete;
ConnAckPacket &operator=(const ConnAckPacket &) = delete;
Expand Down Expand Up @@ -1802,7 +1802,7 @@ namespace Aws
*/
const Crt::Vector<UserProperty> &getUserProperties() const noexcept;

virtual ~PubAckPacket(){};
virtual ~PubAckPacket() {};
PubAckPacket(const PubAckPacket &toCopy) noexcept = delete;
PubAckPacket(PubAckPacket &&toMove) noexcept = delete;
PubAckPacket &operator=(const PubAckPacket &toCopy) noexcept = delete;
Expand Down Expand Up @@ -1968,7 +1968,7 @@ namespace Aws

bool initializeRawOptions(aws_mqtt5_subscription_view &raw_options) const noexcept;

virtual ~Subscription(){};
virtual ~Subscription() {};
Subscription(const Subscription &) noexcept;
Subscription(Subscription &&) noexcept;
Subscription &operator=(const Subscription &) noexcept;
Expand Down Expand Up @@ -2404,5 +2404,5 @@ namespace Aws
};

} // namespace Mqtt5
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/mqtt/MqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ namespace Aws
aws_mqtt_client *m_client;
};
} // namespace Mqtt
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/mqtt/MqttConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,5 @@ namespace Aws
std::shared_ptr<MqttConnectionCore> m_connectionCore;
};
} // namespace Mqtt
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/mqtt/MqttTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ namespace Aws
uint64_t unackedOperationSize;
};
} // namespace Mqtt
} // namespace Crt
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/mqtt/private/Mqtt5ClientCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,6 @@ namespace Aws
};

} // namespace Mqtt5
} // namespace Crt
} // namespace Crt
} // namespace Aws
/*! \endcond */
2 changes: 1 addition & 1 deletion include/aws/crt/mqtt/private/MqttConnectionCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,6 @@ namespace Aws
std::shared_ptr<MqttConnectionCore> m_self;
};
} // namespace Mqtt
} // namespace Crt
} // namespace Crt
} // namespace Aws
/*! \endcond */
15 changes: 12 additions & 3 deletions source/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ namespace Aws
namespace Crt
{

Allocator *DefaultAllocatorImplementation() noexcept { return aws_default_allocator(); }
Allocator *DefaultAllocatorImplementation() noexcept
{
return aws_default_allocator();
}

Allocator *DefaultAllocator() noexcept { return DefaultAllocatorImplementation(); }
Allocator *DefaultAllocator() noexcept
{
return DefaultAllocatorImplementation();
}

Allocator *g_allocator = Aws::Crt::DefaultAllocatorImplementation();

Allocator *ApiAllocator() noexcept { return g_allocator; }
Allocator *ApiAllocator() noexcept
{
return g_allocator;
}

} // namespace Crt
} // namespace Aws
Loading

0 comments on commit a1a3160

Please sign in to comment.