-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_single_header
More file actions
executable file
·31 lines (26 loc) · 913 Bytes
/
make_single_header
File metadata and controls
executable file
·31 lines (26 loc) · 913 Bytes
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
#!/usr/bin/env python3
import os.path
import re
class Generator(object):
def __init__(self, include_path):
self.rex = re.compile(r'''#\s*include\s+<([^>]+)>\s*''')
self.include_path = os.path.abspath(include_path)
self.seen = set()
def run(self, src):
if src in self.seen:
return
self.seen.add(src)
with open(src) as f:
for line in f:
line = line.rstrip()
m = self.rex.fullmatch(line)
if m:
filename = m.group(1)
filename = os.path.join(self.include_path, filename)
if os.path.exists(filename):
self.run(filename)
continue
print(line)
if __name__ == "__main__":
generator = Generator("include")
generator.run(os.path.abspath("include/ctp/ctp.hh"))