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

clang-format 18 #438

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ on: [push]
jobs:
clang-format:

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

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

- name: clang-format lint
uses: DoozyX/clang-format-lint-action@v0.3.1
with:
# List of extensions to check
extensions: c,h
run: |
./format-check.py
47 changes: 47 additions & 0 deletions format-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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|verification)/.*\.(c|h|inl)$')
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.

10 changes: 5 additions & 5 deletions include/aws/s3/private/s3_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#else
# define ASSERT_SYNCED_DATA_LOCK_HELD(object)
#endif
#define KB_TO_BYTES(kb) ((kb)*1024)
#define MB_TO_BYTES(mb) ((mb)*1024 * 1024)
#define GB_TO_BYTES(gb) ((gb)*1024 * 1024 * 1024ULL)
#define KB_TO_BYTES(kb) ((kb) * 1024)
#define MB_TO_BYTES(mb) ((mb) * 1024 * 1024)
#define GB_TO_BYTES(gb) ((gb) * 1024 * 1024 * 1024ULL)

#define MS_TO_NS(ms) ((uint64_t)(ms)*1000000)
#define SEC_TO_NS(ms) ((uint64_t)(ms)*1000000000)
#define MS_TO_NS(ms) ((uint64_t)(ms) * 1000000)
#define SEC_TO_NS(ms) ((uint64_t)(ms) * 1000000000)

struct aws_allocator;
struct aws_http_stream;
Expand Down
12 changes: 6 additions & 6 deletions include/aws/s3/s3_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ typedef int(aws_s3_meta_request_upload_review_fn)(
*
* @return The aws_s3express_credentials_provider.
*/
typedef struct aws_s3express_credentials_provider *(aws_s3express_provider_factory_fn)(
struct aws_allocator *allocator,
struct aws_s3_client *client,
aws_simple_completion_callback on_provider_shutdown_callback,
void *shutdown_user_data,
void *factory_user_data);
typedef struct aws_s3express_credentials_provider *(
aws_s3express_provider_factory_fn)(struct aws_allocator *allocator,
struct aws_s3_client *client,
aws_simple_completion_callback on_provider_shutdown_callback,
void *shutdown_user_data,
void *factory_user_data);

/* Keepalive properties are TCP only.
* If interval or timeout are zero, then default values are used.
Expand Down
5 changes: 4 additions & 1 deletion tests/s3_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

static void s_init_mock_s3_request_upload_part_timeout(
struct aws_s3_request *mock_request,
Expand Down
5 changes: 4 additions & 1 deletion tests/s3_meta_request_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

TEST_CASE(meta_request_auto_ranged_get_new_error_handling) {
(void)ctx;
Expand Down
5 changes: 4 additions & 1 deletion tests/s3_mock_server_s3express_provider_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

static uint64_t s_bg_refresh_secs_override = 60;

Expand Down
5 changes: 4 additions & 1 deletion tests/s3_mock_server_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

static int s_validate_mpu_mock_server_metrics(struct aws_array_list *metrics_list) {
/* Check the size of the metrics should be the same as the number of requests, which should be create MPU, two
Expand Down
5 changes: 4 additions & 1 deletion tests/s3_parallel_read_stream_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

#define ONE_SEC_IN_NS ((uint64_t)AWS_TIMESTAMP_NANOS)
#define MAX_TIMEOUT_NS (600 * ONE_SEC_IN_NS)
Expand Down
5 changes: 4 additions & 1 deletion tests/s3_s3express_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

struct aws_s3express_client_tester {
struct aws_allocator *allocator;
Expand Down
4 changes: 3 additions & 1 deletion tests/s3_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ int aws_s3_tester_init(struct aws_allocator *allocator, struct aws_s3_tester *te
&tester->default_signing_config, g_test_s3_region, tester->credentials_provider);
}
#else
{ tester->default_signing_config = tester->anonymous_signing_config; }
{
tester->default_signing_config = tester->anonymous_signing_config;
}
#endif

return AWS_OP_SUCCESS;
Expand Down