16
16
17
17
from tools .paths import EXPORT_DIR , MBED_HAL , MBED_LIBRARIES , MBED_TARGETS_PATH
18
18
from tools .settings import BUILD_DIR
19
- from tools .export import EXPORTERS , mcu_ide_matrix , mcu_ide_list , export_project , get_exporter_toolchain
19
+ from tools .export import (
20
+ EXPORTERS ,
21
+ mcu_ide_matrix ,
22
+ mcu_ide_list ,
23
+ export_project ,
24
+ get_exporter_toolchain ,
25
+ )
20
26
from tools .tests import TESTS , TEST_MAP
21
27
from tools .tests import test_known , test_name_known , Test
22
28
from tools .targets import TARGET_NAMES
23
- from tools .utils import argparse_filestring_type , argparse_profile_filestring_type , argparse_many , args_error
29
+ from tools .utils import (
30
+ argparse_filestring_type ,
31
+ argparse_profile_filestring_type ,
32
+ argparse_many ,
33
+ args_error ,
34
+ )
24
35
from tools .utils import argparse_force_lowercase_type
25
36
from tools .utils import argparse_force_uppercase_type
26
37
from tools .utils import print_large_string
@@ -41,7 +52,14 @@ def resolve_exporter_alias(ide):
41
52
return ide
42
53
43
54
44
- def setup_project (ide , target , program = None , source_dir = None , build = None , export_path = None ):
55
+ def setup_project (
56
+ ide ,
57
+ target ,
58
+ program = None ,
59
+ source_dir = None ,
60
+ build = None ,
61
+ export_path = None
62
+ ):
45
63
"""Generate a name, if not provided, and find dependencies
46
64
47
65
Positional arguments:
@@ -75,7 +93,6 @@ def setup_project(ide, target, program=None, source_dir=None, build=None, export
75
93
test .dependencies .append (MBED_HAL )
76
94
test .dependencies .append (MBED_TARGETS_PATH )
77
95
78
-
79
96
src_paths = [test .source_dir ]
80
97
lib_paths = test .dependencies
81
98
project_name = "_" .join ([test .id , ide , target ])
@@ -104,15 +121,31 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
104
121
105
122
Returns an object of type Exporter (tools/exports/exporters.py)
106
123
"""
107
- project_dir , name , src , lib = setup_project (ide , target , program = project_id ,
108
- source_dir = src , build = build , export_path = export_path )
124
+ project_dir , name , src , lib = setup_project (
125
+ ide ,
126
+ target ,
127
+ program = project_id ,
128
+ source_dir = src ,
129
+ build = build ,
130
+ export_path = export_path ,
131
+ )
109
132
110
133
zip_name = name + ".zip" if zip_proj else None
111
134
112
- return export_project (src , project_dir , target , ide , name = name ,
113
- macros = macros , libraries_paths = lib , zip_proj = zip_name ,
114
- build_profile = build_profile , notify = notify ,
115
- app_config = app_config , ignore = ignore )
135
+ return export_project (
136
+ src ,
137
+ project_dir ,
138
+ target ,
139
+ ide ,
140
+ name = name ,
141
+ macros = macros ,
142
+ libraries_paths = lib ,
143
+ zip_proj = zip_name ,
144
+ build_profile = build_profile ,
145
+ notify = notify ,
146
+ app_config = app_config ,
147
+ ignore = ignore
148
+ )
116
149
117
150
118
151
def main ():
@@ -125,100 +158,139 @@ def main():
125
158
toolchainlist = list (EXPORTERS .keys () + EXPORTER_ALIASES .keys ())
126
159
toolchainlist .sort ()
127
160
128
- parser .add_argument ("-m" , "--mcu" ,
129
- metavar = "MCU" ,
130
- help = "generate project for the given MCU ({})" .format (
131
- ', ' .join (targetnames )))
132
-
133
- parser .add_argument ("-i" ,
134
- dest = "ide" ,
135
- type = argparse_force_lowercase_type (
136
- toolchainlist , "toolchain" ),
137
- help = "The target IDE: %s" % str (toolchainlist ))
138
-
139
- parser .add_argument ("-c" , "--clean" ,
140
- action = "store_true" ,
141
- default = False ,
142
- help = "clean the export directory" )
161
+ parser .add_argument (
162
+ "-m" , "--mcu" ,
163
+ metavar = "MCU" ,
164
+ help = "generate project for the given MCU ({})" .format (
165
+ ', ' .join (targetnames ))
166
+ )
167
+
168
+ parser .add_argument (
169
+ "-i" ,
170
+ dest = "ide" ,
171
+ type = argparse_force_lowercase_type (
172
+ toolchainlist , "toolchain" ),
173
+ help = "The target IDE: %s" % str (toolchainlist )
174
+ )
175
+
176
+ parser .add_argument (
177
+ "-c" , "--clean" ,
178
+ action = "store_true" ,
179
+ default = False ,
180
+ help = "clean the export directory"
181
+ )
143
182
144
183
group = parser .add_mutually_exclusive_group (required = False )
145
184
group .add_argument (
146
185
"-p" ,
147
186
type = test_known ,
148
187
dest = "program" ,
149
- help = "The index of the desired test program: [0-%s]" % (len (TESTS )- 1 ))
150
-
151
- group .add_argument ("-n" ,
152
- type = test_name_known ,
153
- dest = "program" ,
154
- help = "The name of the desired test program" )
155
-
156
- parser .add_argument ("-b" ,
157
- dest = "build" ,
158
- default = False ,
159
- action = "store_true" ,
160
- help = "use the mbed library build, instead of the sources" )
161
-
162
- group .add_argument ("-L" , "--list-tests" ,
163
- action = "store_true" ,
164
- dest = "list_tests" ,
165
- default = False ,
166
- help = "list available programs in order and exit" )
167
-
168
- group .add_argument ("-S" , "--list-matrix" ,
169
- dest = "supported_ides" ,
170
- default = False ,
171
- const = "matrix" ,
172
- choices = ["matrix" , "ides" ],
173
- nargs = "?" ,
174
- help = "displays supported matrix of MCUs and IDEs" )
175
-
176
- parser .add_argument ("-E" ,
177
- action = "store_true" ,
178
- dest = "supported_ides_html" ,
179
- default = False ,
180
- help = "writes tools/export/README.md" )
181
-
182
- parser .add_argument ("--build" ,
183
- type = argparse_filestring_type ,
184
- dest = "build_dir" ,
185
- default = None ,
186
- help = "Directory for the exported project files" )
187
-
188
- parser .add_argument ("--source" ,
189
- action = "append" ,
190
- type = argparse_filestring_type ,
191
- dest = "source_dir" ,
192
- default = [],
193
- help = "The source (input) directory" )
194
-
195
- parser .add_argument ("-D" ,
196
- action = "append" ,
197
- dest = "macros" ,
198
- help = "Add a macro definition" )
199
-
200
- parser .add_argument ("--profile" , dest = "profile" , action = "append" ,
201
- type = argparse_profile_filestring_type ,
202
- help = "Build profile to use. Can be either path to json" \
203
- "file or one of the default one ({})" .format (", " .join (list_profiles ())),
204
- default = [])
205
-
206
- parser .add_argument ("--update-packs" ,
207
- dest = "update_packs" ,
208
- action = "store_true" ,
209
- default = False )
210
- parser .add_argument ("--app-config" ,
211
- dest = "app_config" ,
212
- default = None )
213
-
214
- parser .add_argument ("--ignore" , dest = "ignore" , type = argparse_many (str ),
215
- default = None , help = "Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)" )
188
+ help = "The index of the desired test program: [0-%s]" % (len (TESTS ) - 1 )
189
+ )
190
+
191
+ group .add_argument (
192
+ "-n" ,
193
+ type = test_name_known ,
194
+ dest = "program" ,
195
+ help = "The name of the desired test program"
196
+ )
197
+
198
+ parser .add_argument (
199
+ "-b" ,
200
+ dest = "build" ,
201
+ default = False ,
202
+ action = "store_true" ,
203
+ help = "use the mbed library build, instead of the sources"
204
+ )
205
+
206
+ group .add_argument (
207
+ "-L" , "--list-tests" ,
208
+ action = "store_true" ,
209
+ dest = "list_tests" ,
210
+ default = False ,
211
+ help = "list available programs in order and exit"
212
+ )
213
+
214
+ group .add_argument (
215
+ "-S" , "--list-matrix" ,
216
+ dest = "supported_ides" ,
217
+ default = False ,
218
+ const = "matrix" ,
219
+ choices = ["matrix" , "ides" ],
220
+ nargs = "?" ,
221
+ help = "displays supported matrix of MCUs and IDEs"
222
+ )
223
+
224
+ parser .add_argument (
225
+ "-E" ,
226
+ action = "store_true" ,
227
+ dest = "supported_ides_html" ,
228
+ default = False ,
229
+ help = "writes tools/export/README.md"
230
+ )
231
+
232
+ parser .add_argument (
233
+ "--build" ,
234
+ type = argparse_filestring_type ,
235
+ dest = "build_dir" ,
236
+ default = None ,
237
+ help = "Directory for the exported project files"
238
+ )
239
+
240
+ parser .add_argument (
241
+ "--source" ,
242
+ action = "append" ,
243
+ type = argparse_filestring_type ,
244
+ dest = "source_dir" ,
245
+ default = [],
246
+ help = "The source (input) directory"
247
+ )
248
+
249
+ parser .add_argument (
250
+ "-D" ,
251
+ action = "append" ,
252
+ dest = "macros" ,
253
+ help = "Add a macro definition"
254
+ )
255
+
256
+ parser .add_argument (
257
+ "--profile" ,
258
+ dest = "profile" ,
259
+ action = "append" ,
260
+ type = argparse_profile_filestring_type ,
261
+ help = ("Build profile to use. Can be either path to json"
262
+ "file or one of the default one ({})" .format (
263
+ ", " .join (list_profiles ()))),
264
+ default = []
265
+ )
266
+
267
+ parser .add_argument (
268
+ "--update-packs" ,
269
+ dest = "update_packs" ,
270
+ action = "store_true" ,
271
+ default = False
272
+ )
273
+
274
+ parser .add_argument (
275
+ "--app-config" ,
276
+ dest = "app_config" ,
277
+ default = None
278
+ )
279
+
280
+ parser .add_argument (
281
+ "--ignore" ,
282
+ dest = "ignore" ,
283
+ type = argparse_many (str ),
284
+ default = None ,
285
+ help = ("Comma separated list of patterns to add to mbedignore "
286
+ "(eg. ./main.cpp)" )
287
+ )
216
288
217
289
options = parser .parse_args ()
218
290
219
291
# Print available tests in order and exit
220
292
if options .list_tests is True :
221
- print ('\n ' .join ([ str (test ) for test in sorted (TEST_MAP .values ())] ))
293
+ print ('\n ' .join (str (test ) for test in sorted (TEST_MAP .values ())))
222
294
sys .exit ()
223
295
224
296
# Only prints matrix of supported IDEs
@@ -232,17 +304,11 @@ def main():
232
304
# Only prints matrix of supported IDEs
233
305
if options .supported_ides_html :
234
306
html = mcu_ide_matrix (verbose_html = True )
235
- try :
236
- with open ("./export/README.md" , "w" ) as readme :
237
- readme .write ("Exporter IDE/Platform Support\n " )
238
- readme .write ("-----------------------------------\n " )
239
- readme .write ("\n " )
240
- readme .write (html )
241
- except IOError as exc :
242
- print ("I/O error({0}): {1}" .format (exc .errno , exc .strerror ))
243
- except :
244
- print ("Unexpected error:" , sys .exc_info ()[0 ])
245
- raise
307
+ with open ("./export/README.md" , "w" ) as readme :
308
+ readme .write ("Exporter IDE/Platform Support\n " )
309
+ readme .write ("-----------------------------------\n " )
310
+ readme .write ("\n " )
311
+ readme .write (html )
246
312
exit (0 )
247
313
248
314
if options .update_packs :
@@ -267,14 +333,17 @@ def main():
267
333
268
334
notify = TerminalNotifier ()
269
335
270
- if (options .program is None ) and (not options .source_dir ):
271
- args_error (parser , "one of -p, -n, or --source is required" )
272
336
ide = resolve_exporter_alias (options .ide )
273
337
exporter , toolchain_name = get_exporter_toolchain (ide )
338
+ profile = extract_profile (parser , options , toolchain_name , fallback = "debug" )
274
339
mcu = extract_mcus (parser , options )[0 ]
340
+
275
341
if not exporter .is_target_supported (mcu ):
276
342
args_error (parser , "%s not supported by %s" % (mcu , ide ))
277
- profile = extract_profile (parser , options , toolchain_name , fallback = "debug" )
343
+
344
+ if (options .program is None ) and (not options .source_dir ):
345
+ args_error (parser , "one of -p, -n, or --source is required" )
346
+
278
347
if options .clean :
279
348
for cls in EXPORTERS .values ():
280
349
try :
@@ -287,14 +356,22 @@ def main():
287
356
except (IOError , OSError ):
288
357
pass
289
358
try :
290
- export (mcu , ide , build = options .build ,
291
- src = options .source_dir , macros = options .macros ,
292
- project_id = options .program , zip_proj = zip_proj ,
293
- build_profile = profile , app_config = options .app_config ,
294
- export_path = options .build_dir , notify = notify ,
295
- ignore = options .ignore )
359
+ export (
360
+ mcu ,
361
+ ide ,
362
+ build = options .build ,
363
+ src = options .source_dir ,
364
+ macros = options .macros ,
365
+ project_id = options .program ,
366
+ zip_proj = zip_proj ,
367
+ build_profile = profile ,
368
+ app_config = options .app_config ,
369
+ export_path = options .build_dir ,
370
+ notify = notify ,
371
+ ignore = options .ignore
372
+ )
296
373
except NotSupportedException as exc :
297
- print ("[ERROR ] %s" % str (exc ))
374
+ print ("[Not Supported ] %s" % str (exc ))
298
375
299
376
if __name__ == "__main__" :
300
377
main ()
0 commit comments