@@ -54,10 +54,12 @@ def check_duplicate_occurences(occurences):
54
54
55
55
56
56
def check_unlogged_messages (messages , autofix ):
57
- all_source_files = set (pathlib .Path ('.' ).glob ('**/*.cc' )) \
58
- - set (pathlib .Path ('.' ).glob ('**/*messages.cc' )) \
59
- | set (pathlib .Path ('.' ).glob ('**/*.h' )) \
60
- - set (pathlib .Path ('.' ).glob ('**/*messages.h' ))
57
+ parent_dir = os .path .dirname (os .path .realpath (os .path .abspath (sys .argv [0 ])))
58
+ root_dir = f'{ parent_dir } /..'
59
+ all_source_files = set (pathlib .Path (root_dir ).glob ('**/*.cc' )) \
60
+ - set (pathlib .Path (root_dir ).glob ('**/*messages.cc' )) \
61
+ | set (pathlib .Path (root_dir ).glob ('**/*.h' )) \
62
+ - set (pathlib .Path (root_dir ).glob ('**/*messages.h' ))
61
63
all_source_code = ''
62
64
for file in all_source_files :
63
65
with open (file , 'r' , encoding = 'utf-8' ) as f :
@@ -216,6 +218,8 @@ def main():
216
218
formatter_class = argparse .RawTextHelpFormatter )
217
219
parser .add_argument ('-a' , '--autofix' , action = 'store_true' ,
218
220
help = 'Autofix unused messages and debug log levels in docs.' )
221
+ parser .add_argument ('-g' , '--generate-debug-messages-page' , action = 'store_true' ,
222
+ help = 'Generate the debug-messages.rst file included in the ARM.' )
219
223
args = parser .parse_args ()
220
224
221
225
# Initializations
@@ -229,7 +233,9 @@ def main():
229
233
log_pattern = re .compile (r'\b(LOG_DEBUG|LOG_ERROR|LOG_FATAL|LOG_INFO|LOG_WARN)\(' )
230
234
231
235
# Process .mes files.
232
- mes_files = sorted (pathlib .Path ('.' ).glob ('**/*.mes' ))
236
+ parent_dir = os .path .dirname (os .path .realpath (os .path .abspath (sys .argv [0 ])))
237
+ root_dir = f'{ parent_dir } /..'
238
+ mes_files = sorted (pathlib .Path (root_dir ).glob ('**/*.mes' ))
233
239
for mes_file in mes_files :
234
240
with open (mes_file , 'r' , encoding = 'utf-8' ) as f :
235
241
current_message_id = None
@@ -265,8 +271,8 @@ def main():
265
271
}
266
272
267
273
# Process .cc and .h files.
268
- cc_files = sorted (pathlib .Path ('.' ).glob ('**/*.cc' ))
269
- h_files = sorted (pathlib .Path ('.' ).glob ('**/*.h' ))
274
+ cc_files = sorted (pathlib .Path (root_dir ).glob ('**/*.cc' ))
275
+ h_files = sorted (pathlib .Path (root_dir ).glob ('**/*.h' ))
270
276
cpp_files = cc_files + h_files
271
277
for cpp_file in cpp_files :
272
278
# Skip test files.
@@ -327,6 +333,11 @@ def main():
327
333
for level in debug_levels :
328
334
debug_levels [level ] = int (debug_levels [level ])
329
335
336
+ if args .autofix or args .generate_debug_messages_page :
337
+ generate_page_with_messages_printed_on_each_debug_level (messages , debug_levels )
338
+ if args .generate_debug_messages_page :
339
+ return
340
+
330
341
# Get number of occurences for each message id.
331
342
for line in log_lines :
332
343
pos = 1
@@ -354,9 +365,6 @@ def main():
354
365
# 7. Checks that the placeholder ids are consecutive, starting with 1, and unique in the same message definition.
355
366
failure |= check_placeholder_ids (messages )
356
367
357
- if args .autofix :
358
- generate_page_with_messages_printed_on_each_debug_level (messages , debug_levels )
359
-
360
368
if failure :
361
369
sys .exit (1 )
362
370
0 commit comments