85
85
86
86
# mbed url is subset of hg. mbed doesn't support ssh transport
87
87
regex_mbed_url = r'^(https?)://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+)/?$'
88
- regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{12,40})?/?$'
88
+ regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{12,40}|tip )?/?$'
89
89
90
90
# default mbed OS url
91
91
mbed_os_url = 'https://github.com/ARMmbed/mbed-os'
@@ -231,34 +231,17 @@ def init(path, url):
231
231
if not os .path .exists (path ):
232
232
os .mkdir (path )
233
233
with cd (path ):
234
- if not os .path .exists ('.' + Bld .name ):
235
- os .mkdir ('.' + Bld .name )
236
-
237
- fl = os .path .join ('.' + Bld .name , 'bldrc' )
238
- try :
239
- with open (fl , 'w' ) as f :
240
- f .write (url )
241
- except IOError :
242
- error ("Unable to write bldrc file in \" %s\" " % fl , 1 )
234
+ Bld .seturl (url )
243
235
244
236
def clone (url , path = None , rev = None , depth = None , protocol = None ):
245
237
m = Bld .isurl (url )
246
238
if not m :
247
239
raise ProcessException (1 , "Not an mbed library build URL" )
248
240
return False
249
241
250
- arch_url = m .group (1 ) + '/archive/' + rev + '.zip'
251
- arch_dir = m .group (7 ) + '-' + rev
252
-
253
242
try :
254
- Bld .init (path , url + '/' + rev )
255
- with cd (path ):
256
- if not os .path .exists (arch_dir ):
257
- Bld .dlunzip (arch_url , rev )
243
+ Bld .init (path , url + '/tip' )
258
244
except Exception as e :
259
- with cd (path ):
260
- if os .path .exists (arch_dir ):
261
- rmtree_readonly (arch_dir )
262
245
error (e [1 ], e [0 ])
263
246
264
247
def dlunzip (url , rev ):
@@ -284,7 +267,6 @@ def dlunzip(url, rev):
284
267
rmtree_readonly (arch_dir )
285
268
raise Exception (128 , "An error occurred while unpacking mbed library archive \" %s\" in \" %s\" " % (tmp_file , os .getcwd ()))
286
269
287
-
288
270
def add (dest ):
289
271
return True
290
272
@@ -302,22 +284,37 @@ def publish(repo, all=None):
302
284
def fetch (repo ):
303
285
error ("mbed library builds do not support pushing" )
304
286
287
+ def checkout (repo , rev , clean = False ):
288
+ url = Bld .geturl ()
289
+ m = Bld .isurl (url )
290
+ if not m :
291
+ raise ProcessException (1 , "Not an mbed library build URL" )
292
+ return False
293
+
294
+ arch_url = m .group (1 ) + '/archive/' + rev + '.zip'
295
+ arch_dir = m .group (7 ) + '-' + rev
296
+
297
+ try :
298
+ if not os .path .exists (arch_dir ):
299
+ Bld .dlunzip (arch_url , rev )
300
+ except Exception as e :
301
+ if os .path .exists (arch_dir ):
302
+ rmtree_readonly (arch_dir )
303
+ error (e [1 ], e [0 ])
304
+ Bld .seturl (url + '/' + rev )
305
+
305
306
def update (repo , rev = None , clean = False ):
306
307
m = Bld .isurl (repo .url )
307
308
rev = Hg .remoteid (m .group (1 ), rev )
308
-
309
309
if not rev :
310
310
error ("Unable to fetch late mbed library revision" )
311
311
312
312
if rev != repo .rev :
313
- log ("Cleaning up build folder" )
314
- for fl in os .listdir (repo . path ):
313
+ log ("Cleaning up library build folder" )
314
+ for fl in os .listdir ('.' ):
315
315
if not fl .startswith ('.' ):
316
- if os .path .isfile (os .path .join (repo .path , fl )):
317
- os .remove (os .path .join (repo .path , fl ))
318
- else :
319
- shutil .rmtree (os .path .join (repo .path , fl ))
320
- return Bld .clone (repo .url , repo .path , rev )
316
+ os .remove (fl ) if os .path .isfile (fl ) else shutil .rmtree (fl )
317
+ return Bld .checkout (repo , rev )
321
318
322
319
def status ():
323
320
return False
@@ -334,17 +331,28 @@ def outgoing():
334
331
def isdetached ():
335
332
return False
336
333
334
+ def seturl (url ):
335
+ if not os .path .exists ('.' + Bld .name ):
336
+ os .mkdir ('.' + Bld .name )
337
+
338
+ fl = os .path .join ('.' + Bld .name , 'bldrc' )
339
+ try :
340
+ with open (fl , 'w' ) as f :
341
+ f .write (url )
342
+ except IOError :
343
+ error ("Unable to write bldrc file in \" %s\" " % fl , 1 )
344
+
337
345
def geturl ():
338
346
with open (os .path .join ('.bld' , 'bldrc' )) as f :
339
347
url = f .read ().strip ()
340
348
m = Bld .isurl (url )
341
- return m .group (1 )+ '/builds'
349
+ return m .group (1 )+ '/builds' if m else ''
342
350
343
351
def getrev ():
344
352
with open (os .path .join ('.bld' , 'bldrc' )) as f :
345
353
url = f .read ().strip ()
346
354
m = Bld .isurl (url )
347
- return m .group (8 )
355
+ return m .group (8 ) if m else ''
348
356
349
357
def getbranch ():
350
358
return "default"
@@ -414,6 +422,8 @@ def fetch(repo):
414
422
popen ([hg_cmd , 'pull' ] + (['-v' ] if verbose else ['-q' ]))
415
423
416
424
def checkout (repo , rev , clean = False ):
425
+ if not rev :
426
+ return False
417
427
if repo :
418
428
log ("Checkout \" %s\" to %s" % (repo .name , repo .revtype (rev , True )))
419
429
popen ([hg_cmd , 'update' ] + (['-r' , rev ] if rev else []) + (['-C' ] if clean else []) + (['-v' ] if verbose else ['-q' ]))
@@ -613,6 +623,8 @@ def discard(repo):
613
623
popen ([git_cmd , 'clean' , '-fdq' ] + ([] if verbose else ['-q' ])) # cleans up untracked files and folders
614
624
615
625
def checkout (repo , rev , clean = False ):
626
+ if not rev :
627
+ return False
616
628
if repo :
617
629
log ("Checkout \" %s\" to %s" % (repo .name , repo .revtype (rev , True )))
618
630
popen ([git_cmd , 'checkout' , rev ] + ([] if verbose else ['-q' ]))
@@ -1332,7 +1344,15 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1332
1344
action ("%s \" %s\" from \" %s/\" %s" % (text , relpath (cwd_root , repo .path ), repo .url , ' at ' + (repo .revtype (repo .rev , True ))))
1333
1345
for _ , scm in sorted_scms :
1334
1346
try :
1335
- scm .clone (repo .url , repo .path , repo .rev , depth = depth , protocol = protocol )
1347
+ scm .clone (repo .url , repo .path , depth = depth , protocol = protocol )
1348
+ with cd (repo .path ):
1349
+ try :
1350
+ scm .checkout (repo , repo .rev , True )
1351
+ except ProcessException as e :
1352
+ err = "Unable to checkout \" %s\" to %s" % (repo .name , repo .revtype (repo .rev , True ))
1353
+ if depth :
1354
+ err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev , True )))
1355
+ warning (err ) if ignore else error (err , e [0 ])
1336
1356
break
1337
1357
except ProcessException :
1338
1358
if os .path .isdir (repo .path ):
@@ -1346,7 +1366,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1346
1366
cwd_root = repo .path
1347
1367
1348
1368
with cd (repo .path ):
1349
- deploy (ignore , depth = depth , protocol = protocol , top = False )
1369
+ deploy (ignore = ignore , depth = depth , protocol = protocol , top = False )
1350
1370
1351
1371
if top :
1352
1372
program = Program (repo .path )
@@ -1385,7 +1405,7 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
1385
1405
dict (name = '--depth' , nargs = '?' , help = 'Number of revisions to fetch from the remote repository. Default: all revisions.' ),
1386
1406
dict (name = '--protocol' , nargs = '?' , help = 'Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.' ),
1387
1407
help = 'Add a library and its dependencies into the current %s or specified destination path.' % cwd_type )
1388
- def add (url , path = None , depth = None , protocol = None ):
1408
+ def add (url , path = None , ignore = False , depth = None , protocol = None ):
1389
1409
repo = Repo .fromrepo ()
1390
1410
1391
1411
lib = Repo .fromurl (url , path )
@@ -1480,7 +1500,15 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
1480
1500
cwd_type if top else cwd_dest ,
1481
1501
os .path .basename (repo .path ) if top else relpath (cwd_root , repo .path ),
1482
1502
repo .revtype (rev , True )))
1483
- repo .scm .update (repo , rev , clean )
1503
+
1504
+ try :
1505
+ repo .scm .update (repo , rev , clean )
1506
+ except ProcessException as e :
1507
+ err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (rev , True ))
1508
+ if depth :
1509
+ err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev , True )))
1510
+ warning (err ) if ignore else error (err , e [0 ])
1511
+
1484
1512
repo .rm_untracked ()
1485
1513
if top and cwd_type == 'library' :
1486
1514
repo .sync ()
0 commit comments