-
Notifications
You must be signed in to change notification settings - Fork 0
/
iwyu_dir_tool.py
34 lines (23 loc) · 939 Bytes
/
iwyu_dir_tool.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
import os
import subprocess
import sys
def print_usage():
print("Usage: " + sys.argv[0] + " /path/to/source/dir")
print(" or: " + sys.argv[0] + " /path/to/source/file.cpp")
if len(sys.argv) != 2:
quit(print_usage())
if not (os.path.isdir(sys.argv[1]) or os.path.isfile(sys.argv[1])):
quit(print_usage())
if os.path.isfile(sys.argv[1]) and not sys.argv[1].endswith('.cpp'):
quit(print_usage())
command_list = ['iwyu_tool.py', '-p', '/scratch/chaste_debug/']
if os.path.isfile(sys.argv[1]):
command_list.append(sys.argv[1])
else:
for root, directory, files in os.walk(sys.argv[1]):
for f in files:
if f.endswith('.cpp'):
command_list.append(os.path.join(root, f))
output_file_name = os.path.join('/tmp/', 'iwyu.out')
subprocess.call(command_list, stderr=open(output_file_name, 'w'))
os.system('fix_includes.py --nocomments --nosafe_headers < ' + output_file_name)