Skip to content

Commit

Permalink
Add single plist option
Browse files Browse the repository at this point in the history
This patch adds the logic of report output merging into one singluar
`.plist` file. Now analyze and check can be invoked with the
`--plist-file-name` option, which if provided will merge all new
`.plist` result files into the specified file name under the specified
output report folder.
  • Loading branch information
vodorok committed Oct 14, 2024
1 parent 6553578 commit ea1d3c0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
32 changes: 28 additions & 4 deletions analyzer/codechecker_analyzer/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
import traceback
import zipfile

from pathlib import Path
from threading import Timer

import multiprocess
import psutil

import plistlib

from codechecker_common.logger import get_logger
from codechecker_common.review_status_handler import ReviewStatusHandler

Expand Down Expand Up @@ -57,8 +60,29 @@ def print_analyzer_statistic_summary(metadata_analyzers, status, msg=None):
LOG.info(" %s: %s", analyzer_type, res)


def worker_result_handler(results, metadata_tool, output_path):
""" Print the analysis summary. """
def worker_result_handler(results, metadata_tool, output_path, plist_file_name):
"""
Handle analysis results after all the analyzer threads returned. It may
merge all the plist output files into one, and print the analysis summary.
"""
LOG.info("Merging plist files into %s", plist_file_name)
if plist_file_name:
plist_data = []
single_plist = Path(output_path, plist_file_name)
for _, _, _, _, original_plist, _ in results:
original_plist = Path(original_plist)
if os.path.exists(original_plist):
with open(original_plist, 'rb') as plist:
LOG.debug(f"Merging original plist {original_plist}")
plist_data.append(plistlib.load(plist))

with open(single_plist, 'wb') as plist:
LOG.debug(f"Dumping merged plist file into {single_plist}")
plistlib.dump(plist_data, plist)

LOG.debug(f"Removing original plist file {original_plist}")
original_plist.unlink()

skipped_num = 0
reanalyzed_num = 0
metadata_analyzers = metadata_tool['analyzers']
Expand Down Expand Up @@ -719,7 +743,7 @@ def skip_cpp(compile_actions, skip_handlers):


def start_workers(actions_map, actions, analyzer_config_map,
jobs, output_path, skip_handlers,
jobs, output_path, plist_file_name, skip_handlers,
rs_handler: ReviewStatusHandler, metadata_tool,
quiet_analyze, capture_analysis_output, generate_reproducer,
timeout, ctu_reanalyze_on_failure, statistics_data, manager,
Expand Down Expand Up @@ -813,7 +837,7 @@ def signal_handler(signum, _):
analyzed_actions,
1,
callback=lambda results: worker_result_handler(
results, metadata_tool, output_path)
results, metadata_tool, output_path, plist_file_name)
).get(timeout)

pool.close()
Expand Down
1 change: 1 addition & 0 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
analysis_manager.start_workers(actions_map, actions,
config_map, args.jobs,
args.output_path,
args.plist_file_name,
skip_handlers,
rs_handler,
metadata_tool,
Expand Down
9 changes: 9 additions & 0 deletions analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ def add_arguments_to_parser(parser):
default=argparse.SUPPRESS,
help="Store the analysis output in the given folder.")

parser.add_argument('--plist-file-name',
type=str,
dest="plist_file_name",
required=False,
help="If given, all the `.plist` files containing "
"the analyzer result files will be merged "
"into a single `.plist` file in the report "
"output folder given by `-o/--output`.")

parser.add_argument('--compiler-info-file',
dest="compiler_info_file",
required=False,
Expand Down
9 changes: 9 additions & 0 deletions analyzer/codechecker_analyzer/cmd/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ def add_arguments_to_parser(parser):
"If it is not given then the results go into a "
"temporary directory which will be removed after "
"the analysis.")

parser.add_argument('--plist-file-name',
type=str,
dest="plist_file_name",
required=False,
help="If given, all the `.plist` files containing "
"the analyzer result files will be merged "
"into a single `.plist` file in the report "
"output folder given by `-o/--output`.")

parser.add_argument('-t', '--type', '--output-format',
dest="output_format",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,25 @@ def get_reports(
if not plist:
return reports

metadata = plist.get('metadata')
if not isinstance(plist, list):
plist=[plist]

files = get_file_index_map(
plist, source_dir_path, self._file_cache)
for sub_plist in plist:

for diag in plist.get('diagnostics', []):
report = self.__create_report(
analyzer_result_file_path, diag, files, metadata)
metadata = sub_plist.get('metadata')

if report.report_hash is None:
report.report_hash = get_report_hash(
report, HashType.PATH_SENSITIVE)
files = get_file_index_map(
sub_plist, source_dir_path, self._file_cache)

for diag in sub_plist.get('diagnostics', []):
report = self.__create_report(
analyzer_result_file_path, diag, files, metadata)

if report.report_hash is None:
report.report_hash = get_report_hash(
report, HashType.PATH_SENSITIVE)

reports.append(report)
reports.append(report)
except KeyError as ex:
LOG.warning("Failed to get file path id! Found files: %s. "
"KeyError: %s", files, ex)
Expand Down

0 comments on commit ea1d3c0

Please sign in to comment.