Skip to content

Commit

Permalink
[tool] Separate module for report hash generation
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Mar 12, 2020
1 parent 12fedce commit 6bfc96e
Show file tree
Hide file tree
Showing 32 changed files with 1,521 additions and 344 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ script:
make package &&
make -C tools/plist_to_html test &&
make -C tools/report-converter package test &&
make -C tools/codechecker_report_hash test &&
if [[ "$CC_MODULE" = "analyzer" ]]; then
BUILD_DIR=$TRAVIS_BUILD_DIR/build make -C analyzer \
test_unit \
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ package_report_converter: build_report_converter package_dir_structure
cd $(CC_BUILD_DIR) && \
ln -sf ../lib/python3/codechecker_report_converter/cli.py bin/report-converter

package: package_dir_structure set_git_commit_template package_plist_to_html package_tu_collector package_report_converter
build_report_hash:
$(MAKE) -C $(ROOT)/tools/codechecker_report_hash build

package_report_hash: build_report_hash package_dir_structure
cp -r $(CC_TOOLS)/codechecker_report_hash/build/codechecker_report_hash/codechecker_report_hash $(CC_BUILD_LIB_DIR)

package: package_dir_structure set_git_commit_template package_plist_to_html package_tu_collector package_report_converter package_report_hash
BUILD_DIR=$(BUILD_DIR) BUILD_LOGGER_64_BIT_ONLY=$(BUILD_LOGGER_64_BIT_ONLY) $(MAKE) -C $(CC_ANALYZER) package_analyzer
BUILD_DIR=$(BUILD_DIR) $(MAKE) -C $(CC_WEB) package_web

Expand Down Expand Up @@ -147,7 +153,7 @@ clean_venv_dev:

clean: clean_package clean_vendor

clean_package: clean_plist_to_html clean_tu_collector clean_report_converter
clean_package: clean_plist_to_html clean_tu_collector clean_report_converter clean_report_hash
rm -rf $(BUILD_DIR)
find . -name "*.pyc" -delete

Expand All @@ -163,6 +169,9 @@ clean_tu_collector:
clean_report_converter:
$(MAKE) -C $(CC_TOOLS)/report-converter clean

clean_report_hash:
$(MAKE) -C $(CC_TOOLS)/codechecker_report_hash clean

clean_travis:
# Clean CodeChecker config files stored in the users home directory.
rm -rf ~/.codechecker*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"""


from codechecker_common import report
from codechecker_common.logger import get_logger
from codechecker_report_hash.hash import HashType, replace_report_hash

from ..result_handler_base import ResultHandler

Expand All @@ -27,4 +27,5 @@ def postprocess_result(self):
context insensitive if it is enabled during analysis.
"""
if self.report_hash_type in ['context-free', 'context-free-v2']:
report.use_context_free_hashes(self.analyzer_result_file)
replace_report_hash(self.analyzer_result_file,
HashType.CONTEXT_FREE)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import re

from codechecker_common.logger import get_logger
from codechecker_common.report import generate_report_hash
from codechecker_report_hash.hash import get_report_hash, HashType

LOG = get_logger('analyzer.tidy')

Expand Down Expand Up @@ -300,10 +300,9 @@ def _create_diag(message, fmap, files):
diag['path'].append(PListConverter._create_event_from_note(message,
fmap))

source_file = files[diag['location']['file']]
diag['issue_hash_content_of_line_in_context'] \
= generate_report_hash(diag['path'],
files[diag['location']['file']],
message.checker)
= get_report_hash(diag, source_file, HashType.PATH_SENSITIVE)

return diag

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


from codechecker_common import report
from codechecker_common.logger import get_logger
from codechecker_report_hash.hash import HashType, replace_report_hash

from ..result_handler_base import ResultHandler

Expand Down Expand Up @@ -54,4 +54,4 @@ def postprocess_result(self):
# --report-hash option ('context-free-v2') and we still do not use
# context free hash for 'context-free' choice.
if self.report_hash_type == 'context-free-v2':
report.use_context_free_hashes(output_file)
replace_report_hash(output_file, HashType.CONTEXT_FREE)
7 changes: 4 additions & 3 deletions analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
from codechecker_common.source_code_comment_handler import \
SourceCodeCommentHandler
from codechecker_common.output_formatters import twodim_to_str
from codechecker_common.report import Report, get_report_path_hash
from codechecker_common.report import Report
from codechecker_common.source_code_comment_handler import skip_suppress_status
from codechecker_report_hash.hash import get_report_path_hash

LOG = logger.get_logger('system')

Expand Down Expand Up @@ -150,7 +151,7 @@ def write(self, file_report_map, output=sys.stdout):
key=lambda r: r.main['location']['line'])

for report in sorted_reports:
path_hash = get_report_path_hash(report, report.files)
path_hash = get_report_path_hash(report.bug_path, report.files)
if path_hash in self._processed_path_hashes:
LOG.debug("Not showing report because it is a "
"deduplication of an already processed report!")
Expand Down Expand Up @@ -608,7 +609,7 @@ def skip_html_report_data_handler(report_hash, source_file, report_line,
comments.
"""
report = Report(None, diag['path'], files)
path_hash = get_report_path_hash(report, files)
path_hash = get_report_path_hash(report.bug_path, files)
if path_hash in processed_path_hashes:
LOG.debug("Skip report because it is a deduplication of an "
"already processed report!")
Expand Down
1 change: 1 addition & 0 deletions analyzer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
PKG_ROOT = os.path.join(REPO_ROOT, 'build', 'CodeChecker')

sys.path.append(REPO_ROOT)
sys.path.append(os.path.join(REPO_ROOT, 'tools', 'codechecker_report_hash'))
31 changes: 11 additions & 20 deletions codechecker_common/plist_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
from xml.parsers.expat import ExpatError

from codechecker_common.logger import get_logger
from codechecker_common.report import Report, generate_report_hash
from codechecker_common.report import Report
from codechecker_report_hash.hash import get_report_hash, HashType

LOG = get_logger('report')

Expand Down Expand Up @@ -116,22 +117,6 @@ def get_checker_name(diagnostic, path=""):
return checker_name


def get_report_hash(diagnostic, source_file):
"""
Check if checker name is available in the report.
Checker hash was not available in older clang versions before 3.8.
"""

report_hash = diagnostic.get('issue_hash_content_of_line_in_context')
if not report_hash:
# Generate hash value if it is missing from the report.
report_hash \
= generate_report_hash(diagnostic['path'],
source_file,
get_checker_name(diagnostic))
return report_hash


def parse_plist_file(path, source_root=None, allow_plist_update=True):
"""
Parse the reports from a plist file.
Expand Down Expand Up @@ -168,9 +153,15 @@ def parse_plist_file(path, source_root=None, allow_plist_update=True):
if source_root:
file_path = os.path.join(source_root, file_path.lstrip('/'))

report_hash = get_report_hash(diag, file_path)
main_section['issue_hash_content_of_line_in_context'] = \
report_hash
report_hash = diag.get('issue_hash_content_of_line_in_context')

if not report_hash:
# Generate hash value if it is missing from the report.
report_hash = get_report_hash(diag, file_path,
HashType.PATH_SENSITIVE)

main_section['issue_hash_content_of_line_in_context'] = \
report_hash

if 'issue_hash_content_of_line_in_context' not in diag:
# If the report hash was not in the plist, we set it in the
Expand Down
Loading

0 comments on commit 6bfc96e

Please sign in to comment.