8
8
import sys
9
9
10
10
head_re = re .compile ("include/(?P<name>.*)\.hpp" )
11
+
12
+
11
13
def clean_name (file ):
12
14
match = head_re .match (file )
13
15
return match .group ("name" )
14
16
17
+
15
18
top = []
16
- for toplevel in glob .glob (' include/?eman/*/*.hpp' ):
19
+ for toplevel in glob .glob (" include/?eman/*/*.hpp" ):
17
20
top .append (clean_name (toplevel ))
18
21
19
22
all = top .copy ()
20
- for detail in glob .glob (' include/?eman/*/?etail/*.hpp' ):
23
+ for detail in glob .glob (" include/?eman/*/?etail/*.hpp" ):
21
24
all .append (clean_name (detail ))
22
25
23
26
headers = {}
24
27
beman_re = re .compile ('#include ["<](?P<name>[bB]eman/.*)\.hpp[">]' )
25
28
other_re = re .compile ('#include ["<](?P<name>.*)[">]' )
26
29
30
+
27
31
def get_dependencies (component ):
28
32
deps = []
29
33
with open ("include/" + component + ".hpp" ) as file :
30
34
for line in file .readlines ():
31
35
if beman_re .match (line ):
32
36
deps .append (beman_re .match (line ).group ("name" ))
33
- elif ( other_re .match (line ) ):
37
+ elif other_re .match (line ):
34
38
header = other_re .match (line ).group ("name" )
35
39
if header not in headers :
36
40
headers [header ] = 1
37
41
38
42
return deps
39
43
44
+
40
45
dependencies = {}
41
46
42
47
for component in all :
43
48
dependencies [component ] = get_dependencies (component )
44
49
45
50
if len (sys .argv ) != 2 :
46
- print (f' usage: { sys .argv [0 ]} <target-dir>' )
51
+ print (f" usage: { sys .argv [0 ]} <target-dir>" )
47
52
sys .exit (1 )
48
53
49
54
dir = sys .argv [1 ]
50
55
51
56
project_re = re .compile ("(?P<project>(?P<beman>[bB]eman)/.*)/" )
52
57
define_re = re .compile ("#define" )
53
58
59
+
54
60
def write_header (to , header ):
55
- with open (f' include/{ header } .hpp' ) as file :
61
+ with open (f" include/{ header } .hpp" ) as file :
56
62
for line in file .readlines ():
57
63
if not beman_re .match (line ) and not other_re .match (line ):
58
64
to .write (line )
59
65
66
+
60
67
def build_header (file , to , header ):
61
68
includes = list (headers .keys ())
62
69
for include in includes :
63
- to .write (f' #include <{ include } >\n ' )
70
+ to .write (f" #include <{ include } >\n " )
64
71
65
72
deps = {}
66
73
todo = dependencies [header ].copy ()
@@ -70,7 +77,7 @@ def build_header(file, to, header):
70
77
for new in dependencies [todo [0 ]]:
71
78
todo .append (new )
72
79
todo = todo [1 :]
73
-
80
+
74
81
while 0 < len (deps ):
75
82
empty = [item for item in deps .keys () if 0 == len (deps [item ])]
76
83
for e in empty :
@@ -79,22 +86,23 @@ def build_header(file, to, header):
79
86
for d in deps .keys ():
80
87
deps [d ] = [item for item in deps [d ] if e != item ]
81
88
89
+
82
90
for header in top :
83
91
beman = project_re .match (header ).group ("beman" )
84
- if not os .path .exists (f' { dir } /{ beman } ' ):
85
- os .mkdir (f' { dir } /{ beman } ' )
92
+ if not os .path .exists (f" { dir } /{ beman } " ):
93
+ os .mkdir (f" { dir } /{ beman } " )
86
94
project = project_re .match (header ).group ("project" )
87
- if not os .path .exists (f' { dir } /{ project } ' ):
88
- os .mkdir (f' { dir } /{ project } ' )
95
+ if not os .path .exists (f" { dir } /{ project } " ):
96
+ os .mkdir (f" { dir } /{ project } " )
89
97
90
98
prolog_done = False
91
- with open (f' include/{ header } .hpp' ) as file :
92
- with open (f' { dir } /{ header } .hpp' , 'w' ) as to :
99
+ with open (f" include/{ header } .hpp" ) as file :
100
+ with open (f" { dir } /{ header } .hpp" , "w" ) as to :
93
101
for line in file .readlines ():
94
102
if not beman_re .match (line ) and not other_re .match (line ):
95
103
to .write (line )
96
104
if not prolog_done and define_re .match (line ):
97
105
prolog_done = True
98
106
to .write ("\n " )
99
107
build_header (file , to , header )
100
- to .write ("\n " )
108
+ to .write ("\n " )
0 commit comments