misra,cert: use premiumaddon if it exists

This commit is contained in:
Daniel Marjamäki 2022-02-23 20:26:31 +01:00
parent 48f2524774
commit ef28c579bf
3 changed files with 30 additions and 9 deletions

View File

@ -13,6 +13,7 @@ import argparse
import cppcheckdata import cppcheckdata
import sys import sys
import re import re
import subprocess
VERIFY = ('-verify' in sys.argv) VERIFY = ('-verify' in sys.argv)
VERIFY_EXPECTED = [] VERIFY_EXPECTED = []
@ -401,6 +402,8 @@ if __name__ == '__main__':
parser = get_args_parser() parser = get_args_parser()
args = parser.parse_args() args = parser.parse_args()
path_premium_addon = cppcheckdata.get_path_premium_addon()
if args.verify: if args.verify:
VERIFY = True VERIFY = True
@ -413,6 +416,14 @@ if __name__ == '__main__':
if not args.quiet: if not args.quiet:
print('Checking %s...' % dumpfile) print('Checking %s...' % dumpfile)
if path_premium_addon:
premium_command = [path_premium_addon, '--cert', dumpfile]
if args.cli:
premium_command.append('--cli')
for line in subprocess.check_output(premium_command).decode('ascii').split('\n'):
if line.find('cert-') > 0:
print(line.strip())
data = cppcheckdata.CppcheckData(dumpfile) data = cppcheckdata.CppcheckData(dumpfile)
if VERIFY: if VERIFY:

View File

@ -8,6 +8,8 @@ License: No restrictions, use this as you need.
import argparse import argparse
import json import json
import os
import pathlib
import sys import sys
from xml.etree import ElementTree from xml.etree import ElementTree
@ -1364,3 +1366,12 @@ def reportSummary(dumpfile, summary_type, summary_data):
with open(ctu_info_file, 'at') as f: with open(ctu_info_file, 'at') as f:
msg = {'summary': summary_type, 'data': summary_data} msg = {'summary': summary_type, 'data': summary_data}
f.write(json.dumps(msg) + '\n') f.write(json.dumps(msg) + '\n')
def get_path_premium_addon():
p = pathlib.Path(sys.argv[0]).parent.parent
p1 = os.path.join(p, 'premiumaddon')
p2 = os.path.join(p, 'cppcheck')
if os.path.isfile(p1) and os.path.isfile(p2):
return p1
return None

View File

@ -1318,7 +1318,7 @@ class MisraChecker:
self._ctu_summary_identifiers = False self._ctu_summary_identifiers = False
self._ctu_summary_usage = False self._ctu_summary_usage = False
self.premium_addon = None self.path_premium_addon = None
def __repr__(self): def __repr__(self):
attrs = ["settings", "verify_expected", "verify_actual", "violations", attrs = ["settings", "verify_expected", "verify_actual", "violations",
@ -4048,8 +4048,8 @@ class MisraChecker:
misra_severity = self.ruleTexts[ruleNum].misra_severity misra_severity = self.ruleTexts[ruleNum].misra_severity
cppcheck_severity = self.ruleTexts[ruleNum].cppcheck_severity cppcheck_severity = self.ruleTexts[ruleNum].cppcheck_severity
elif len(self.ruleTexts) == 0: elif len(self.ruleTexts) == 0:
if self.premium_addon: if self.path_premium_addon:
errmsg = subprocess.check_output([self.premium_addon, '--get-rule-text=' + errorId]).strip().decode('ascii') errmsg = subprocess.check_output([self.path_premium_addon, '--get-rule-text=' + errorId]).strip().decode('ascii')
else: else:
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)' errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
else: else:
@ -4386,8 +4386,8 @@ class MisraChecker:
self.executeCheck(2210, self.misra_22_10, cfg) self.executeCheck(2210, self.misra_22_10, cfg)
# Premium MISRA checking, deep analysis # Premium MISRA checking, deep analysis
if cfgNumber == 0 and self.premium_addon: if cfgNumber == 0 and self.path_premium_addon:
subprocess.call([self.premium_addon, '--misra', dumpfile]) subprocess.call([self.path_premium_addon, '--misra', dumpfile])
def analyse_ctu_info(self, ctu_info_files): def analyse_ctu_info(self, ctu_info_files):
all_typedef_info = [] all_typedef_info = []
@ -4572,7 +4572,6 @@ def get_args_parser():
parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true") parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true")
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true") parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ") parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ")
parser.add_argument("--premium-addon", type=str, default=None, help=argparse.SUPPRESS)
return parser return parser
@ -4582,7 +4581,7 @@ def main():
settings = MisraSettings(args) settings = MisraSettings(args)
checker = MisraChecker(settings) checker = MisraChecker(settings)
checker.premium_addon = args.premium_addon checker.path_premium_addon = cppcheckdata.get_path_premium_addon()
if args.generate_table: if args.generate_table:
generateTable() generateTable()
@ -4645,8 +4644,8 @@ def main():
checker.analyse_ctu_info(ctu_info_files) checker.analyse_ctu_info(ctu_info_files)
if args.file_list and args.premium_addon: if args.file_list and checker.path_premium_addon:
premium_command = [args.premium_addon, '--misra', '--file-list', args.file_list] premium_command = [checker.path_premium_addon, '--misra', '--file-list', args.file_list]
if args.cli: if args.cli:
premium_command.append('--cli') premium_command.append('--cli')
for line in subprocess.check_output(premium_command).decode('ascii').split('\n'): for line in subprocess.check_output(premium_command).decode('ascii').split('\n'):