26
26
GITHUB_SHA ,
27
27
make_headers ,
28
28
IS_ON_RUNNER ,
29
+ CACHE_PATH ,
30
+ CLANG_FORMAT_XML ,
31
+ CLANG_TIDY_YML ,
32
+ CLANG_TIDY_STDOUT ,
33
+ CHANGED_FILES_JSON ,
29
34
log_response_msg ,
30
35
range_of_changed_lines ,
31
36
assemble_version_exec ,
@@ -187,7 +192,8 @@ def filter_out_non_source_files(
187
192
Globals .FILES = files
188
193
if not IS_ON_RUNNER : # if not executed on a github runner
189
194
# dump altered json of changed files
190
- Path (".changed_files.json" ).write_text (
195
+ CACHE_PATH .mkdir (exist_ok = True )
196
+ CHANGED_FILES_JSON .write_text (
191
197
json .dumps (Globals .FILES , indent = 2 ),
192
198
encoding = "utf-8" ,
193
199
)
@@ -295,14 +301,15 @@ def run_clang_tidy(
295
301
296
302
cpp-linter --extra-arg=-std=c++14 --extra-arg=-Wall
297
303
"""
304
+ CACHE_PATH .mkdir (exist_ok = True )
298
305
if checks == "-*" : # if all checks are disabled, then clang-tidy is skipped
299
306
# clear the clang-tidy output file and exit function
300
- Path ( "clang_tidy_report.txt" ) .write_bytes (b"" )
307
+ CLANG_TIDY_STDOUT .write_bytes (b"" )
301
308
return
302
309
filename = PurePath (filename ).as_posix ()
303
310
cmds = [
304
311
assemble_version_exec ("clang-tidy" , version ),
305
- "--export-fixes=clang_tidy_output.yml " ,
312
+ f "--export-fixes={ str ( CLANG_TIDY_YML ) } " ,
306
313
]
307
314
if checks :
308
315
cmds .append (f"-checks={ checks } " )
@@ -323,12 +330,12 @@ def run_clang_tidy(
323
330
cmds .append (f"--extra-arg={ extra_arg } " )
324
331
cmds .append (filename )
325
332
# clear yml file's content before running clang-tidy
326
- Path ( "clang_tidy_output.yml" ) .write_bytes (b"" )
333
+ CLANG_TIDY_YML .write_bytes (b"" )
327
334
logger .info ('Running "%s"' , " " .join (cmds ))
328
335
results = subprocess .run (cmds , capture_output = True )
329
- Path ( "clang_tidy_report.txt" ) .write_bytes (results .stdout )
336
+ CLANG_TIDY_STDOUT .write_bytes (results .stdout )
330
337
logger .debug ("Output from clang-tidy:\n %s" , results .stdout .decode ())
331
- if Path ( "clang_tidy_output.yml" ) .stat ().st_size :
338
+ if CLANG_TIDY_YML .stat ().st_size :
332
339
parse_tidy_suggestions_yml () # get clang-tidy fixes from yml
333
340
if results .stderr :
334
341
logger .debug (
@@ -353,8 +360,9 @@ def run_clang_format(
353
360
:param lines_changed_only: A flag that forces focus on only changes in the event's
354
361
diff info.
355
362
"""
363
+ CACHE_PATH .mkdir (exist_ok = True )
356
364
if not style : # if `style` == ""
357
- Path ( "clang_format_output.xml" ) .write_bytes (b"" )
365
+ CLANG_FORMAT_XML .write_bytes (b"" )
358
366
return # clear any previous output and exit
359
367
cmds = [
360
368
assemble_version_exec ("clang-format" , version ),
@@ -370,7 +378,7 @@ def run_clang_format(
370
378
cmds .append (PurePath (filename ).as_posix ())
371
379
logger .info ('Running "%s"' , " " .join (cmds ))
372
380
results = subprocess .run (cmds , capture_output = True )
373
- Path ( "clang_format_output.xml" ) .write_bytes (results .stdout )
381
+ CLANG_FORMAT_XML .write_bytes (results .stdout )
374
382
if results .returncode :
375
383
logger .debug (
376
384
"%s raised the following error(s):\n %s" , cmds [0 ], results .stderr .decode ()
@@ -394,7 +402,7 @@ def create_comment_body(
394
402
`make_annotations()` after `capture_clang_tools_output()` is finished.
395
403
"""
396
404
ranges = range_of_changed_lines (file_obj , lines_changed_only )
397
- if Path ( "clang_tidy_report.txt" ) .stat ().st_size :
405
+ if CLANG_TIDY_STDOUT . exists () and CLANG_TIDY_STDOUT .stat ().st_size :
398
406
parse_tidy_output () # get clang-tidy fixes from stdout
399
407
comment_output = ""
400
408
if Globals .PAYLOAD_TIDY :
@@ -409,7 +417,7 @@ def create_comment_body(
409
417
Globals .PAYLOAD_TIDY += comment_output
410
418
GlobalParser .tidy_notes .clear () # empty list to avoid duplicated output
411
419
412
- if Path ( "clang_format_output.xml" ) .stat ().st_size :
420
+ if CLANG_FORMAT_XML . exists () and CLANG_FORMAT_XML .stat ().st_size :
413
421
parse_format_replacements_xml (PurePath (filename ).as_posix ())
414
422
if GlobalParser .format_advice and GlobalParser .format_advice [- 1 ].replaced_lines :
415
423
should_comment = lines_changed_only == 0
0 commit comments