@@ -836,18 +836,29 @@ def get_os_dir(self):
836
836
else :
837
837
return None
838
838
839
+ # Gets mbed OS tools dir (unified)
840
+ def get_tools_dir (self ):
841
+ mbed_os_path = self .get_os_dir ()
842
+ if mbed_os_path and os .path .isdir (os .path .join (mbed_os_path , 'tools' )):
843
+ return os .path .join (mbed_os_path , 'tools' )
844
+ else :
845
+ return None
846
+
839
847
# Routines after cloning mbed-os
840
848
def post_clone (self ):
841
849
mbed_os_path = self .get_os_dir ()
842
850
if not mbed_os_path :
851
+ warning ("Cannot find the mbed-os directory in \" %s\" " % self .path )
843
852
return False
844
- if not os .path .isdir (os .path .join (mbed_os_path , 'tools' )):
853
+
854
+ mbed_tools_path = self .get_tools_dir ()
855
+ if not mbed_tools_path :
845
856
warning ("Cannot find the mbed-os tools directory in \" %s\" " % mbed_os_path )
846
857
return False
847
858
848
859
if (not os .path .isfile (os .path .join (self .path , 'mbed_settings.py' )) and
849
- os .path .isfile (os .path .join (mbed_os_path , 'tools/ default_settings.py' ))):
850
- shutil .copy (os .path .join (mbed_os_path , 'tools/ default_settings.py' ), os .path .join (self .path , 'mbed_settings.py' ))
860
+ os .path .isfile (os .path .join (mbed_tools_path , 'default_settings.py' ))):
861
+ shutil .copy (os .path .join (mbed_tools_path , 'default_settings.py' ), os .path .join (self .path , 'mbed_settings.py' ))
851
862
852
863
853
864
missing = []
@@ -1311,12 +1322,10 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
1311
1322
orig_path = os .getcwd ()
1312
1323
1313
1324
with cd (program .path ):
1314
- if os .path .isdir ('mbed-os' ): # its application with mbed-os sub dir
1315
- mbed_os_path = os .path .abspath ('mbed-os' )
1316
- elif os .path .basename (os .getcwd ()) == 'mbed-os' :# its standalone mbed-os (is root)
1317
- mbed_os_path = os .path .abspath ('.' )
1318
- else :
1319
- error ('The mbed-os codebase and tools were not found.' , - 1 )
1325
+ mbed_os_path = program .get_os_dir ()
1326
+ tools_dir = os .path .abspath (program .get_tools_dir ())
1327
+ if not mbed_os_path or not tools_dir :
1328
+ error ('The mbed-os codebase or tools were not found in "%s".' % program .path , - 1 )
1320
1329
1321
1330
target = mcu if mcu else program .get_cfg ('TARGET' )
1322
1331
if target is None :
@@ -1331,8 +1340,6 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
1331
1340
with open ('MACROS.txt' ) as f :
1332
1341
macros = f .read ().splitlines ()
1333
1342
1334
- tools_dir = os .path .abspath (os .path .join (mbed_os_path , 'tools' ))
1335
-
1336
1343
env = os .environ .copy ()
1337
1344
env ['PYTHONPATH' ] = os .path .abspath (program .path )
1338
1345
@@ -1390,17 +1397,16 @@ def test(tlist=False):
1390
1397
program = Program (os .getcwd (), True )
1391
1398
# Change directories to the program root to use mbed OS tools
1392
1399
with cd (program .path ):
1393
- # If "mbed-os" folder doesn't exist, error
1394
- if not os .path .isdir ('mbed-os' ):
1395
- error ('The mbed-os codebase and tools were not found in this program.' , - 1 )
1400
+ if not program .get_tools_dir ():
1401
+ error ('The mbed-os codebase or tools were not found in "%s".' % program .path , - 1 )
1396
1402
1397
1403
# Prepare environment variables
1398
1404
env = os .environ .copy ()
1399
1405
env ['PYTHONPATH' ] = '.'
1400
1406
if tlist :
1401
1407
# List all available tests (by default in a human-readable format)
1402
1408
try :
1403
- popen (['python' , 'mbed-os/tools/ test.py' , '-l' ] + args , env = env )
1409
+ popen (['python' , os . path . join ( program . get_tools_dir (), ' test.py') , '-l' ] + args , env = env )
1404
1410
except ProcessException :
1405
1411
error ('Failed to run test script' )
1406
1412
@@ -1417,8 +1423,8 @@ def export(ide=None, mcu=None):
1417
1423
program = Program (os .getcwd (), True )
1418
1424
# Change directories to the program root to use mbed OS tools
1419
1425
with cd (program .path ):
1420
- if not os . path . isdir ( 'mbed-os' ):
1421
- error ('The mbed-os codebase and tools were not found in this program.' , - 1 )
1426
+ if not program . get_tools_dir ( ):
1427
+ error ('The mbed-os codebase or tools were not found in "%s".' % program .path , - 1 )
1422
1428
1423
1429
target = mcu if mcu else program .get_cfg ('TARGET' )
1424
1430
if target is None :
@@ -1431,7 +1437,7 @@ def export(ide=None, mcu=None):
1431
1437
1432
1438
env = os .environ .copy ()
1433
1439
env ['PYTHONPATH' ] = '.'
1434
- popen (['python' , 'mbed-os/tools/ project.py' ]
1440
+ popen (['python' , os . path . join ( program . get_tools_dir (), ' project.py') ]
1435
1441
+ list (chain .from_iterable (izip (repeat ('-D' ), macros )))
1436
1442
+ ['-i' , ide , '-m' , target , '--source=%s' % program .path ]
1437
1443
+ args ,
0 commit comments