Skip to content

Commit 6971859

Browse files
committed
Adding a --drop-reports-from-skipped-files parameter to analyze
The report filtering post processing step was removed as part of the --skip SKIPFILE parameter and was separated out to a --drop-reports-from-skipped-files paramer. This way the reports are not skipped as a post processing step by default. With the argument set to true the legacy behaviour is triggered that is all reports from the files which are skipped from the analysis are dropped.
1 parent 6123768 commit 6971859

File tree

6 files changed

+79
-11
lines changed

6 files changed

+79
-11
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, 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+
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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ 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('--drop-reports-from-skipped-files',
187+
dest="drop_skipped_reports",
188+
required=False,
189+
action='store_true',
190+
default=False,
191+
help="Filter our reports from files that were "
192+
"skipped from the analysis.")
193+
186194
skip_mode.add_argument('--file',
187195
nargs='+',
188196
dest="files",
@@ -1097,8 +1105,13 @@ def main(args):
10971105
LOG.error(f"Found no compilation commands in '{args.input}'")
10981106
sys.exit(1)
10991107

1100-
# Process the skip list if present.
1108+
# Process the skip list if present. This will filter out analysis actions.
11011109
skip_handlers = __get_skip_handlers(args, compile_commands)
1110+
# Post processin filters
1111+
filter_handlers = None
1112+
if ('drop_skipped_reports' in args and args.drop_skipped_reports):
1113+
filter_handlers = skip_handlers
1114+
11021115
rs_handler = review_status_handler.ReviewStatusHandler(args.output_path)
11031116

11041117
try:
@@ -1244,8 +1257,9 @@ def main(args):
12441257
LOG.debug_analyzer("Compile commands forwarded for analysis: %d",
12451258
compile_cmd_count.analyze)
12461259

1247-
analyzer.perform_analysis(args, skip_handlers, rs_handler, actions,
1248-
metadata_tool, compile_cmd_count)
1260+
analyzer.perform_analysis(args, skip_handlers, filter_handlers,
1261+
rs_handler, actions, metadata_tool,
1262+
compile_cmd_count)
12491263

12501264
__update_skip_file(args)
12511265
__update_review_status_config(args)

analyzer/codechecker_analyzer/cmd/check.py

Lines changed: 10 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,14 @@ 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('--drop-reports-from-skipped-files',
289+
dest="drop_skipped_reports",
290+
required=False,
291+
action='store_true',
292+
default=False,
293+
help="Filter our reports from files that were "
294+
"skipped from the analysis.")
295+
288296
skip_mode.add_argument('--file',
289297
nargs='+',
290298
dest="files",
@@ -881,6 +889,7 @@ def __update_if_key_exists(source, target, key):
881889
# after the call.
882890
args_to_update = ['quiet',
883891
'skipfile',
892+
'drop_skipped_reports',
884893
'files',
885894
'analyzers',
886895
'add_compiler_defaults',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-*file_to_be_skipped.cpp

analyzer/tests/functional/skip/test_skip.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,47 @@ def __run_parse(self, extra_options=None):
136136

137137
def test_skip(self):
138138
"""Analyze a project with a skip file."""
139-
self.__log_and_analyze_simple(["--ignore", "skipfile"])
139+
# we should see a report from skip.h
140+
# we should not see a report from file_to_be_skipped.cpp
141+
self.__log_and_analyze_simple(["--ignore", "skipfile_drop"])
142+
143+
# Check if file is skipped.
144+
report_dir_files = os.listdir(self.report_dir)
145+
for f in report_dir_files:
146+
self.assertFalse("file_to_be_skipped.cpp" in f)
147+
148+
# Check if report from the report file is removed.
149+
report_dir_files = os.listdir(self.report_dir)
150+
report_file_to_check = None
151+
for f in report_dir_files:
152+
if "skip_header.cpp" in f:
153+
report_file_to_check = os.path.join(self.report_dir, f)
154+
break
155+
156+
self.assertIsNotNone(report_file_to_check,
157+
"Report file should be generated.")
158+
report_data = {}
159+
with open(report_file_to_check, 'rb') as plist_file:
160+
report_data = plistlib.load(plist_file)
161+
files = report_data['files']
162+
163+
skipped_file_index = None
164+
for i, f in enumerate(files):
165+
if "skip.h" in f:
166+
skipped_file_index = i
167+
break
168+
169+
self.assertNotEqual(skipped_file_index, None,
170+
"Reports from headers should be kept"
171+
" if the header is not on the skiplist")
172+
173+
def test_drop_reports(self):
174+
"""Analyze a project with a skip file."""
175+
# we should not see a report from skip.h
176+
# we should not see a report from file_to_be_skipped.cpp
177+
178+
self.__log_and_analyze_simple(["--ignore", "skipfile",
179+
"--drop-reports-from-skipped-files"])
140180

141181
# Check if file is skipped.
142182
report_dir_files = os.listdir(self.report_dir)

0 commit comments

Comments
 (0)