예제 #1
0
    def collect_file_hashes_from_plist(plist_file):
        """
        Collects file content hashes and last modification times for the
        source files which can be found in the given plist file.

        :returns List of file paths which are in the processed plist file but
        missing from the user's disk and the source file modification times
        for the still available source files.

        """
        source_file_mod_times = {}
        missing_files = []
        sc_handler = SourceCodeCommentHandler()

        try:
            files, reports = plist_parser.parse_plist_file(plist_file)

            if not reports:
                return missing_files, source_file_mod_times

            # CppCheck generates a '0' value for the bug hash.
            # In case all of the reports in a plist file contain only
            # a hash with '0' value oeverwrite the hash values in the
            # plist report files with a context free hash value.
            rep_hash = [rep.report_hash == '0' for rep in reports]
            if all(rep_hash):
                replace_report_hash(plist_file, HashType.CONTEXT_FREE)

            for f in files:
                if not os.path.isfile(f):
                    missing_files.append(f)
                    missing_source_files.add(f)
                    continue

                content_hash = get_file_content_hash(f)
                hash_to_file[content_hash] = f
                file_to_hash[f] = content_hash
                source_file_mod_times[f] = util.get_last_mod_time(f)

            # Get file hashes which contain source code comments.
            for report in reports:
                last_report_event = report.bug_path[-1]
                file_path = files[last_report_event['location']['file']]
                if not os.path.isfile(file_path):
                    continue

                file_hash = file_to_hash[file_path]
                if file_hash in file_hash_with_review_status:
                    continue

                report_line = last_report_event['location']['line']
                if sc_handler.has_source_line_comments(file_path, report_line):
                    file_hash_with_review_status.add(file_hash)

            return missing_files, source_file_mod_times
        except Exception as ex:
            import traceback
            traceback.print_stack()
            LOG.error('Parsing the plist failed: %s', str(ex))
예제 #2
0
 def postprocess_result(self):
     """
     Override the context sensitive issue hash in the plist files to
     context insensitive if it is enabled during analysis.
     """
     if self.report_hash_type in ['context-free', 'context-free-v2']:
         replace_report_hash(self.analyzer_result_file,
                             HashType.CONTEXT_FREE)
예제 #3
0
def overwrite_cppcheck_report_hash(reports, plist_file):
    """CppCheck generates a '0' value for the bug hash.
    In case all of the reports in a plist file contain only
    a hash with '0' value overwrite the hash values in the
    plist report files with a context free hash value.
    """
    rep_hash = [rep.report_hash == '0' for rep in reports]
    if all(rep_hash):
        replace_report_hash(plist_file, HashType.CONTEXT_FREE)
        return True
    return False
    def test_replace_report_hash_in_empty_plist(self):
        """ Test replacing hash in an empty plist file. """
        with tempfile.NamedTemporaryFile("wb+",
                                         suffix='.plist') as empty_plist_file:
            content = {'diagnostics': [], 'files': []}
            plistlib.dump(content, empty_plist_file)
            empty_plist_file.flush()
            empty_plist_file.seek(0)

            replace_report_hash(empty_plist_file.name, HashType.CONTEXT_FREE)
            empty_plist_file.flush()
            empty_plist_file.seek(0)

            # Check that plist file is not empty.
            self.assertNotEqual(empty_plist_file.read(), b'')
예제 #5
0
    def postprocess_result(self):
        """
        Generate plist file which can be parsed and processed for
        results which can be stored into the database.
        """
        output_file = self.analyzer_result_file
        LOG.debug_analyzer(self.analyzer_stdout)
        tidy_stdout = self.analyzer_stdout.splitlines()
        generate_plist_from_tidy_result(output_file, tidy_stdout)

        # In the earlier versions of CodeChecker Clang Tidy never used context
        # free hash even if we enabled it with '--report-hash context-free'
        # when calling the analyze command. To do not break every hash
        # automatically when using this option we introduced a new choice for
        # --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':
            replace_report_hash(output_file, HashType.CONTEXT_FREE)