@@ -51,42 +51,38 @@ def find_program(names):
51
51
@click .command ()
52
52
@click .option (
53
53
'--log-level' ,
54
- default = 'INFO' ,
54
+ show_default = True ,
55
+ default = 'info' ,
55
56
type = click .Choice (__LOG_LEVELS__ .keys (), case_sensitive = False ),
56
- help = 'Determines the verbosity of script output.' )
57
+ help = 'Set the verbosity of script output.' )
57
58
@click .option (
58
59
'--no-log-timestamps' ,
59
60
default = False ,
60
61
is_flag = True ,
61
- help = 'Skip timestamps in log output' )
62
+ help = 'Skip timestamps in log output. ' )
62
63
@click .option (
63
64
'--compile-commands-glob' ,
64
65
show_default = True ,
65
- default = os .path .join (proj_root_dir , "out" , "debug" , "compile_commands*.json" ),
66
- help = 'Set global pattern for compile_commands.json files'
67
- )
68
- @click .option (
69
- '--scanning-destination' ,
70
- show_default = True ,
71
- default = os .path .join (proj_root_dir , "src" , "platform" ),
72
- help = 'Set scanning destination file(s) or directory /ies in project'
73
- )
66
+ default = os .path .join (proj_root_dir , "out" , "debug" ,
67
+ "compile_commands*.json" ),
68
+ help = 'Set global pattern for compile_commands.json files.' )
74
69
@click .option (
75
70
'--mapping-file-dir' ,
76
- help = 'Set mapping file directory /ies manually. File should have name iwyu.imp'
77
- )
71
+ help = 'Set directory with iwyu.imp mapping file.' )
78
72
@click .option (
79
73
'--iwyu-args' ,
80
74
show_default = True ,
81
75
default = "-Xiwyu --no_fwd_decls" ,
82
- help = 'Set custom arg(s) for include what you use'
83
- )
76
+ help = 'Set custom arg(s) for include what you use.' )
84
77
@click .option (
85
78
'--clang-args' ,
86
79
default = "" ,
87
- help = 'Set custom arg(s) for clang'
88
- )
89
- def main (compile_commands_glob , scanning_destination , mapping_file_dir ,
80
+ help = 'Set custom arg(s) for clang.' )
81
+ @click .argument (
82
+ 'source' ,
83
+ nargs = - 1 ,
84
+ type = click .Path (exists = True ))
85
+ def main (compile_commands_glob , source , mapping_file_dir ,
90
86
iwyu_args , clang_args , log_level , no_log_timestamps ):
91
87
# Ensures somewhat pretty logging of what is going on
92
88
log_fmt = '%(asctime)s %(levelname)-7s %(message)s'
@@ -114,8 +110,10 @@ def main(compile_commands_glob, scanning_destination, mapping_file_dir,
114
110
for compile_commands in compile_commands_glob :
115
111
116
112
compile_commands_path = os .path .dirname (compile_commands )
117
- compile_commands_file = os .path .join (compile_commands_path , "compile_commands.json" )
118
- logging .debug ("Copy compile command file %s to %s" , compile_commands , compile_commands_file )
113
+ compile_commands_file = os .path .join (
114
+ compile_commands_path , "compile_commands.json" )
115
+ logging .debug ("Copy compile command file %s to %s" ,
116
+ compile_commands , compile_commands_file )
119
117
120
118
with contextlib .suppress (shutil .SameFileError ):
121
119
shutil .copyfile (compile_commands , compile_commands_file )
@@ -153,14 +151,14 @@ def main(compile_commands_glob, scanning_destination, mapping_file_dir,
153
151
154
152
command_arr = [
155
153
iwyu ,
156
- "-p" , compile_commands_path , scanning_destination ,
154
+ "-p" , compile_commands_path , * source ,
157
155
"--" , iwyu_args ,
158
156
"-Xiwyu" , "--mapping_file=" + mapping_file_dir + "/iwyu.imp" ,
159
157
] + platform_clang_args + [clang_args ]
160
158
161
159
logging .info ("Used compile commands: %s" , compile_commands )
162
160
logging .info ("Scanning includes for platform: %s" , platform )
163
- logging .info ("Scanning destination : %s" , scanning_destination )
161
+ logging .info ("Scanning sources(s) : %s" , ", " . join ( source ) )
164
162
165
163
logging .debug ("Command: %s" , " " .join (command_arr ))
166
164
status = subprocess .Popen (" " .join (command_arr ),
@@ -175,13 +173,13 @@ def main(compile_commands_glob, scanning_destination, mapping_file_dir,
175
173
for line in status .stdout :
176
174
line = line .rstrip ()
177
175
178
- if re .match (r"^warning:.*$ " , line ):
176
+ if re .search (r"^warning:" , line ):
179
177
logger = logging .warning
180
- elif re .match (r"^.*([A-Za-z0-9]+(/[A-Za-z0-9]+)+)\.cpp should [a-zA-Z]+ these lines:$" , line ):
178
+ elif re .search (r"should (add|remove)? these lines:$" , line ):
181
179
logger = logging .warning
182
- elif re .match (r"^.*([A-Za-z0-9]+(/[A-Za-z0-9]+)+)\.[a-zA-Z]+ has correct #includes/fwd-decls\)$" , line ):
180
+ elif re .search (r"has correct #includes/fwd-decls\)$" , line ):
183
181
logger = logging .info
184
- elif re .match (r"^The full include-list for .*$ " , line ):
182
+ elif re .search (r"^The full include-list for" , line ):
185
183
logger = logging .warning
186
184
warning_in_files += 1
187
185
@@ -190,7 +188,8 @@ def main(compile_commands_glob, scanning_destination, mapping_file_dir,
190
188
logging .info ("============== IWYU output end ================" )
191
189
192
190
if warning_in_files :
193
- logging .error ("Number of files with include issues: %d" , warning_in_files )
191
+ logging .error ("Number of files with include issues: %d" ,
192
+ warning_in_files )
194
193
sys .exit (2 )
195
194
else :
196
195
logging .info ("Every include looks good!" )
0 commit comments