35
35
36
36
37
37
# Application version
38
- ver = '0.9.1 '
38
+ ver = '0.9.5 '
39
39
40
40
# Default paths to Mercurial and Git
41
41
hg_cmd = 'hg'
@@ -409,7 +409,7 @@ def discard():
409
409
popen ([hg_cmd , 'update' , '-C' ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
410
410
411
411
def checkout (rev , clean = False , clean_files = False ):
412
- info ("Checkout \" %s\" in %s to %s " % (rev , os .path .basename (os .getcwd ()), rev ))
412
+ info ("Checkout \" %s\" in %s" % (rev if rev else "latest" , os .path .basename (os .getcwd ())))
413
413
if clean_files :
414
414
files = pquery ([hg_cmd , 'status' , '--no-status' , '-ui' ]).splitlines ()
415
415
for f in files :
@@ -449,7 +449,7 @@ def geturl():
449
449
lines = f .read ().splitlines ()
450
450
if tagpaths in lines :
451
451
idx = lines .index (tagpaths )
452
- m = re .match (r'^([\w_]+)\s*=\s*(.*)? $' , lines [idx + 1 ])
452
+ m = re .match (r'^([\w_]+)\s*=\s*(.*)$' , lines [idx + 1 ])
453
453
if m :
454
454
if m .group (1 ) == 'default' :
455
455
default_url = m .group (2 )
@@ -598,7 +598,7 @@ def merge(dest):
598
598
def checkout (rev , clean = False ):
599
599
if not rev :
600
600
return
601
- info ("Checkout \" %s\" in %s to %s " % (rev , os .path .basename (os .getcwd ()), rev ))
601
+ info ("Checkout \" %s\" in %s" % (rev , os .path .basename (os .getcwd ())))
602
602
popen ([git_cmd , 'checkout' , rev ] + (['-f' ] if clean else []) + ([] if very_verbose else ['-q' ]))
603
603
if Git .isdetached (): # try to find associated refs to avoid detached state
604
604
refs = Git .getrefs (rev )
@@ -1286,6 +1286,20 @@ def add_tools(self, path):
1286
1286
rmtree_readonly (tools_dir )
1287
1287
error ("An error occurred while cloning the mbed SDK tools from \" %s\" " % mbed_sdk_tools_url )
1288
1288
1289
+ def update_tools (self , path ):
1290
+ if not os .path .exists (path ):
1291
+ os .mkdir (path )
1292
+ with cd (path ):
1293
+ tools_dir = 'tools'
1294
+ if os .path .exists (tools_dir ):
1295
+ with cd (tools_dir ):
1296
+ try :
1297
+ action ("Updating the mbed 2.0 SDK tools..." )
1298
+ repo = Repo .fromrepo ()
1299
+ repo .update ()
1300
+ except Exception :
1301
+ error ("An error occurred while update the mbed SDK tools from \" %s\" " % mbed_sdk_tools_url )
1302
+
1289
1303
def get_tools (self ):
1290
1304
mbed_tools_path = self .get_tools_dir ()
1291
1305
if not mbed_tools_path :
@@ -1366,7 +1380,7 @@ def set(self, var, val):
1366
1380
lines = []
1367
1381
1368
1382
for line in lines :
1369
- m = re .match (r'^([\w+-]+)\=(.*)? $' , line )
1383
+ m = re .match (r'^([\w+-]+)\=(.*)$' , line )
1370
1384
if m and m .group (1 ) == var :
1371
1385
lines .remove (line )
1372
1386
@@ -1390,7 +1404,7 @@ def get(self, var, default_val=None):
1390
1404
lines = []
1391
1405
1392
1406
for line in lines :
1393
- m = re .match (r'^([\w+-]+)\=(.*)? $' , line )
1407
+ m = re .match (r'^([\w+-]+)\=(.*)$' , line )
1394
1408
if m and m .group (1 ) == var :
1395
1409
return m .group (2 )
1396
1410
return default_val
@@ -1406,7 +1420,7 @@ def list(self):
1406
1420
1407
1421
vars = {}
1408
1422
for line in lines :
1409
- m = re .match (r'^([\w+-]+)\=(.*)? $' , line )
1423
+ m = re .match (r'^([\w+-]+)\=(.*)$' , line )
1410
1424
if m and m .group (1 ) and m .group (1 ) != 'ROOT' :
1411
1425
vars [m .group (1 )] = m .group (2 )
1412
1426
return vars
@@ -1554,11 +1568,15 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
1554
1568
p .set_root ()
1555
1569
if not create_only and not p .get_os_dir () and not p .get_mbedlib_dir ():
1556
1570
url = mbed_lib_url if mbedlib else mbed_os_url
1571
+ d = 'mbed' if mbedlib else 'mbed-os'
1557
1572
try :
1558
1573
with cd (d_path ):
1559
1574
add (url , depth = depth , protocol = protocol , top = False )
1575
+ if not mbedlib :
1576
+ with cd (d ):
1577
+ repo = Repo .fromrepo ()
1578
+ repo .checkout ('latest' )
1560
1579
except Exception as e :
1561
- d = 'mbed' if mbedlib else 'mbed-os'
1562
1580
if os .path .isdir (os .path .join (d_path , d )):
1563
1581
rmtree_readonly (os .path .join (d_path , d ))
1564
1582
raise e
@@ -1707,8 +1725,10 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
1707
1725
repo .ignore (relpath (repo .path , lib .path ))
1708
1726
1709
1727
if top :
1710
- Program (repo .path ).post_action ()
1711
-
1728
+ program = Program (repo .path )
1729
+ program .post_action ()
1730
+ if program .is_classic :
1731
+ program .update_tools ('.temp' )
1712
1732
1713
1733
# Publish command
1714
1734
@subcommand ('publish' ,
@@ -1869,6 +1889,8 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
1869
1889
program = Program (repo .path )
1870
1890
program .set_root ()
1871
1891
program .post_action ()
1892
+ if program .is_classic :
1893
+ program .update_tools ('.temp' )
1872
1894
1873
1895
1874
1896
# Synch command
@@ -2157,7 +2179,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
2157
2179
2158
2180
# Export command
2159
2181
@subcommand ('export' ,
2160
- dict (name = ['-i' , '--ide' ], help = 'IDE to create project files for. Example: UVISION4, UVISION5, GCC_ARM, IAR, COIDE' , required = True ),
2182
+ dict (name = ['-i' , '--ide' ], help = 'IDE to create project files for. Example: UVISION4, UVISION5, GCC_ARM, IAR, COIDE' ),
2161
2183
dict (name = ['-m' , '--target' ], help = 'Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
2162
2184
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
2163
2185
dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
@@ -2194,7 +2216,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False):
2194
2216
2195
2217
popen (['python' , '-u' , os .path .join (tools_dir , 'project.py' )]
2196
2218
+ list (chain .from_iterable (izip (repeat ('-D' ), macros )))
2197
- + ['-i' , ide .lower (), '-m' , target ]
2219
+ + ( ['-i' , ide .lower (), '-m' , target ] if ide else [])
2198
2220
+ (['-c' ] if clean else [])
2199
2221
+ list (chain .from_iterable (izip (repeat ('--source' ), source )))
2200
2222
+ args ,
@@ -2335,6 +2357,11 @@ def main():
2335
2357
2336
2358
# Help messages adapt based on current dir
2337
2359
cwd_root = os .getcwd ()
2360
+
2361
+ if sys .version_info [0 ] != 2 or sys .version_info [1 ] < 7 :
2362
+ error (
2363
+ "mbed CLI is compatible with Python version >= 2.7 and < 3.0\n "
2364
+ "Please refer to the online guide available at https://github.com/ARMmbed/mbed-cli" )
2338
2365
2339
2366
# Parse/run command
2340
2367
if len (sys .argv ) <= 1 :
0 commit comments