Skip to content

Commit 71a915a

Browse files
committed
Adding a --filter post-processing step to analyze
The report filtering post processing step was removed as part of the --skip SKIPFILE parameter and was separated out to a --filter SKIPFILE parameter. This way the reports are not skipped as a post processing step by default.
1 parent 6123768 commit 71a915a

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

analyzer/codechecker_analyzer/analysis_manager.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def prepare_check(action, analyzer_config, output_dir,
216216

217217

218218
def handle_success(
219-
rh, result_file, result_base, skip_handlers,
219+
rh, result_file, result_base, skip_handlers, filter_handlers,
220220
rs_handler: ReviewStatusHandler,
221221
capture_analysis_output, success_dir
222222
):
@@ -230,7 +230,7 @@ def handle_success(
230230
save_output(os.path.join(success_dir, result_base),
231231
rh.analyzer_stdout, rh.analyzer_stderr)
232232

233-
rh.postprocess_result(skip_handlers, rs_handler)
233+
rh.postprocess_result(filter_handlers, rs_handler)
234234

235235
# Generated reports will be handled separately at store.
236236

@@ -487,7 +487,8 @@ def check(check_data):
487487
skiplist handler is None if no skip file was configured.
488488
"""
489489
actions_map, action, analyzer_config, \
490-
output_dir, skip_handlers, rs_handler, quiet_output_on_stdout, \
490+
output_dir, skip_handlers, filter_handlers, \
491+
rs_handler, quiet_output_on_stdout, \
491492
capture_analysis_output, generate_reproducer, analysis_timeout, \
492493
ctu_reanalyze_on_failure, \
493494
output_dirs, statistics_data = check_data
@@ -605,7 +606,7 @@ def handle_analysis_result(success, zip_file=zip_file):
605606

606607
if success:
607608
handle_success(rh, result_file, result_base,
608-
skip_handlers, rs_handler,
609+
skip_handlers, filter_handlers, rs_handler,
609610
capture_analysis_output, success_dir)
610611
elif not generate_reproducer:
611612
handle_failure(source_analyzer, rh,
@@ -719,7 +720,7 @@ def skip_cpp(compile_actions, skip_handlers):
719720

720721

721722
def start_workers(actions_map, actions, analyzer_config_map,
722-
jobs, output_path, skip_handlers,
723+
jobs, output_path, skip_handlers, filter_handlers,
723724
rs_handler: ReviewStatusHandler, metadata_tool,
724725
quiet_analyze, capture_analysis_output, generate_reproducer,
725726
timeout, ctu_reanalyze_on_failure, statistics_data, manager,
@@ -785,6 +786,7 @@ def signal_handler(signum, _):
785786
analyzer_config_map.get(build_action.analyzer_type),
786787
output_path,
787788
skip_handlers,
789+
filter_handlers,
788790
rs_handler,
789791
quiet_analyze,
790792
capture_analysis_output,

analyzer/codechecker_analyzer/analyzer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def __has_enabled_checker(ch: AnalyzerConfigHandler):
130130
for _, (state, _) in ch.checks().items())
131131

132132

133-
def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
133+
def perform_analysis(args, skip_handlers, filter_handlers,
134+
rs_handler: ReviewStatusHandler,
134135
actions, metadata_tool, compile_cmd_count):
135136
"""
136137
Perform static analysis via the given (or if not, all) analyzers,
@@ -335,6 +336,7 @@ def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
335336
config_map, args.jobs,
336337
args.output_path,
337338
skip_handlers,
339+
filter_handlers,
338340
rs_handler,
339341
metadata_tool,
340342
'quiet' in args,

analyzer/codechecker_analyzer/cmd/analyze.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ def add_arguments_to_parser(parser):
183183
"Please consult the User guide on how a "
184184
"Skipfile should be laid out.")
185185

186+
skip_mode.add_argument('--filter',
187+
dest="filterfile",
188+
required=False,
189+
default=argparse.SUPPRESS,
190+
help="Path to the Skipfile dictating which reports "
191+
"should be filtered out from the result set in a "
192+
"post processing step. "
193+
"Please consult the User guide on how a "
194+
"Skipfile should be laid out.")
195+
186196
skip_mode.add_argument('--file',
187197
nargs='+',
188198
dest="files",
@@ -950,6 +960,21 @@ def __get_skip_handlers(args, compile_commands) -> SkipListHandlers:
950960
return skip_handlers
951961

952962

963+
def __get_filter_handlers(args, compile_commands) -> SkipListHandlers:
964+
"""
965+
Initialize and return a list of skiplist handlers if
966+
there is a filter list file in the arguments or files options is provided.
967+
"""
968+
filter_handlers = SkipListHandlers()
969+
if 'filterfile' in args:
970+
with open(args.filterfile, encoding="utf-8", errors="ignore") as f:
971+
content = f.read()
972+
filter_handlers.append(SkipListHandler(content))
973+
LOG.debug("Filter handler is created for the '--filter' option with "
974+
"the following filters:\n%s", content)
975+
976+
return filter_handlers
977+
953978
def __update_skip_file(args):
954979
"""
955980
Remove previous skip file if there was any.
@@ -1097,8 +1122,11 @@ def main(args):
10971122
LOG.error(f"Found no compilation commands in '{args.input}'")
10981123
sys.exit(1)
10991124

1100-
# Process the skip list if present.
1125+
# Process the skip list if present. This will filter out analysis actions.
11011126
skip_handlers = __get_skip_handlers(args, compile_commands)
1127+
# Process the filter list if present. This will filter out successful reports.
1128+
filter_handlers = __get_filter_handlers(args, compile_commands)
1129+
11021130
rs_handler = review_status_handler.ReviewStatusHandler(args.output_path)
11031131

11041132
try:
@@ -1244,7 +1272,7 @@ def main(args):
12441272
LOG.debug_analyzer("Compile commands forwarded for analysis: %d",
12451273
compile_cmd_count.analyze)
12461274

1247-
analyzer.perform_analysis(args, skip_handlers, rs_handler, actions,
1275+
analyzer.perform_analysis(args, skip_handlers,filter_handlers, rs_handler, actions,
12481276
metadata_tool, compile_cmd_count)
12491277

12501278
__update_skip_file(args)

analyzer/codechecker_analyzer/cmd/check.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def add_arguments_to_parser(parser):
275275
"more information.\n"
276276
"USE WISELY AND AT YOUR OWN RISK!")
277277

278-
skip_mode = analyzer_opts.add_mutually_exclusive_group()
278+
skip_mode = parser.add_argument_group("file filter arguments")
279279
skip_mode.add_argument('-i', '--ignore', '--skip',
280280
dest="skipfile",
281281
required=False,
@@ -285,6 +285,16 @@ def add_arguments_to_parser(parser):
285285
"Please consult the User guide on how a "
286286
"Skipfile should be laid out.")
287287

288+
skip_mode.add_argument('--filter',
289+
dest="filterfile",
290+
required=False,
291+
default=argparse.SUPPRESS,
292+
help="Path to the Skipfile dictating which reports "
293+
"should be filtered out from the result set in a "
294+
"post processing step. "
295+
"Please consult the User guide on how a "
296+
"Skipfile should be laid out.")
297+
288298
skip_mode.add_argument('--file',
289299
nargs='+',
290300
dest="files",
@@ -881,6 +891,7 @@ def __update_if_key_exists(source, target, key):
881891
# after the call.
882892
args_to_update = ['quiet',
883893
'skipfile',
894+
'filterfile',
884895
'files',
885896
'analyzers',
886897
'add_compiler_defaults',

0 commit comments

Comments
 (0)