From b23b256027ca092ac518188eaad856d9fd2a2bc4 Mon Sep 17 00:00:00 2001 From: bruntib Date: Mon, 8 Jul 2024 16:42:53 +0200 Subject: [PATCH] [feat] Accept non-existing file paths in report-converter Some analyzer tools (e.g. sanitizers) give an output that contains relative source file paths. When report-converter is executed from a directory where these absolute paths are not valid, then reports are simply not generated. If all reports contain such a relative path, then this message is given by report-converter: No 'lsan' results can be found in '...' This message is obviously false. This patch allows non-existing file paths in the analyzer outputs. Using further CodeChecker commands (store, parse, etc.) will emit an error message on these paths anyway, but at least we get rid of the incomprehensible error message above. Fixes #4280 --- .../analyzers/sanitizers/parser.py | 16 ++++++---------- .../codechecker_report_converter/report/hash.py | 5 +++-- .../codechecker_report_converter/util.py | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/report-converter/codechecker_report_converter/analyzers/sanitizers/parser.py b/tools/report-converter/codechecker_report_converter/analyzers/sanitizers/parser.py index 2d63d0ea24..d7cb94c905 100644 --- a/tools/report-converter/codechecker_report_converter/analyzers/sanitizers/parser.py +++ b/tools/report-converter/codechecker_report_converter/analyzers/sanitizers/parser.py @@ -90,16 +90,12 @@ def parse_stack_trace_line(self, line: str) -> Optional[BugPathEvent]: return None file_path = file_match.group('path') - if file_path and os.path.exists(file_path): - col = file_match.group('column') - return BugPathEvent( - line.rstrip(), - get_or_create_file( - os.path.abspath(file_path), self._file_cache), - int(file_match.group('line')), - int(col) if col else 0) - - return None + col = file_match.group('column') + return BugPathEvent( + line.rstrip(), + get_or_create_file(os.path.abspath(file_path), self._file_cache), + int(file_match.group('line')), + int(col) if col else 0) def create_report( self, diff --git a/tools/report-converter/codechecker_report_converter/report/hash.py b/tools/report-converter/codechecker_report_converter/report/hash.py index c7682b66cd..20970300f0 100644 --- a/tools/report-converter/codechecker_report_converter/report/hash.py +++ b/tools/report-converter/codechecker_report_converter/report/hash.py @@ -137,8 +137,9 @@ def __get_report_hash_context_free(report: Report) -> List[str]: if line_content == '' and \ not os.path.isfile(report.file.original_path): - LOG.error("Failed to include source line in the report hash.") - LOG.error('%s does not exists!', report.file.original_path) + LOG.warning( + "Failed to include source line in the report hash. " + '%s does not exist!', report.file.original_path) return [ report.file.name, diff --git a/tools/report-converter/codechecker_report_converter/util.py b/tools/report-converter/codechecker_report_converter/util.py index 789f8001f5..ce23e8229d 100644 --- a/tools/report-converter/codechecker_report_converter/util.py +++ b/tools/report-converter/codechecker_report_converter/util.py @@ -58,7 +58,7 @@ def get_line(file_path: str, line_no: int, errors: str = 'ignore') -> str: with open(file_path, mode='r', encoding='utf-8', errors=errors) as f: return get_linef(f, line_no) except IOError: - LOG.error("Failed to open file %s", file_path) + LOG.warning("Failed to open file %s", file_path) return ''