Skip to content

Commit 48d042e

Browse files
authored
clang-format 18 (#112)
see: awslabs/aws-c-common#1113
1 parent 1a70c50 commit 48d042e

File tree

3 files changed

+51
-32
lines changed

3 files changed

+51
-32
lines changed

.github/workflows/clang-format.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ on: [push]
55
jobs:
66
clang-format:
77

8-
runs-on: ubuntu-20.04 # latest
8+
runs-on: ubuntu-24.04 # latest
99

1010
steps:
1111
- name: Checkout Sources
12-
uses: actions/checkout@v1
12+
uses: actions/checkout@v4
1313

1414
- name: clang-format lint
15-
uses: DoozyX/[email protected]
16-
with:
17-
# List of extensions to check
18-
extensions: c,h
19-
exclude: './bin'
20-
clangFormatVersion: 11.1.0
15+
run: |
16+
./format-check.py

format-check.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import os
4+
from pathlib import Path
5+
import re
6+
from subprocess import list2cmdline, run
7+
from tempfile import NamedTemporaryFile
8+
9+
CLANG_FORMAT_VERSION = '18.1.6'
10+
11+
INCLUDE_REGEX = re.compile(
12+
r'^(include|source|tests|verification)/.*\.(c|h|inl)$')
13+
EXCLUDE_REGEX = re.compile(r'^$')
14+
15+
arg_parser = argparse.ArgumentParser(description="Check with clang-format")
16+
arg_parser.add_argument('-i', '--inplace-edit', action='store_true',
17+
help="Edit files inplace")
18+
args = arg_parser.parse_args()
19+
20+
os.chdir(Path(__file__).parent)
21+
22+
# create file containing list of all files to format
23+
filepaths_file = NamedTemporaryFile(delete=False)
24+
for dirpath, dirnames, filenames in os.walk('.'):
25+
for filename in filenames:
26+
# our regexes expect filepath to use forward slash
27+
filepath = Path(dirpath, filename).as_posix()
28+
if not INCLUDE_REGEX.match(filepath):
29+
continue
30+
if EXCLUDE_REGEX.match(filepath):
31+
continue
32+
33+
filepaths_file.write(f"{filepath}\n".encode())
34+
filepaths_file.close()
35+
36+
# use pipx to run clang-format from PyPI
37+
# this is a simple way to run the same clang-format version regardless of OS
38+
cmd = ['pipx', 'run', f'clang-format=={CLANG_FORMAT_VERSION}',
39+
f'--files={filepaths_file.name}']
40+
if args.inplace_edit:
41+
cmd += ['-i']
42+
else:
43+
cmd += ['--Werror', '--dry-run']
44+
45+
print(f"{Path.cwd()}$ {list2cmdline(cmd)}")
46+
if run(cmd).returncode:
47+
exit(1)

format-check.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)