forked from BhallaLab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmake_sanity_check.py
executable file
·87 lines (74 loc) · 2.38 KB
/
cmake_sanity_check.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
"""cmake_sanity_check.py: Check if Cmake files are ok.
Last modified: Sat Jan 18, 2014 05:01PM
"""
__author__ = "Dilawar Singh"
__copyright__ = "Copyright 2013, Dilawar Singh and NCBS Bangalore"
__credits__ = ["NCBS Bangalore"]
__license__ = "GNU GPL"
__version__ = "1.0.0"
__maintainer__ = "Dilawar Singh"
__email__ = "[email protected]"
__status__ = "Development"
import sys
import os
import re
from collections import defaultdict
makefiles = {}
cmakefiles = {}
makedirs = set()
cmakedirs = set()
def check(d):
searchMakefiles(d)
checkMissingCMake()
checkSrcs()
def checkMissingCMake():
if (makedirs - cmakedirs):
print("[Failed] Test 1")
print("Following directories have Makefile but not a CMakeFiles.txt file.")
print("%s" % "\t\n".join(makedirs - cmakedirs))
def searchMakefiles(d):
for d, subd, fs in os.walk(d):
if "CMakeLists.txt" in fs:
cmakedirs.add(d)
cmakefiles[d] = fs
if "Makefile" in fs:
makedirs.add(d)
makefiles[d] = fs
else: pass
def checkSrcs():
objPat = re.compile(r"\w+\.o")
srcPat = re.compile(r"\w+\.cpp")
srcs = []
csrcs = []
for d in makefiles:
with open(os.path.join(d, "Makefile"), "r") as f:
txt = f.read()
srcs = objPat.findall(txt)
try:
with open(os.path.join(d, "CMakeLists.txt"), "r") as f:
txt = f.read()
csrcs = srcPat.findall(txt)
except:
print("Dir {} does not have CMakeLists.txt".format(d))
csrcs = []
#print("[TEST 2] Checking if CMake is creating extra objects")
for csr in csrcs:
objName = csr.replace(".cpp", ".o")
if objName in srcs:
pass
else:
#print(" Failed: In dir {}, CMake is creating extra object {}".format(d, objName))
pass
print("[TEST 3] Checking if CMake is missing some objects")
for obj in srcs:
srcName = obj.replace(".o", ".cpp")
if srcName in csrcs: pass
else:
print(" Failed: In dir {}, CMake is missing object {}".format(d,
srcName))
def main():
dir = sys.argv[1]
check(dir)
if __name__ == '__main__':
main()