-
Notifications
You must be signed in to change notification settings - Fork 2
/
create-single-cpp.py
executable file
·61 lines (45 loc) · 1.4 KB
/
create-single-cpp.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
#!/usr/bin/env python
import os
HERE = os.path.dirname(os.path.realpath(__file__))
ALREADY_SEEN = set()
def find_file(path):
candidates = [
os.path.join(HERE, "vesin", "src", path),
os.path.join(HERE, "vesin", "include", path),
]
for candidate in candidates:
if os.path.exists(candidate):
return candidate
raise RuntimeError(f"unable to find file for {path}")
def include_path(line):
assert "#include" in line
_, path = line.split("#include")
path = path.strip()
if path.startswith('"'):
return path[1:-1]
else:
return ""
def merge_files(path, output):
path = find_file(path)
if path in ALREADY_SEEN:
return
else:
ALREADY_SEEN.add(path)
if path.endswith("include/vesin.h"):
output.write('#include "vesin.h"\n')
return
with open(path) as fd:
for line in fd:
if "#include" in line:
new_path = include_path(line)
if new_path != "":
merge_files(new_path, output)
else:
output.write(line)
else:
output.write(line)
if __name__ == "__main__":
with open("vesin-single-build.cpp", "w") as output:
merge_files("cpu_cell_list.cpp", output)
merge_files("vesin.cpp", output)
print("created single build file 'vesin-single-build.cpp'")