Skip to content

Commit

Permalink
Avoid plist filenames being the same
Browse files Browse the repository at this point in the history
This makes the filenames of plist format reports generated by
report-converter include the file hash as well as the file name,
since before if two different plist files had the same name there
was only one of the reports in the database. Fixes Ericsson#3436 .
  • Loading branch information
milanlakhani committed Feb 3, 2022
1 parent 2c49428 commit 16244e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
17 changes: 9 additions & 8 deletions docs/tools/report-converter.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ optional arguments:
file name output of this tool. This tool can produce
multiple plist files on the given code analyzer output
result file. The problem is if we run this tool
multiple times on the same directory, it may override
some plist files. To prevent this we can generate a
unique hash into the plist file names with this
option. For example: '{source_file}_{analyzer}_xxxxx'.
{source_file} and {analyzer} are special values which
will be replaced with the current analyzer and source
file name where the bug was found. (default:
{source_file}_{analyzer})
multiple times on the same file, it may override some
plist files. To prevent this we can generate a unique
hash into the plist file names with this option. For
example: '{source_file}_{analyzer}_{file_hash}_xxxxx'.
{source_file}, {analyzer} and {file_hash} are special
values which will be replaced with the current
analyzer, source file name and hash of the absolute
file path where the bug was found. (default:
{source_file}_{analyzer}_{file_hash})
-c, --clean Delete files stored in the output directory. (default:
False)
-v, --verbose Set verbosity level. (default: False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from abc import ABCMeta, abstractmethod
from collections import defaultdict
import hashlib
from typing import Dict, List, Optional

from codechecker_report_converter.report import Report, report_file
Expand Down Expand Up @@ -39,7 +40,7 @@ def transform(
analyzer_result_file_path: str,
output_dir_path: str,
export_type: str,
file_name: str = "{source_file}_{analyzer}",
file_name: str = "{source_file}_{analyzer}_{file_hash}",
metadata: Optional[Dict[str, str]] = None
) -> bool:
"""
Expand Down Expand Up @@ -143,15 +144,19 @@ def _write(

file_to_report: Dict[str, List[Report]] = defaultdict(list)
for report in reports:
file_to_report[report.file.original_path].append(report)
file_path = os.path.normpath(report.file.original_path)
file_to_report[file_path].append(report)

analyzer_info = AnalyzerInfo(name=self.TOOL_NAME)
for file_path, file_reports in file_to_report.items():
source_file = os.path.basename(file_path)
file_hash = hashlib.md5(file_path.encode(errors='ignore')) \
.hexdigest()

out_file_name = file_name \
.replace("{source_file}", source_file) \
.replace("{analyzer}", self.TOOL_NAME)
.replace("{analyzer}", self.TOOL_NAME) \
.replace("{file_hash}", file_hash)
out_file_name = f"{out_file_name}.{export_type}"
out_file_path = os.path.join(output_dir, out_file_name)

Expand Down
20 changes: 11 additions & 9 deletions tools/report-converter/codechecker_report_converter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,22 @@ def __add_arguments_to_parser(parser):
type=str,
dest='filename',
metavar='FILENAME',
default="{source_file}_{analyzer}",
default="{source_file}_{analyzer}_{file_hash}",
help="This option can be used to override the default "
"plist file name output of this tool. This tool "
"can produce multiple plist files on the given "
"code analyzer output result file. The problem "
"is if we run this tool multiple times on the "
"same directory, it may override some plist "
"files. To prevent this we can generate a unique "
"hash into the plist file names with this "
"option. For example: "
"'{source_file}_{analyzer}_xxxxx'. {source_file} "
"and {analyzer} are special values which will "
"be replaced with the current analyzer and "
"source file name where the bug was found.")
"same file, it may override some plist files. To "
"prevent this we can generate a unique hash into "
"the plist file names with this option. For "
"example: "
"'{source_file}_{analyzer}_{file_hash}_xxxxx'. "
"{source_file}, {analyzer} and {file_hash} are "
"special values which will be replaced with the "
"current analyzer, source file name and hash of "
"the absolute file path where the bug was "
"found. ")

parser.add_argument('-c', '--clean',
dest="clean",
Expand Down

0 comments on commit 16244e3

Please sign in to comment.