-
Notifications
You must be signed in to change notification settings - Fork 329
/
clang-format.py
executable file
·30 lines (26 loc) · 1.18 KB
/
clang-format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
import os
import sys
import argparse
import subprocess
path_list = ['bytehook/src/main/cpp/include',
'bytehook/src/main/cpp',
'bytehook_systest/src/main/cpp',
'bytehook_sample/src/main/cpp']
suffix_tuple = ('.h', '.c')
def main():
parser = argparse.ArgumentParser(description='clang-format runner')
parser.add_argument('-n', '--dry-run', action='store_true', help='If set, do not actually make the formatting changes')
options = parser.parse_args()
dry_run = '-n ' if options.dry_run else ''
for path in path_list:
for filename in sorted(os.listdir(path)):
f = os.path.join(path, filename)
if os.path.isfile(f) and f.endswith(suffix_tuple):
cmd = 'clang-format ' + dry_run + '--Werror -i -style=file ' + f
ret = subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
retcode = ('' if ret.returncode == 0 else (' >>> return code: ' + str(ret.returncode)))
print('>>> ' + cmd + retcode)
print(ret.stdout, end='')
if __name__ == '__main__':
sys.exit(main())