Skip to content

Commit 03deb4d

Browse files
committed
addons: interface with premiumaddon if it exists
1 parent 45de9a7 commit 03deb4d

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

.github/workflows/scriptcheck.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
if: matrix.python-version == '2.7'
5656
run: |
5757
python -m pip install pip --upgrade
58+
python -m pip install pathlib
5859
python -m pip install pytest
5960
python -m pip install pygments
6061

addons/cert.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import cppcheckdata
1414
import sys
1515
import re
16+
import subprocess
1617

1718
VERIFY = ('-verify' in sys.argv)
1819
VERIFY_EXPECTED = []
@@ -401,6 +402,8 @@ def get_args_parser():
401402
parser = get_args_parser()
402403
args = parser.parse_args()
403404

405+
path_premium_addon = cppcheckdata.get_path_premium_addon()
406+
404407
if args.verify:
405408
VERIFY = True
406409

@@ -413,6 +416,14 @@ def get_args_parser():
413416
if not args.quiet:
414417
print('Checking %s...' % dumpfile)
415418

419+
if path_premium_addon:
420+
premium_command = [path_premium_addon, '--cert', dumpfile]
421+
if args.cli:
422+
premium_command.append('--cli')
423+
for line in subprocess.check_output(premium_command).decode('ascii').split('\n'):
424+
if line.find('cert-') > 0:
425+
print(line.strip())
426+
416427
data = cppcheckdata.CppcheckData(dumpfile)
417428

418429
if VERIFY:

addons/cppcheckdata.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import argparse
1010
import json
11+
import os
12+
import pathlib
1113
import sys
1214

1315
from xml.etree import ElementTree
@@ -1364,3 +1366,15 @@ def reportSummary(dumpfile, summary_type, summary_data):
13641366
with open(ctu_info_file, 'at') as f:
13651367
msg = {'summary': summary_type, 'data': summary_data}
13661368
f.write(json.dumps(msg) + '\n')
1369+
1370+
1371+
def get_path_premium_addon():
1372+
p = pathlib.Path(sys.argv[0]).parent.parent
1373+
1374+
for ext in ('.exe', ''):
1375+
p1 = os.path.join(p, 'premiumaddon' + ext)
1376+
p2 = os.path.join(p, 'cppcheck' + ext)
1377+
if os.path.isfile(p1) and os.path.isfile(p2):
1378+
print(p1)
1379+
return p1
1380+
return None

addons/misra.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ def __init__(self, settings, stdversion="c89"):
13181318
self._ctu_summary_identifiers = False
13191319
self._ctu_summary_usage = False
13201320

1321-
self.premium_addon = None
1321+
self.path_premium_addon = None
13221322

13231323
def __repr__(self):
13241324
attrs = ["settings", "verify_expected", "verify_actual", "violations",
@@ -4048,8 +4048,8 @@ def reportError(self, location, num1, num2):
40484048
misra_severity = self.ruleTexts[ruleNum].misra_severity
40494049
cppcheck_severity = self.ruleTexts[ruleNum].cppcheck_severity
40504050
elif len(self.ruleTexts) == 0:
4051-
if self.premium_addon:
4052-
errmsg = subprocess.check_output([self.premium_addon, '--get-rule-text=' + errorId]).strip().decode('ascii')
4051+
if self.path_premium_addon:
4052+
errmsg = subprocess.check_output([self.path_premium_addon, '--get-rule-text=' + errorId]).strip().decode('ascii')
40534053
else:
40544054
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
40554055
else:
@@ -4386,8 +4386,8 @@ def fillVerifyExpected(verify_expected, tok):
43864386
self.executeCheck(2210, self.misra_22_10, cfg)
43874387

43884388
# Premium MISRA checking, deep analysis
4389-
if cfgNumber == 0 and self.premium_addon:
4390-
subprocess.call([self.premium_addon, '--misra', dumpfile])
4389+
if cfgNumber == 0 and self.path_premium_addon:
4390+
subprocess.call([self.path_premium_addon, '--misra', dumpfile])
43914391

43924392
def analyse_ctu_info(self, ctu_info_files):
43934393
all_typedef_info = []
@@ -4572,7 +4572,6 @@ def get_args_parser():
45724572
parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true")
45734573
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
45744574
parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ")
4575-
parser.add_argument("--premium-addon", type=str, default=None, help=argparse.SUPPRESS)
45764575
return parser
45774576

45784577

@@ -4582,7 +4581,7 @@ def main():
45824581
settings = MisraSettings(args)
45834582
checker = MisraChecker(settings)
45844583

4585-
checker.premium_addon = args.premium_addon
4584+
checker.path_premium_addon = cppcheckdata.get_path_premium_addon()
45864585

45874586
if args.generate_table:
45884587
generateTable()
@@ -4645,8 +4644,8 @@ def main():
46454644

46464645
checker.analyse_ctu_info(ctu_info_files)
46474646

4648-
if args.file_list and args.premium_addon:
4649-
premium_command = [args.premium_addon, '--misra', '--file-list', args.file_list]
4647+
if args.file_list and checker.path_premium_addon:
4648+
premium_command = [checker.path_premium_addon, '--misra', '--file-list', args.file_list]
46504649
if args.cli:
46514650
premium_command.append('--cli')
46524651
for line in subprocess.check_output(premium_command).decode('ascii').split('\n'):

0 commit comments

Comments
 (0)