This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
forked from KhronosGroup/SYCL-CTS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clangformat.py
executable file
·61 lines (53 loc) · 1.79 KB
/
clangformat.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# run clang format over all files
#
import os
import subprocess
gClangFormat = 'clang-format'
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# run clang format for the given file
#
def visit_file( afile ):
# construct the command line argument
l_cmd = gClangFormat + ' -style=file -i ' + afile
print(l_cmd)
# run clang format
subprocess.call( l_cmd, shell=True )
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# collect all files in the current directory
#
def walk_dir( a_dirs, a_suffixs ):
l_files = []
# for all given directorys
for l_dir in a_dirs:
# walk every directory
for ( l_dir_path, l_dir_names, l_file_names ) in os.walk( l_dir ):
# convert path specifier
l_dir_path = l_dir_path.replace( '\\', '/' )
# itterate over each file
for l_file_name in l_file_names:
# check if file has suffix
if l_file_name.endswith( a_suffixs ):
# add to list
l_files.append( l_dir_path + '/' + l_file_name )
# return list of matches
return l_files
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# program entry point
#
def main( ):
# collect all files with a given suffix
l_file_list = []
l_file_list.extend( walk_dir( ['util', 'tests'], ( '.cpp', '.h', '.template' ) ))
# itterate over all matches
for l_name in l_file_list:
try:
# try to hash the file
visit_file( l_name )
except Exception as e:
pass
return
# call the entry point
if __name__ == "__main__":
main()