Skip to content

Commit

Permalink
[server] Handle missing database file ids for file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Nov 18, 2021
1 parent 153b0e0 commit 11dcdc7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def __init__(
self.__sc_handler = SourceCodeCommentHandler()

self.__source_line: Optional[str] = source_line
self.__files: Optional[Set[str]] = None
self.__files: Optional[Set[File]] = None
self.__changed_files: Optional[Set[str]] = None

@property
Expand Down Expand Up @@ -350,23 +350,33 @@ def trim_path_prefixes(self, path_prefixes: Optional[List[str]] = None):
event.file.trim(path_prefixes)

@property
def files(self) -> Set[str]:
def files(self) -> Set[File]:
""" Returns all referenced file paths. """
if self.__files is not None:
return self.__files

self.__files = {self.file.original_path}
self.__files = {self.file}

for event in itertools.chain(
self.bug_path_events,
self.bug_path_positions,
self.notes,
self.macro_expansions
):
self.__files.add(event.file.original_path)
self.__files.add(event.file)

return self.__files

@property
def trimmed_files(self) -> Set[str]:
""" Returns all referenced trimmed file paths. """
return {file.path for file in self.files}

@property
def original_files(self) -> Set[str]:
""" Returns all referenced original file paths. """
return {file.original_path for file in self.files}

@property
def changed_files(self) -> Set[str]:
"""
Expand All @@ -391,7 +401,7 @@ def changed_files(self) -> Set[str]:
# changed.
self.__changed_files.add(self.analyzer_result_file_path)

for file_path in self.files:
for file_path in self.original_files:
if not os.path.exists(file_path):
self.__changed_files.add(file_path)
continue
Expand Down Expand Up @@ -503,7 +513,7 @@ def review_status(self) -> str:
def skip(self, skip_handler: Optional[SkipListHandler]) -> bool:
""" True if the report should be skipped. """
if skip_handler:
for file_path in self.files:
for file_path in self.original_files:
if skip_handler(file_path):
return True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def convert(

files = set()
for report in reports:
files.update(report.files)
files.update(report.original_files)

file_index_map: Dict[str, int] = {}
for idx, file_path in enumerate(sorted(files)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class GenericSuppressHandler:
store_suppress_bug_id: Callable[[Any, str, str, str, str], bool]


def get_mentioned_files(reports: List[Report]) -> Set[str]:
def get_mentioned_original_files(reports: List[Report]) -> Set[str]:
""" Get all mentioned files from the given reports. """
files = set()

for report in reports:
files.update(report.files)
files.update(report.original_files)

return files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

from codechecker_report_converter.report import BugPathEvent, \
BugPathPosition, File, Range, Report, report_file
from codechecker_report_converter.report.reports import get_mentioned_files
from codechecker_report_converter.report.reports import \
get_mentioned_original_files


gen_plist_dir_path = os.path.join(
Expand Down Expand Up @@ -166,7 +167,7 @@ def test_clang37_plist(self):
reports = report_file.get_reports(clang37_plist)
self.assertEqual(len(reports), 3)

files = get_mentioned_files(reports)
files = get_mentioned_original_files(reports)
self.assertEqual(files, set(SRC_FILES))

for report in reports:
Expand Down Expand Up @@ -197,7 +198,7 @@ def test_clang38_trunk_plist(self):
reports = report_file.get_reports(clang38_plist)
self.assertEqual(len(reports), 3)

files = get_mentioned_files(reports)
files = get_mentioned_original_files(reports)
self.assertEqual(files, set(SRC_FILES))

for report in reports:
Expand All @@ -220,7 +221,7 @@ def test_clang40_plist(self):
reports = report_file.get_reports(clang40_plist)
self.assertEqual(len(reports), 3)

files = get_mentioned_files(reports)
files = get_mentioned_original_files(reports)
self.assertEqual(files, set(SRC_FILES))

for report in reports:
Expand Down Expand Up @@ -248,7 +249,7 @@ def test_clang50_trunk_plist(self):
reports = report_file.get_reports(clang50_trunk_plist)
self.assertEqual(len(reports), 3)

files = get_mentioned_files(reports)
files = get_mentioned_original_files(reports)
self.assertEqual(files, set(SRC_FILES))

for report in reports:
Expand Down
2 changes: 1 addition & 1 deletion web/client/codechecker_client/cmd/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def assemble_zip(inputs, zip_file, client):
changed_files.update(report.changed_files)
continue

file_paths.update(report.files)
file_paths.update(report.original_files)
file_report_positions[report.file.original_path].add(report.line)

if changed_files:
Expand Down
24 changes: 21 additions & 3 deletions web/server/codechecker_server/api/mass_store_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,17 +831,35 @@ def set_review_status(report: Report):
self.__wrong_src_code_comments.append(
f"{source_file}|{report_line}|{checker_name}")

def get_missing_file_ids(report: Report) -> List[str]:
""" Returns file paths which database file id is missing. """
missing_ids_for_files = []
for file_path in report.trimmed_files:
file_id = file_path_to_id.get(file_path, -1)
if file_id == -1:
missing_ids_for_files.append(file_path)

return missing_ids_for_files

root_dir_path = os.path.dirname(report_file_path)
mip = self.__mips[root_dir_path]
analysis_info = self.__analysis_info.get(root_dir_path)

for report in reports:
self.__all_report_checkers.add(report.checker_name)
report.trim_path_prefixes(self.__trim_path_prefixes)

if skip_handler.should_skip(report.file.path):
missing_ids_for_files = get_missing_file_ids(report)
if missing_ids_for_files:
LOG.warning("Failed to get database id for file path '%s'! "
"Skip adding report: %s:%d:%d [%s]",
' '.join(missing_ids_for_files), report.file.path,
report.line, report.column, report.checker_name)
continue

report.trim_path_prefixes(self.__trim_path_prefixes)
self.__all_report_checkers.add(report.checker_name)

if skip_handler.should_skip(report.file.original_path):
continue

report_path_hash = get_report_path_hash(report)
if report_path_hash in self.__already_added_report_hashes:
Expand Down

0 comments on commit 11dcdc7

Please sign in to comment.