22
22
import subprocess
23
23
from shutil import rmtree
24
24
import json
25
+ import logging
26
+
27
+ logging .basicConfig (level = logging .DEBUG , format = '[EXAMPLES]> %(levelname)-8s %(message)s' )
25
28
26
29
""" Import and bulid a bunch of example programs
27
30
@@ -171,7 +174,7 @@ def get_repo_list(example):
171
174
return repos
172
175
173
176
174
- def source_repos (config , examples ):
177
+ def source_repos (config , exp_filter ):
175
178
""" Imports each of the repos and its dependencies (.lib files) associated
176
179
with the specific examples name from the json config file. Note if
177
180
there is already a clone of the repo then it will first be removed to
@@ -182,22 +185,20 @@ def source_repos(config, examples):
182
185
"""
183
186
print ("\n Importing example repos....\n " )
184
187
for example in config ['examples' ]:
185
- for repo_info in get_repo_list (example ):
186
- name = basename (repo_info ['repo' ])
187
- if name in examples :
188
- if os .path .exists (name ):
189
- print ("'%s' example directory already exists. Deleting..." % name )
190
- rmtree (name )
191
-
192
- cmd = "mbed-cli import %s" % repo_info ['repo' ]
193
- result = subprocess .call (cmd , shell = True )
194
-
195
- if result :
196
- return result
197
-
188
+ name = example ['name' ]
189
+ if name in exp_filter :
190
+ if os .path .exists (name ):
191
+ logging .warning ("'%s' example directory already exists. Deleting..." % name )
192
+ rmtree (name )
193
+
194
+ cmd = "mbed-cli import %s" % example ['github' ]
195
+ logging .info ("Executing command '%s'..." % cmd )
196
+ result = subprocess .call (cmd , shell = True )
197
+ if result :
198
+ return result
198
199
return 0
199
200
200
- def clone_repos (config , examples , retry = 3 ):
201
+ def clone_repos (config , exp_filter , retry = 3 ):
201
202
""" Clones each of the repos associated with the specific examples name from the
202
203
json config file. Note if there is already a clone of the repo then it will first
203
204
be removed to ensure a clean, up to date cloning.
@@ -207,22 +208,23 @@ def clone_repos(config, examples , retry = 3):
207
208
"""
208
209
print ("\n Cloning example repos....\n " )
209
210
for example in config ['examples' ]:
210
- for repo_info in get_repo_list (example ):
211
- name = basename (repo_info ['repo' ])
212
- if name in examples :
213
- if os .path .exists (name ):
214
- print ("'%s' example directory already exists. Deleting..." % name )
215
- rmtree (name )
216
- cmd = "%s clone %s" % (repo_info ['type' ], repo_info ['repo' ])
217
- for i in range (0 , retry ):
218
- if not subprocess .call (cmd , shell = True ):
219
- break
220
- else :
221
- print ("ERROR : unable to clone the repo {}" .format (name ))
222
- return 1
211
+ name = example ['name' ]
212
+ if name in exp_filter :
213
+ if os .path .exists (name ):
214
+ logging .warning ("'%s' example directory already exists. Deleting..." % name )
215
+ rmtree (name , onerror = remove_readonly )
216
+
217
+ cmd = "git clone %s" % example ['github' ]
218
+ for i in range (0 , retry ):
219
+ logging .info ("Executing command '%s'..." % cmd )
220
+ if not subprocess .call (cmd , shell = True ):
221
+ break
222
+ else :
223
+ logging .error ("unable to clone the repo '%s'" % name )
224
+ return 1
223
225
return 0
224
226
225
- def deploy_repos (config , examples ):
227
+ def deploy_repos (config , exp_filter ):
226
228
""" If the example directory exists as provided by the json config file,
227
229
pull in the examples dependencies by using `mbed-cli deploy`.
228
230
Args:
@@ -231,19 +233,21 @@ def deploy_repos(config, examples):
231
233
"""
232
234
print ("\n Deploying example repos....\n " )
233
235
for example in config ['examples' ]:
234
- for repo_info in get_repo_list (example ):
235
- name = basename (repo_info ['repo' ].strip ('/' ))
236
- if name in examples :
237
- if os .path .exists (name ):
238
- os .chdir (name )
239
- result = subprocess .call ("mbed-cli deploy" , shell = True )
240
- os .chdir (".." )
241
- if result :
242
- print ("mbed-cli deploy command failed for '%s'" % name )
243
- return result
244
- else :
245
- print ("'%s' example directory doesn't exist. Skipping..." % name )
246
- return 1
236
+ name = example ['name' ]
237
+ if name in exp_filter :
238
+ if os .path .exists (name ):
239
+ os .chdir (name )
240
+ logging .info ("In folder '%s'" % name )
241
+ cmd = "mbed-cli deploy"
242
+ logging .info ("Executing command '%s'..." % cmd )
243
+ result = subprocess .call (cmd , shell = True )
244
+ os .chdir (CWD )
245
+ if result :
246
+ logging .error ("mbed-cli deploy command failed for '%s'" % name )
247
+ return result
248
+ else :
249
+ logging .info ("'%s' example directory doesn't exist. Skipping..." % name )
250
+ return 1
247
251
return 0
248
252
249
253
def get_num_failures (results , export = False ):
@@ -463,7 +467,7 @@ def compile_repos(config, toolchains, targets, profile, verbose, examples, jobs=
463
467
return results
464
468
465
469
466
- def update_mbedos_version (config , tag , examples ):
470
+ def update_mbedos_version (config , tag , exp_filter ):
467
471
""" For each example repo identified in the config json object, update the version of
468
472
mbed-os to that specified by the supplied GitHub tag. This function assumes that each
469
473
example repo has already been cloned.
@@ -473,20 +477,39 @@ def update_mbedos_version(config, tag, examples):
473
477
tag - GitHub tag corresponding to a version of mbed-os to upgrade to.
474
478
475
479
"""
476
- print ("Updating mbed-os in examples to version %s \n " % tag )
480
+ print ("\n Updating mbed-os in examples to version '%s' \n " % tag )
477
481
for example in config ['examples' ]:
478
- if example ['name' ] not in examples :
482
+ if example ['name' ] not in exp_filter :
479
483
continue
480
- for repo_info in get_repo_list (example ):
481
- update_dir = basename (repo_info ['repo' ]) + "/mbed-os"
482
- print ("\n Changing dir to %s\n " % update_dir )
484
+ for name in get_sub_examples_list (example ):
485
+ update_dir = name + "/mbed-os"
483
486
os .chdir (update_dir )
487
+ logging .info ("In folder '%s'" % name )
484
488
cmd = "mbed-cli update %s --clean" % tag
489
+ logging .info ("Executing command '%s'..." % cmd )
485
490
result = subprocess .call (cmd , shell = True )
486
- os .chdir ("../.." )
491
+ os .chdir (CWD )
487
492
if result :
488
493
return result
489
-
494
+ return 0
495
+
496
+ def symlink_mbedos (config , path , exp_filter ):
497
+ """
498
+ """
499
+ print ("\n Creating mbed-os Symbolic link to '%s'\n " % path )
500
+ for example in config ['examples' ]:
501
+ if example ['name' ] not in exp_filter :
502
+ continue
503
+ for name in get_sub_examples_list (example ):
504
+ os .chdir (name )
505
+ logging .info ("In folder '%s'" % name )
506
+ if os .path .exists ("mbed-os.lib" ):
507
+ os .remove ("mbed-os.lib" )
508
+ else :
509
+ logging .warning ("No 'mbed-os.lib' found in '%s'" % name )
510
+ logging .info ("Creating Symbolic link '%s'->'mbed-os'" % path )
511
+ os .symlink (path , "mbed-os" )
512
+ os .chdir (CWD )
490
513
return 0
491
514
492
515
def fetch_output_image (output ):
0 commit comments