From 01cbadc6ede09a4194e73e4d45705f6292f557e2 Mon Sep 17 00:00:00 2001 From: "Richard A. Smith" Date: Mon, 21 May 2018 15:46:58 -0400 Subject: [PATCH] Add --quiet flag to misra.py for cleaner output (#1254) Output will still be given for style violations. This allows the build process output to be smaller and cleaner, making it easier to spot and address problems. --- addons/misra.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index d970974ad..c31338910 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -13,6 +13,8 @@ # # Total number of rules: 143 +from __future__ import print_function + import cppcheckdata import sys import re @@ -24,10 +26,15 @@ ruleTexts = {} VERIFY = False SHOW_SUMMARY = True +QUIET = False VERIFY_EXPECTED = [] VERIFY_ACTUAL = [] VIOLATIONS = [] +def printStatus(*args, **kwargs): + if not QUIET: + print(*args, **kwargs) + def reportError(location, num1, num2): if VERIFY: VERIFY_ACTUAL.append(str(location.linenr) + ':' + str(num1) + '.' + str(num2)) @@ -1498,6 +1505,8 @@ OPTIONS: Rule 1.2 Rule text for 1.2 <...> + +--quiet Only print something when there is an error """) sys.exit(1) @@ -1569,6 +1578,8 @@ for arg in sys.argv[1:]: generateTable() elif arg == "--no-summary": SHOW_SUMMARY = False + elif arg == "--quiet": + QUIET = True else: print('Fatal error: unhandled argument ' + arg) sys.exit(1) @@ -1597,14 +1608,14 @@ for arg in sys.argv[1:]: if compiled.match(word): VERIFY_EXPECTED.append(str(tok.linenr) + ':' + word) else: - print('Checking ' + arg + '...') + printStatus('Checking ' + arg + '...') cfgNumber = 0 for cfg in data.configurations: cfgNumber = cfgNumber + 1 if len(data.configurations) > 1: - print('Checking ' + arg + ', config "' + cfg.name + '"...') + printStatus('Checking ' + arg + ', config "' + cfg.name + '"...') if cfgNumber == 1: misra_3_1(data.rawTokens)