-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
68 lines (49 loc) · 1.51 KB
/
run.py
File metadata and controls
68 lines (49 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import subprocess
import os
import re
import shutil
import xml.etree.ElementTree as ET
# loaded rules list:
rules= []
from Rule1 import *
rules.append(Rule1())
#import Rule2
#rules.append(Rule2())
#import Rule3
#rules.append(Rule3())
# configurations
sources='C:/Users/fgrando/Downloads/cppcheck-rules/'
workspace='C:/Users/fgrando/Downloads/cppcheck-rules/ws'
cppcheckDir='C:/Users/fgrando/Downloads/cppcheck-2.3/cppcheck-2.3/bin/debug'
cppcheckBin='cppcheck.exe'
def sourceFilesList(path, regex):
out = []
for f in os.listdir(path):
if re.match(regex, f):
out.append(os.path.join(path, f))
return out
def runCppCheck(src, dst):
cppcheck = os.path.join(cppcheckDir, cppcheckBin)
cmd = cppcheck + " -q --language=c++ --dump " + src
# cppcheck generates a file with the .dump extension in the source folder.
# move this file to the destination
ret = subprocess.run(cmd.split(), stdout=subprocess.PIPE, cwd=cppcheckDir)
output = ret.stdout.decode('utf-8')
if output != "":
print(f"Possible failure converting {src}: {output}")
exit(-1)
shutil.move(src+'.dump', dst)
print("Enabled rules:")
for rule in rules:
rule.show()
print("\n\n\n")
for src in sourceFilesList(sources, ".*\.h$"):
name = os.path.basename(src)
print(f"processing {name} ...")
dst = os.path.join(workspace, name+'.xml')
runCppCheck(src, dst)
# load the xml
tree = ET.parse(dst)
root = tree.getroot()
for rule in rules:
rule.check(root)