mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-26 03:40:26 +00:00
Use a class variable for quiet
instead of passing it around
Signed-off-by: Yuto Takano <yuto.takano@arm.com>
This commit is contained in:
parent
6adb287960
commit
5473be2914
@ -93,8 +93,9 @@ class Problem(): # pylint: disable=too-few-public-methods
|
|||||||
"""
|
"""
|
||||||
A parent class representing a form of static analysis error.
|
A parent class representing a form of static analysis error.
|
||||||
"""
|
"""
|
||||||
|
# Class variable to control the quietness of all problems
|
||||||
|
quiet = False
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.quiet = False
|
|
||||||
self.textwrapper = textwrap.TextWrapper()
|
self.textwrapper = textwrap.TextWrapper()
|
||||||
self.textwrapper.width = 80
|
self.textwrapper.width = 80
|
||||||
self.textwrapper.initial_indent = " > "
|
self.textwrapper.initial_indent = " > "
|
||||||
@ -644,8 +645,9 @@ class NameChecker():
|
|||||||
* quiet: whether to hide detailed problem explanation.
|
* quiet: whether to hide detailed problem explanation.
|
||||||
"""
|
"""
|
||||||
self.log.info("=============")
|
self.log.info("=============")
|
||||||
|
Problem.quiet = quiet
|
||||||
problems = 0
|
problems = 0
|
||||||
problems += self.check_symbols_declared_in_header(quiet)
|
problems += self.check_symbols_declared_in_header()
|
||||||
|
|
||||||
pattern_checks = [
|
pattern_checks = [
|
||||||
("macros", MACRO_PATTERN),
|
("macros", MACRO_PATTERN),
|
||||||
@ -653,9 +655,9 @@ class NameChecker():
|
|||||||
("identifiers", IDENTIFIER_PATTERN)
|
("identifiers", IDENTIFIER_PATTERN)
|
||||||
]
|
]
|
||||||
for group, check_pattern in pattern_checks:
|
for group, check_pattern in pattern_checks:
|
||||||
problems += self.check_match_pattern(quiet, group, check_pattern)
|
problems += self.check_match_pattern(group, check_pattern)
|
||||||
|
|
||||||
problems += self.check_for_typos(quiet)
|
problems += self.check_for_typos()
|
||||||
|
|
||||||
self.log.info("=============")
|
self.log.info("=============")
|
||||||
if problems > 0:
|
if problems > 0:
|
||||||
@ -669,15 +671,12 @@ class NameChecker():
|
|||||||
self.log.info("PASS")
|
self.log.info("PASS")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def check_symbols_declared_in_header(self, quiet):
|
def check_symbols_declared_in_header(self):
|
||||||
"""
|
"""
|
||||||
Perform a check that all detected symbols in the library object files
|
Perform a check that all detected symbols in the library object files
|
||||||
are properly declared in headers.
|
are properly declared in headers.
|
||||||
Assumes parse_names_in_source() was called before this.
|
Assumes parse_names_in_source() was called before this.
|
||||||
|
|
||||||
Args:
|
|
||||||
* quiet: whether to hide detailed problem explanation.
|
|
||||||
|
|
||||||
Returns the number of problems that need fixing.
|
Returns the number of problems that need fixing.
|
||||||
"""
|
"""
|
||||||
problems = []
|
problems = []
|
||||||
@ -692,16 +691,15 @@ class NameChecker():
|
|||||||
if not found_symbol_declared:
|
if not found_symbol_declared:
|
||||||
problems.append(SymbolNotInHeader(symbol))
|
problems.append(SymbolNotInHeader(symbol))
|
||||||
|
|
||||||
self.output_check_result(quiet, "All symbols in header", problems)
|
self.output_check_result("All symbols in header", problems)
|
||||||
return len(problems)
|
return len(problems)
|
||||||
|
|
||||||
def check_match_pattern(self, quiet, group_to_check, check_pattern):
|
def check_match_pattern(self, group_to_check, check_pattern):
|
||||||
"""
|
"""
|
||||||
Perform a check that all items of a group conform to a regex pattern.
|
Perform a check that all items of a group conform to a regex pattern.
|
||||||
Assumes parse_names_in_source() was called before this.
|
Assumes parse_names_in_source() was called before this.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
* quiet: whether to hide detailed problem explanation.
|
|
||||||
* group_to_check: string key to index into self.parse_result.
|
* group_to_check: string key to index into self.parse_result.
|
||||||
* check_pattern: the regex to check against.
|
* check_pattern: the regex to check against.
|
||||||
|
|
||||||
@ -717,20 +715,16 @@ class NameChecker():
|
|||||||
problems.append(PatternMismatch("double underscore", item_match))
|
problems.append(PatternMismatch("double underscore", item_match))
|
||||||
|
|
||||||
self.output_check_result(
|
self.output_check_result(
|
||||||
quiet,
|
|
||||||
"Naming patterns of {}".format(group_to_check),
|
"Naming patterns of {}".format(group_to_check),
|
||||||
problems)
|
problems)
|
||||||
return len(problems)
|
return len(problems)
|
||||||
|
|
||||||
def check_for_typos(self, quiet):
|
def check_for_typos(self):
|
||||||
"""
|
"""
|
||||||
Perform a check that all words in the soure code beginning with MBED are
|
Perform a check that all words in the soure code beginning with MBED are
|
||||||
either defined as macros, or as enum constants.
|
either defined as macros, or as enum constants.
|
||||||
Assumes parse_names_in_source() was called before this.
|
Assumes parse_names_in_source() was called before this.
|
||||||
|
|
||||||
Args:
|
|
||||||
* quiet: whether to hide detailed problem explanation.
|
|
||||||
|
|
||||||
Returns the number of problems that need fixing.
|
Returns the number of problems that need fixing.
|
||||||
"""
|
"""
|
||||||
problems = []
|
problems = []
|
||||||
@ -757,23 +751,21 @@ class NameChecker():
|
|||||||
if not found and not typo_exclusion.search(name_match.name):
|
if not found and not typo_exclusion.search(name_match.name):
|
||||||
problems.append(Typo(name_match))
|
problems.append(Typo(name_match))
|
||||||
|
|
||||||
self.output_check_result(quiet, "Likely typos", problems)
|
self.output_check_result("Likely typos", problems)
|
||||||
return len(problems)
|
return len(problems)
|
||||||
|
|
||||||
def output_check_result(self, quiet, name, problems):
|
def output_check_result(self, name, problems):
|
||||||
"""
|
"""
|
||||||
Write out the PASS/FAIL status of a performed check depending on whether
|
Write out the PASS/FAIL status of a performed check depending on whether
|
||||||
there were problems.
|
there were problems.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
* quiet: whether to hide detailed problem explanation.
|
|
||||||
* name: the name of the test
|
* name: the name of the test
|
||||||
* problems: a List of encountered Problems
|
* problems: a List of encountered Problems
|
||||||
"""
|
"""
|
||||||
if problems:
|
if problems:
|
||||||
self.log.info("{}: FAIL\n".format(name))
|
self.log.info("{}: FAIL\n".format(name))
|
||||||
for problem in problems:
|
for problem in problems:
|
||||||
problem.quiet = quiet
|
|
||||||
self.log.warning(str(problem))
|
self.log.warning(str(problem))
|
||||||
else:
|
else:
|
||||||
self.log.info("{}: PASS".format(name))
|
self.log.info("{}: PASS".format(name))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user