forked from Z3Prover/z3
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate_include.py
69 lines (60 loc) · 1.81 KB
/
update_include.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
# Copyright (c) 2017 Microsoft Corporation
import os
import re
is_include = re.compile("#include \"(.*)\"")
is_include2 = re.compile("#include\"(.*)\"")
def fix_include(file, paths):
tmp = "%s.tmp" % file
ins = open(file)
ous = open(tmp,'w')
line = ins.readline()
found = False
while line:
m = is_include.search(line)
if m and m.group(1) in paths:
ous.write("#include \"")
ous.write(paths[m.group(1)])
ous.write("\"\n")
found = True
line = ins.readline()
continue
m = is_include2.search(line)
if m and m.group(1) in paths:
ous.write("#include \"")
ous.write(paths[m.group(1)])
ous.write("\"\n")
found = True
line = ins.readline()
continue
ous.write(line)
line = ins.readline()
ins.close()
ous.close()
if found:
print(file)
os.system("move %s %s" % (tmp, file))
else:
os.system("del %s" % tmp)
def find_paths(dir):
paths = {}
for root, dirs, files in os.walk(dir):
root1 = root.replace("\\","/")[4:]
for f in files:
if f.endswith('.h') or f.endswith('.hpp') or f.endswith('.cpp'):
path = "%s/%s" % (root1, f)
paths[f] = path
if f.endswith('.pyg'):
f = f.replace("pyg","hpp")
path = "%s/%s" % (root1, f)
paths[f] = path
return paths
paths = find_paths('src')
def fixup(dir):
for root, dirs, files in os.walk(dir):
for f in files:
if f == "z3.h":
continue
if f.endswith('.h') or f.endswith('.cpp'):
path = "%s\\%s" % (root, f)
fix_include(path, paths)
fixup('src')