7 .gitconfig configuration : 13 source-patterns = *.cpp *.cxx *.c 14 header-patterns = *.hpp *.hxx *.h 15 cppcheck-path="C:/Program Files/Cppcheck/cppcheck.exe" 21 from fnmatch
import fnmatch
25 SEPARATOR =
'%s\n' % (
'-' * 79)
26 CPPCHECK_PATH =
'cppcheck' 32 def check_cppcheck_install():
33 p = subprocess.Popen([CPPCHECK_PATH,
'--version'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
43 common.note(
'Checking with ' + CPPCHECK_PATH +
' file: ' + file)
46 p = subprocess.Popen([CPPCHECK_PATH, \
47 '--suppress=missingInclude', \
48 '--suppress=noExplicitConstructor', \
49 '--suppress=unmatchedSuppression', \
50 '--suppress=unusedFunction', \
51 '--enable=all',
'--quiet', \
52 '--template={file}@!@{line}@!@{severity}@!@{message}', \
54 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
55 out, err = p.communicate()
70 for line
in out.splitlines():
71 words = re.findall(
'(.+)@!@(.+)@!@(.+)@!@(.+)', line)
73 num_line = words[0][1]
74 severity = words[0][2]
76 common.error(
'[%s] line %s: %s' % (severity, num_line, message))
87 source_patterns =
common.get_option(
'cppcheck-hook.source-patterns', default=
'*.cpp *.cxx *.c').split()
88 header_patterns =
common.get_option(
'cppcheck-hook.header-patterns', default=
'*.hpp *.hxx *.h').split()
90 code_patterns = source_patterns + header_patterns
94 if common.g_cppcheck_path_arg
is not None and len(common.g_cppcheck_path_arg) > 0:
95 CPPCHECK_PATH = common.g_cppcheck_path_arg
97 CPPCHECK_PATH =
common.get_option(
'cppcheck-hook.cppcheck-path', default=CPPCHECK_PATH, type=
'--path').strip()
99 if check_cppcheck_install():
105 if any(fnmatch(f.path.lower(), p)
for p
in code_patterns):
108 file = os.path.join(repoRoot, f.path)
109 abort = check_file(file)
or abort
115 'cppcheck': cppcheck,
def get_option(option, default, type="")