forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Extend the `CodeChecker parse` command with an extra baseline output type which can be used to generate a baseline file which will contain report hashes for legacy reports. - Extend the `CodeChecker cmd diff` to support baseline files. - Add test cases. - Extend the documentation with the recommended usage of this workflow.
- Loading branch information
1 parent
35008b9
commit d162500
Showing
11 changed files
with
625 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
""" CodeChecker baseline output helpers. """ | ||
|
||
from io import TextIOWrapper | ||
import os | ||
from typing import Iterable, List, Set | ||
|
||
from codechecker_common import logger | ||
from codechecker_common.report import Report | ||
|
||
|
||
LOG = logger.get_logger('system') | ||
|
||
|
||
def __get_report_hashes(f: TextIOWrapper) -> List[str]: | ||
""" Get report hashes from the given file. """ | ||
return [h for h in f.readlines() if h] | ||
|
||
|
||
def get_report_hashes( | ||
baseline_file_paths: Iterable[str] | ||
) -> Set[str]: | ||
""" Get uniqued hashes from baseline files. """ | ||
report_hashes = set() | ||
for file_path in baseline_file_paths: | ||
with open(file_path, mode='r', encoding='utf-8', errors="ignore") as f: | ||
report_hashes.update(__get_report_hashes(f)) | ||
|
||
return report_hashes | ||
|
||
|
||
def convert(reports: Iterable[Report]) -> List[str]: | ||
""" Convert the given reports to CodeChecker baseline format. | ||
Returns a list of sorted unique report hashes. | ||
""" | ||
return sorted(set(r.report_hash for r in reports)) | ||
|
||
|
||
def write(output_dir_path: str, report_hashes: Iterable[str]): | ||
""" Create a new baseline file or extend an existing one with the given | ||
report hashes in the given output directory. It will remove the duplicates | ||
and also sort the report hashes before writing it to a file. | ||
""" | ||
file_path = os.path.join(output_dir_path, 'reports.baseline') | ||
with open(file_path, mode='a+', encoding='utf-8', errors="ignore") as f: | ||
f.seek(0) | ||
old_report_hashes = __get_report_hashes(f) | ||
new_report_hashes = set(report_hashes) - set(old_report_hashes) | ||
|
||
if not new_report_hashes: | ||
LOG.info("Baseline file (%s) is up-to-date.", file_path) | ||
return | ||
|
||
if old_report_hashes: | ||
LOG.info("Merging existing baseline file: %s", file_path) | ||
else: | ||
LOG.info("Creating new baseline file: %s", file_path) | ||
|
||
LOG.info("Total number of old report hashes: %d", | ||
len(old_report_hashes)) | ||
LOG.info("Total number of new report hashes: %d", | ||
len(new_report_hashes)) | ||
|
||
LOG.debug("New report hashes: %s", sorted(new_report_hashes)) | ||
|
||
f.seek(0) | ||
f.truncate() | ||
f.write("\n".join(sorted( | ||
set([*old_report_hashes, *report_hashes])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.