19
19
# Default paths to Mercurial and Git
20
20
hg_cmd = 'hg'
21
21
git_cmd = 'git'
22
- ver = '0.4.0 '
22
+ ver = '0.4.1 '
23
23
24
24
ignores = [
25
25
# Version control folders
@@ -1146,7 +1146,7 @@ def post_action(self):
1146
1146
if not mbed_tools_path :
1147
1147
if not os .path .exists (os .path .join (self .path , '.temp' )):
1148
1148
os .mkdir (os .path .join (self .path , '.temp' ))
1149
- self .get_tools (os .path .join (self .path , '.temp' ))
1149
+ self .add_tools (os .path .join (self .path , '.temp' ))
1150
1150
mbed_tools_path = self .get_tools_dir ()
1151
1151
1152
1152
if not mbed_tools_path :
@@ -1182,7 +1182,7 @@ def post_action(self):
1182
1182
"The missing Python modules are: %s\n "
1183
1183
"You can install all missing modules by opening a command prompt in \" %s\" and running \" pip install -r %s\" " % (', ' .join (missing ), mbed_os_path , fname ))
1184
1184
1185
- def get_tools (self , path ):
1185
+ def add_tools (self , path ):
1186
1186
with cd (path ):
1187
1187
tools_dir = 'tools'
1188
1188
if not os .path .exists (tools_dir ):
@@ -1194,6 +1194,31 @@ def get_tools(self, path):
1194
1194
rmtree_readonly (tools_dir )
1195
1195
raise Exception (128 , "An error occurred while cloning the mbed SDK tools from \" %s\" " % mbed_sdk_tools_url )
1196
1196
1197
+ def get_tools (self ):
1198
+ mbed_tools_path = self .get_tools_dir ()
1199
+ if not mbed_tools_path :
1200
+ error ('The mbed_tools_pathd in "%s". \n Run `mbed deploy` to install dependencies and tools. ' % self .path , - 1 )
1201
+ return mbed_tools_path
1202
+
1203
+ def get_mcu (self , mcu = None ):
1204
+ target = mcu if mcu else self .get_cfg ('TARGET' )
1205
+ if target is None :
1206
+ error ('Please specify compile target using the -m switch or set default target using command "target"' , 1 )
1207
+ return target
1208
+
1209
+ def get_toolchain (self , toolchain = None ):
1210
+ tchain = toolchain if toolchain else program .get_cfg ('TOOLCHAIN' )
1211
+ if tchain is None :
1212
+ error ('Please specify compile toolchain using the -t switch or set default toolchain using command "toolchain"' , 1 )
1213
+ return tchain
1214
+
1215
+ def get_macros (self ):
1216
+ macros = []
1217
+ if os .path .isfile ('MACROS.txt' ):
1218
+ with open ('MACROS.txt' ) as f :
1219
+ macros = f .read ().splitlines ()
1220
+ return macros
1221
+
1197
1222
1198
1223
def formaturl (url , format = "default" ):
1199
1224
url = "%s" % url
@@ -1716,23 +1741,10 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
1716
1741
orig_path = os .getcwd ()
1717
1742
1718
1743
with cd (program .path ):
1719
- mbed_tools_path = program .get_tools_dir ()
1720
- if not mbed_tools_path :
1721
- error ('The mbed tools were not found in "%s". \n Run `mbed deploy` to install dependencies and tools. ' % program .path , - 1 )
1722
- tools_dir = os .path .abspath (mbed_tools_path )
1723
-
1724
- target = mcu if mcu else program .get_cfg ('TARGET' )
1725
- if target is None :
1726
- error ('Please specify compile target using the -m switch or set default target using command "target"' , 1 )
1727
-
1728
- tchain = toolchain if toolchain else program .get_cfg ('TOOLCHAIN' )
1729
- if tchain is None :
1730
- error ('Please specify compile toolchain using the -t switch or set default toolchain using command "toolchain"' , 1 )
1731
-
1732
- macros = []
1733
- if os .path .isfile ('MACROS.txt' ):
1734
- with open ('MACROS.txt' ) as f :
1735
- macros = f .read ().splitlines ()
1744
+ tools_dir = os .path .abspath (program .get_tools ())
1745
+ target = program .get_mcu (mcu )
1746
+ tchain = program .get_toolchain (toolchain )
1747
+ macros = program .get_macros ()
1736
1748
1737
1749
env = os .environ .copy ()
1738
1750
env ['PYTHONPATH' ] = os .path .abspath (program .path )
@@ -1793,16 +1805,15 @@ def test(tlist=False):
1793
1805
program = Program (os .getcwd (), True )
1794
1806
# Change directories to the program root to use mbed OS tools
1795
1807
with cd (program .path ):
1796
- if not program .get_tools_dir ():
1797
- error ('The mbed tools were not found in "%s".' % program .path , - 1 )
1808
+ tools_dir = program .get_tools ()
1798
1809
1799
1810
# Prepare environment variables
1800
1811
env = os .environ .copy ()
1801
1812
env ['PYTHONPATH' ] = '.'
1802
1813
if tlist :
1803
1814
# List all available tests (by default in a human-readable format)
1804
1815
try :
1805
- popen (['python' , os .path .join (program . get_tools_dir () , 'test.py' ), '-l' ] + args , env = env )
1816
+ popen (['python' , os .path .join (tools_dir , 'test.py' ), '-l' ] + args , env = env )
1806
1817
except ProcessException :
1807
1818
error ('Failed to run test script' )
1808
1819
@@ -1819,21 +1830,13 @@ def export(ide=None, mcu=None):
1819
1830
program = Program (os .getcwd (), True )
1820
1831
# Change directories to the program root to use mbed OS tools
1821
1832
with cd (program .path ):
1822
- if not program .get_tools_dir ():
1823
- error ('The mbed tools were not found in "%s".' % program .path , - 1 )
1824
-
1825
- target = mcu if mcu else program .get_cfg ('TARGET' )
1826
- if target is None :
1827
- error ('Please specify export target using the -m switch or set default target using command "target"' , 1 )
1828
-
1829
- macros = []
1830
- if os .path .isfile ('MACROS.txt' ):
1831
- with open ('MACROS.txt' ) as f :
1832
- macros = f .read ().splitlines ()
1833
+ tools_dir = program .get_tools ()
1834
+ target = program .get_mcu (mcu )
1835
+ macros = program .get_macros ()
1833
1836
1834
1837
env = os .environ .copy ()
1835
1838
env ['PYTHONPATH' ] = '.'
1836
- popen (['python' , os .path .join (program . get_tools_dir () , 'project.py' )]
1839
+ popen (['python' , os .path .join (tools_dir , 'project.py' )]
1837
1840
+ list (chain .from_iterable (izip (repeat ('-D' ), macros )))
1838
1841
+ ['-i' , ide , '-m' , target , '--source=%s' % program .path ]
1839
1842
+ args ,
0 commit comments