From 03deb4d31ec056825737e8cd22bbd21bd06883a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 24 Feb 2022 16:08:59 +0100 Subject: [PATCH] addons: interface with premiumaddon if it exists --- .github/workflows/scriptcheck.yml | 1 + addons/cert.py | 11 +++++++++++ addons/cppcheckdata.py | 14 ++++++++++++++ addons/misra.py | 17 ++++++++--------- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index 95ec7ae94..930eae9ba 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -55,6 +55,7 @@ jobs: if: matrix.python-version == '2.7' run: | python -m pip install pip --upgrade + python -m pip install pathlib python -m pip install pytest python -m pip install pygments diff --git a/addons/cert.py b/addons/cert.py index a4f8c507f..3e9ca3549 100755 --- a/addons/cert.py +++ b/addons/cert.py @@ -13,6 +13,7 @@ import argparse import cppcheckdata import sys import re +import subprocess VERIFY = ('-verify' in sys.argv) VERIFY_EXPECTED = [] @@ -401,6 +402,8 @@ if __name__ == '__main__': parser = get_args_parser() args = parser.parse_args() + path_premium_addon = cppcheckdata.get_path_premium_addon() + if args.verify: VERIFY = True @@ -413,6 +416,14 @@ if __name__ == '__main__': if not args.quiet: 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) if VERIFY: diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 157e0d85e..575cfdca9 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -8,6 +8,8 @@ License: No restrictions, use this as you need. import argparse import json +import os +import pathlib import sys from xml.etree import ElementTree @@ -1364,3 +1366,15 @@ def reportSummary(dumpfile, summary_type, summary_data): with open(ctu_info_file, 'at') as f: msg = {'summary': summary_type, 'data': summary_data} f.write(json.dumps(msg) + '\n') + + +def get_path_premium_addon(): + p = pathlib.Path(sys.argv[0]).parent.parent + + for ext in ('.exe', ''): + p1 = os.path.join(p, 'premiumaddon' + ext) + p2 = os.path.join(p, 'cppcheck' + ext) + if os.path.isfile(p1) and os.path.isfile(p2): + print(p1) + return p1 + return None diff --git a/addons/misra.py b/addons/misra.py index c79cd6302..47724476e 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1318,7 +1318,7 @@ class MisraChecker: self._ctu_summary_identifiers = False self._ctu_summary_usage = False - self.premium_addon = None + self.path_premium_addon = None def __repr__(self): attrs = ["settings", "verify_expected", "verify_actual", "violations", @@ -4048,8 +4048,8 @@ class MisraChecker: misra_severity = self.ruleTexts[ruleNum].misra_severity cppcheck_severity = self.ruleTexts[ruleNum].cppcheck_severity elif len(self.ruleTexts) == 0: - if self.premium_addon: - errmsg = subprocess.check_output([self.premium_addon, '--get-rule-text=' + errorId]).strip().decode('ascii') + if self.path_premium_addon: + errmsg = subprocess.check_output([self.path_premium_addon, '--get-rule-text=' + errorId]).strip().decode('ascii') else: errmsg = 'misra violation (use --rule-texts= to get proper output)' else: @@ -4386,8 +4386,8 @@ class MisraChecker: self.executeCheck(2210, self.misra_22_10, cfg) # Premium MISRA checking, deep analysis - if cfgNumber == 0 and self.premium_addon: - subprocess.call([self.premium_addon, '--misra', dumpfile]) + if cfgNumber == 0 and self.path_premium_addon: + subprocess.call([self.path_premium_addon, '--misra', dumpfile]) def analyse_ctu_info(self, ctu_info_files): 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("-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("--premium-addon", type=str, default=None, help=argparse.SUPPRESS) return parser @@ -4582,7 +4581,7 @@ def main(): settings = MisraSettings(args) checker = MisraChecker(settings) - checker.premium_addon = args.premium_addon + checker.path_premium_addon = cppcheckdata.get_path_premium_addon() if args.generate_table: generateTable() @@ -4645,8 +4644,8 @@ def main(): checker.analyse_ctu_info(ctu_info_files) - if args.file_list and args.premium_addon: - premium_command = [args.premium_addon, '--misra', '--file-list', args.file_list] + if args.file_list and checker.path_premium_addon: + premium_command = [checker.path_premium_addon, '--misra', '--file-list', args.file_list] if args.cli: premium_command.append('--cli') for line in subprocess.check_output(premium_command).decode('ascii').split('\n'):