@@ -56,6 +56,8 @@ def __init__(self, analyzers, output_path, config_map,
56
56
self .__stats_dir = statistics_data ['stats_out_dir' ]
57
57
58
58
self .__makefile = os .path .join (output_path , 'Makefile' )
59
+ self .__stat_sh = os .path .join (output_path , 'print_stat.sh' )
60
+ self .__exit_codes_dir = os .path .join (output_path , 'exit_codes' )
59
61
60
62
self .__config = None
61
63
self .__func_map_cmd = None
@@ -110,13 +112,51 @@ def __write_default_targets(self, mfile):
110
112
analyzer.
111
113
"""
112
114
mfile .write ("# Default target to run all analysis.\n "
113
- "default: all\n \n " )
115
+ "default: create_exit_code_folder all\n "
116
+ f"\t @bash { self .__stat_sh } \n "
117
+ f"\t @rm -rf { self .__exit_codes_dir } \n \n "
118
+ "# Folder for creating exit codes of analyses.\n "
119
+ "create_exit_code_folder:\n "
120
+ f"\t @rm -rf { self .__exit_codes_dir } \n "
121
+ f"\t @mkdir { self .__exit_codes_dir } \n \n " )
114
122
115
123
for analyzer in self .__analyzers :
116
124
analyzer_name = self .__format_analyzer_type (analyzer )
117
125
mfile .write (f"# Target to run only '{ analyzer_name } ' analysis.\n "
118
126
f"all: all_{ analyzer_name } \n \n " )
119
127
128
+ def __write_print_stats (self , sfile ):
129
+ """ Write target to print analyzer statistics.
130
+
131
+ At the end of the analysis the Makefile should print statistics about
132
+ how many actions were analyzed by the specific analyzers.
133
+ """
134
+ sfile .write (f'''#!/usr/bin/env bash
135
+ declare -A success
136
+ declare -A all
137
+ sum=0
138
+
139
+ for filename in $(ls { self .__exit_codes_dir } ); do
140
+ success[$filename]=$(grep ^0$ { self .__exit_codes_dir } /$filename | wc -l)
141
+ all[$filename]=$(wc -l < { self .__exit_codes_dir } /$filename)
142
+ sum=$(($sum + ${{all[$filename]}}))
143
+ done
144
+
145
+ echo "----==== Summary ====----"
146
+
147
+ echo "Successfully analyzed"
148
+ for analyzer in "${{!success[@]}}"; do
149
+ echo $analyzer: ${{success[$analyzer]}}
150
+ done
151
+
152
+ echo "Failed to analyze"
153
+ for analyzer in "${{!success[@]}}"; do
154
+ echo $analyzer: $((${{all[$analyzer]}} - ${{success[$analyzer]}}))
155
+ done
156
+
157
+ echo "Total analyzed compilation commands: $sum"
158
+ echo "----=================----"''' )
159
+
120
160
def __get_ctu_pre_analysis_cmds (self , action ):
121
161
""" Get CTU pre-analysis commands. """
122
162
cmds = []
@@ -238,6 +278,9 @@ def __write_analysis_targets(self, mfile, action, post_pre_all_target):
238
278
target = self .__get_target_name (action )
239
279
analyzer_name = self .__format_analyzer_type (action .analyzer_type )
240
280
281
+ save_exit_code = \
282
+ f"; echo $$? >> { self .__exit_codes_dir } /{ action .analyzer_type } "
283
+
241
284
if action .analyzer_type == ClangTidy .ANALYZER_NAME :
242
285
analyzer_output_file = rh .analyzer_result_file + ".output"
243
286
file_name = "{source_file}_{analyzer}_" + target
@@ -247,11 +290,12 @@ def __write_analysis_targets(self, mfile, action, post_pre_all_target):
247
290
"--filename" , file_name ,
248
291
analyzer_output_file ]
249
292
250
- command = f"@{ ' ' .join (analyzer_cmd )} > { analyzer_output_file } \n " \
293
+ command = f"@{ ' ' .join (analyzer_cmd )} > " \
294
+ f"{ analyzer_output_file } { save_exit_code } \n " \
251
295
f"\t @{ ' ' .join (report_converter_cmd )} 1>/dev/null\n " \
252
296
f"\t @rm -rf { analyzer_output_file } \n "
253
297
else :
254
- command = f"@{ ' ' .join (analyzer_cmd )} 1>/dev/null"
298
+ command = f"@{ ' ' .join (analyzer_cmd )} 1>/dev/null{ save_exit_code } "
255
299
256
300
mfile .write (
257
301
f'{ target } : { post_pre_all_target } \n '
@@ -265,6 +309,10 @@ def create(self, actions):
265
309
LOG .info ("Creating Makefile from the analyzer commands: '%s'..." ,
266
310
self .__makefile )
267
311
312
+ with open (self .__stat_sh , 'w+' ,
313
+ encoding = 'utf-8' , errors = 'ignore' ) as sfile :
314
+ self .__write_print_stats (sfile )
315
+
268
316
with open (self .__makefile , 'w+' ,
269
317
encoding = 'utf-8' , errors = 'ignore' ) as mfile :
270
318
self .__write_header (mfile )
0 commit comments