Debian Codegraph @

scripts/update_include.py

raw
1 # Copyright (c) 2017 Microsoft Corporation
2
3 import os
4 import re
5
6 is_include = re.compile("#include \"(.*)\"")
7 is_include2 = re.compile("#include\"(.*)\"")
8
9
10 def fix_include(file, paths):
11 tmp = "%s.tmp" % file
12 ins = open(file)
13 ous = open(tmp,'w')
14 line = ins.readline()
15 found = False
16 while line:
17 m = is_include.search(line)
18 if m and m.group(1) in paths:
19 ous.write("#include \"")
20 ous.write(paths[m.group(1)])
21 ous.write("\"\n")
22 found = True
23 line = ins.readline()
24 continue
25 m = is_include2.search(line)
26 if m and m.group(1) in paths:
27 ous.write("#include \"")
28 ous.write(paths[m.group(1)])
29 ous.write("\"\n")
30 found = True
31 line = ins.readline()
32 continue
33 ous.write(line)
34 line = ins.readline()
35 ins.close()
36 ous.close()
37 if found:
38 print(file)
39 os.system("move %s %s" % (tmp, file))
40 else:
41 os.system("del %s" % tmp)
42
43 def find_paths(dir):
44 paths = {}
45 for root, dirs, files in os.walk(dir):
46 root1 = root.replace("\\","/")[4:]
47 for f in files:
48 if f.endswith('.h') or f.endswith('.hpp') or f.endswith('.cpp'):
49 path = "%s/%s" % (root1, f)
50 paths[f] = path
51 if f.endswith('.pyg'):
52 f = f.replace("pyg","hpp")
53 path = "%s/%s" % (root1, f)
54 paths[f] = path
55 return paths
56
57 paths = find_paths('src')
58
59 def fixup(dir):
60 for root, dirs, files in os.walk(dir):
61 for f in files:
62 if f == "z3.h":
63 continue
64 if f.endswith('.h') or f.endswith('.cpp'):
65 path = "%s\\%s" % (root, f)
66 fix_include(path, paths)
67
68
69 fixup('src')