Fix misra crash when premium addon fails

This commit is contained in:
Daniel Marjamäki 2022-05-03 18:37:59 +02:00
parent 51b4cf592b
commit d50823fd22
2 changed files with 11 additions and 6 deletions

View File

@ -1386,3 +1386,10 @@ def get_path_premium_addon():
if os.path.isfile(p1) and os.path.isfile(p2): if os.path.isfile(p1) and os.path.isfile(p2):
return p1 return p1
return None return None
def cmd_output(cmd):
try:
return subprocess.check_output([self.path_premium_addon, '--cli', '--get-rule-text=' + errorId]).strip().decode('ascii')
except subprocess.CalledProcessError as e:
return e.output

View File

@ -4060,13 +4060,11 @@ 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:
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
if self.path_premium_addon: if self.path_premium_addon:
errmsg = '' for line in cppcheckdata.cmd_output([self.path_premium_addon, '--cli', '--get-rule-text=' + errorId]).split('\n'):
for line in subprocess.check_output([self.path_premium_addon, '--cli', '--get-rule-text=' + errorId]).strip().decode('ascii').split('\n'):
if not line.startswith('{'): if not line.startswith('{'):
errmsg = line errmsg = line
else:
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
else: else:
errmsg = 'misra violation %s with no text in the supplied rule-texts-file' % (ruleNum) errmsg = 'misra violation %s with no text in the supplied rule-texts-file' % (ruleNum)
@ -4402,7 +4400,7 @@ class MisraChecker:
# Premium MISRA checking, deep analysis # Premium MISRA checking, deep analysis
if cfgNumber == 0 and self.path_premium_addon: if cfgNumber == 0 and self.path_premium_addon:
subprocess.check_output([self.path_premium_addon, '--cli', '--misra', dumpfile]) subprocess.cmd_output([self.path_premium_addon, '--cli', '--misra', dumpfile])
def analyse_ctu_info(self, ctu_info_files): def analyse_ctu_info(self, ctu_info_files):
all_typedef_info = [] all_typedef_info = []
@ -4667,7 +4665,7 @@ def main():
premium_command = [checker.path_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.cmd_output(premium_command).split('\n'):
if re.search(r'"errorId".*:.*"misra-', line) is not None: if re.search(r'"errorId".*:.*"misra-', line) is not None:
print(line.strip()) print(line.strip())