@@ -28,11 +28,17 @@ def repopath(path):
28
28
return Path (__file__ ).absolute ().parents [2 ] / path
29
29
def relpath (path ):
30
30
return os .path .relpath (path , str (repopath ("." )))
31
+ def rename_board (name ):
32
+ return name .replace ("_" , "-" ).replace ("." , "-" ).replace (":" , "-" ).upper ()\
33
+ .replace ("BLUE-PILL" , "Blue Pill" ) \
34
+ .replace ("BLACK-PILL" , "Black Pill" ) \
35
+ .replace ("ARDUINO-UNO" , "Arduino UNO" ) \
36
+ .replace ("ARDUINO-NANO" , "Arduino NANO" ) \
37
+ .replace ("RASPBERRYPI" , "Raspberry Pi" )
31
38
32
39
sys .path .append (str (repopath ("ext/modm-devices" )))
33
40
from modm_devices .device_identifier import *
34
41
35
-
36
42
def get_targets ():
37
43
builder = lbuild .api .Builder ()
38
44
builder ._load_repositories (repopath ("repo.lb" ))
@@ -75,7 +81,13 @@ def get_targets():
75
81
for key , values in minimal_targets .items ():
76
82
target_list .append (sorted (values , key = lambda d : d .string )[- 1 ])
77
83
78
- return target_list
84
+ # We must include all :board module targets manually
85
+ board_list = []
86
+ for board in repopath ("src/modm/board" ).glob ("*/board.xml" ):
87
+ target = re .search (r"< *option +name=\"modm:target\" *>(.*?)</ *option *>" , board .read_text ())[1 ]
88
+ board_list .append ( (board .parent .name .replace ("_" , "-" ), target ) )
89
+
90
+ return target_list , board_list
79
91
80
92
81
93
def main ():
@@ -92,13 +104,15 @@ def main():
92
104
args = parser .parse_args ()
93
105
94
106
device_list = []
107
+ board_list = []
95
108
if args .test :
96
- # test list
97
109
device_list = ["hosted-linux" , "atmega328p-au" , "stm32f103c8t6" , "stm32g474cet6" , "samd21g18a-uu" ]
110
+ board_list = [("arduino-nano" , "atmega328p-au" ), ("arduino-uno" , "atmega328p-au" ), ("nucleo-g474re" , "stm32g474ret6" ),
111
+ ("blue-pill" , "stm32f103c8t6" ), ("feather-m0" , "samd21g18a-uu" )]
98
112
elif args .test2 :
99
113
device_list = ["hosted-linux" , "atmega328p-pu" , "stm32f103zgt7" , "stm32g474vet7" ]
100
114
else :
101
- device_list = get_targets ()
115
+ device_list , board_list = get_targets ()
102
116
103
117
template_path = os .path .realpath (os .path .dirname (sys .argv [0 ]))
104
118
cwd = Path ().cwd ()
@@ -115,11 +129,12 @@ def main():
115
129
(output_dir / "develop/api" ).mkdir (parents = True )
116
130
os .chdir (tempdir )
117
131
print ("Starting to generate documentation..." )
118
- template_overview (output_dir , device_list , template_path )
132
+ template_overview (output_dir , device_list , board_list , template_path )
119
133
print ("... for {} devices, estimated memory footprint is {} MB" .format (len (device_list ), (len (device_list )* 70 )+ 2000 ))
120
134
with multiprocessing .Pool (args .jobs ) as pool :
121
135
# We can only pass one argument to pool.map
122
- devices = ["{}|{}|{}" .format (modm_path , path_tempdir , d ) for d in device_list ]
136
+ devices = ["{}|{}|{}|" .format (modm_path , path_tempdir , dev ) for dev in device_list ]
137
+ devices += ["{}|{}|{}|{}" .format (modm_path , path_tempdir , dev , brd ) for (brd , dev ) in board_list ]
123
138
results = pool .map (create_target , devices )
124
139
# output_dir.rename(cwd / 'modm-api-docs')
125
140
if args .compress :
@@ -129,7 +144,7 @@ def main():
129
144
# shutil.make_archive(str(cwd / 'modm-api-docs'), 'gztar', str(output_dir))
130
145
else :
131
146
final_output_dir = Path (args .output )
132
- if args .overwrite :
147
+ if args .overwrite and final_output_dir . exists () :
133
148
for i in final_output_dir .iterdir ():
134
149
print ('Removing {}' .format (i ))
135
150
if i .is_dir ():
@@ -143,9 +158,10 @@ def main():
143
158
144
159
145
160
def create_target (argument ):
146
- modm_path , tempdir , device = argument .split ("|" )
161
+ modm_path , tempdir , device , board = argument .split ("|" )
162
+ output_dir = board if board else device
147
163
try :
148
- print ("Generating documentation for {} ..." .format (device ))
164
+ print ("Generating documentation for {} ..." .format (output_dir ))
149
165
150
166
options = ["modm:target={0}" .format (device )]
151
167
if device .startswith ("at" ):
@@ -154,9 +170,12 @@ def create_target(argument):
154
170
builder .load ([Path (modm_path ) / "repo.lb" , Path (modm_path ) / "test/repo.lb" ])
155
171
modules = sorted (builder .parser .modules .keys ())
156
172
157
- # Only allow the first board module to be built (they overwrite each others files)
158
- first_board = next ((m for m in modules if ":board:" in m ), None )
159
- modules = [m for m in modules if ":board" not in m or m == first_board ]
173
+ if board :
174
+ chosen_board = "modm:board:{}" .format (board )
175
+ else :
176
+ # Only allow the first board module to be built (they overwrite each others files)
177
+ chosen_board = next ((m for m in modules if ":board:" in m ), None )
178
+ modules = [m for m in modules if ":board" not in m or m == chosen_board ]
160
179
161
180
# Remove :tinyusb:host modules, they conflict with :tinyusb:device modules
162
181
modules = [m for m in modules if ":tinyusb:host" not in m ]
@@ -165,23 +184,25 @@ def create_target(argument):
165
184
# exist are include as dependencies of the :platform modules.
166
185
modules = [m for m in modules if ":architecture" not in m ]
167
186
168
- builder .build (device , modules )
187
+ builder .build (output_dir , modules )
169
188
170
- print ('Executing: (cd {}/modm/docs/ && doxypress doxypress.json)' .format (device ))
171
- os .system ('(cd {}/modm/docs/ && doxypress doxypress.json > /dev/null 2>&1)' .format (device ))
172
- (Path (tempdir ) / device / "modm/docs/html" ).rename (Path (tempdir ) / 'output/develop/api' / device )
173
- print ("Finished generating documentation for device {}." .format (device ))
189
+ print ('Executing: (cd {}/modm/docs/ && doxypress doxypress.json)' .format (output_dir ))
190
+ os .system ('(cd {}/modm/docs/ && doxypress doxypress.json > /dev/null 2>&1)' .format (output_dir ))
191
+ (Path (tempdir ) / output_dir / "modm/docs/html" ).rename (Path (tempdir ) / 'output/develop/api' / output_dir )
192
+ print ("Finished generating documentation for device {}." .format (output_dir ))
174
193
return True
175
194
except Exception as e :
176
- print ("Error generating documentation for device {}: {}" .format (device , e ))
195
+ print ("Error generating documentation for device {}: {}" .format (output_dir , e ))
177
196
return False
178
197
179
198
180
- def template_overview (output_dir , device_list , template_path ):
199
+ def template_overview (output_dir , device_list , board_list , template_path ):
181
200
html = Environment (loader = FileSystemLoader (template_path )).get_template ("docs_modm_io_index.html.in" ).render (
182
201
devices = device_list ,
202
+ boards = [(b , rename_board (b ), d ) for (b ,d ) in board_list ],
183
203
date = datetime .datetime .now ().strftime ("%d.%m.%Y, %H:%M" ),
184
- num_devices = len (device_list ))
204
+ num_devices = len (device_list ),
205
+ num_boards = len (board_list ))
185
206
with open (str (output_dir ) + "/index.html" ,"w+" ) as f :
186
207
f .write (html )
187
208
with open (str (output_dir ) + "/robots.txt" ,"w+" ) as f :
0 commit comments