-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_single_header
executable file
·37 lines (31 loc) · 1.07 KB
/
make_single_header
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
#!/usr/bin/env python
import argparse
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__":
parser = argparse.ArgumentParser()
parser.add_argument("--include-path", required=True)
parser.add_argument("--src", required=True)
args = parser.parse_args()
generator = Generator(args.include_path)
generator.run(os.path.abspath(args.src))