35
35
36
36
37
37
# Application version
38
- ver = '0.7.17 '
38
+ ver = '0.8.0 '
39
39
40
40
# Default paths to Mercurial and Git
41
41
hg_cmd = 'hg'
103
103
104
104
# mbed url is subset of hg. mbed doesn't support ssh transport
105
105
regex_mbed_url = r'^(https?)://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+)/?$'
106
- regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{12 ,40}|tip)?/?$'
106
+ regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{6 ,40}|tip)?/?$'
107
107
108
108
# base url for all mbed related repos (used as sort of index)
109
109
mbed_base_url = 'https://github.com/ARMmbed'
@@ -384,8 +384,8 @@ def remove(dest):
384
384
except ProcessException :
385
385
pass
386
386
387
- def commit ():
388
- popen ([hg_cmd , 'commit' ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
387
+ def commit (msg = None ):
388
+ popen ([hg_cmd , 'commit' ] + (['-m' , msg ] if msg else []) + ([ '- v' ] if very_verbose else ([] if verbose else ['-q' ])))
389
389
390
390
def publish (all_refs = None ):
391
391
popen ([hg_cmd , 'push' ] + (['--new-branch' ] if all_refs else []) + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
@@ -553,8 +553,8 @@ def remove(dest):
553
553
except ProcessException :
554
554
pass
555
555
556
- def commit ():
557
- popen ([git_cmd , 'commit' , '-a' ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
556
+ def commit (msg = None ):
557
+ popen ([git_cmd , 'commit' , '-a' ] + (['-m' , msg ] if msg else []) + ([ '- v' ] if very_verbose else ([] if verbose else ['-q' ])))
558
558
559
559
def publish (all_refs = None ):
560
560
if all_refs :
@@ -783,6 +783,8 @@ def fromurl(cls, url, path=None):
783
783
repo .path = os .path .abspath (path or os .path .join (os .getcwd (), repo .name ))
784
784
repo .url = formaturl (m_repo_url .group (1 ))
785
785
repo .rev = m_repo_url .group (3 )
786
+ if repo .rev and not re .match (r'^([a-fA-F0-9]{6,40})$' , repo .rev ):
787
+ error ('Invalid revision (%s)' % repo .rev , - 1 )
786
788
else :
787
789
error ('Invalid repository (%s)' % url .strip (), - 1 )
788
790
@@ -870,8 +872,8 @@ def pathtype(cls, path=None):
870
872
def revtype (cls , rev , ret_rev = False ):
871
873
if rev is None or len (rev ) == 0 :
872
874
return 'latest' + (' revision in the current branch' if ret_rev else '' )
873
- elif re .match (r'^([a-zA-Z0 -9]{12 ,40})$' , rev ) or re .match (r'^([0-9]+)$' , rev ):
874
- return 'rev' + (' #' + rev if ret_rev else '' )
875
+ elif re .match (r'^([a-fA-F0 -9]{6 ,40})$' , rev ) or re .match (r'^([0-9]+)$' , rev ):
876
+ return 'rev' + (' #' + rev [ 0 : 12 ] if ret_rev else '' )
875
877
else :
876
878
return 'branch' + (' ' + rev if ret_rev else '' )
877
879
@@ -1170,12 +1172,27 @@ def get_tools_dir(self):
1170
1172
# mbed Classic deployed tools
1171
1173
paths .append ([self .path , '.temp' , 'tools' ])
1172
1174
1173
- fl = 'make.py'
1175
+ return self ._find_file_paths (paths , 'make.py' )
1176
+
1177
+ def get_requirements (self ):
1178
+ paths = []
1179
+ mbed_os_path = self .get_os_dir ()
1180
+ if mbed_os_path :
1181
+ paths .append ([mbed_os_path ])
1182
+ # mbed-os not identified but tools found under cwd/tools
1183
+ paths .append ([self .path , 'core' ])
1184
+ # mbed Classic deployed tools
1185
+ paths .append ([self .path , '.temp' , 'tools' ])
1186
+ # current dir
1187
+ paths .append ([self .path ])
1188
+
1189
+ return self ._find_file_paths (paths , 'requirements.txt' )
1190
+
1191
+ def _find_file_paths (self , paths , fl ):
1174
1192
for p in paths :
1175
1193
path = os .path .join (* p )
1176
1194
if os .path .isdir (path ) and os .path .isfile (os .path .join (path , fl )):
1177
1195
return os .path .join (path )
1178
-
1179
1196
return None
1180
1197
1181
1198
def get_env (self ):
@@ -1184,7 +1201,7 @@ def get_env(self):
1184
1201
compilers = ['ARM' , 'GCC_ARM' , 'IAR' ]
1185
1202
for c in compilers :
1186
1203
if self .get_cfg (c + '_PATH' ):
1187
- env [c + '_PATH' ] = self .get_cfg (c + '_PATH' )
1204
+ env ['MBED_' + c + '_PATH' ] = self .get_cfg (c + '_PATH' )
1188
1205
1189
1206
return env
1190
1207
@@ -1204,16 +1221,13 @@ def post_action(self):
1204
1221
os .path .isfile (os .path .join (mbed_tools_path , 'default_settings.py' ))):
1205
1222
shutil .copy (os .path .join (mbed_tools_path , 'default_settings.py' ), os .path .join (self .path , 'mbed_settings.py' ))
1206
1223
1207
- mbed_os_path = self .get_os_dir ()
1208
- if not mbed_os_path :
1209
- return False
1210
-
1224
+ req_path = self .get_requirements () or self .path
1225
+ req_file = 'requirements.txt'
1211
1226
missing = []
1212
- fname = 'requirements.txt'
1213
1227
try :
1214
- import pip
1215
- installed_packages = [ package . project_name . lower () for package in pip . get_installed_distributions ()]
1216
- with open ( os . path . join ( mbed_os_path , fname ), 'r' ) as f :
1228
+ with open ( os . path . join ( os . path . join ( req_path , req_file )), 'r' ) as f :
1229
+ import pip
1230
+ installed_packages = [ package . project_name . lower () for package in pip . get_installed_distributions ()]
1217
1231
for line in f .read ().splitlines ():
1218
1232
pkg = re .sub (r'^([\w-]+).*$' , r'\1' , line ).lower ()
1219
1233
if not pkg in installed_packages :
@@ -1229,7 +1243,7 @@ def post_action(self):
1229
1243
"The mbed build tools in this program require Python modules that are not installed.\n "
1230
1244
"This might prevent compiling code or exporting to IDEs and other toolchains.\n "
1231
1245
"The missing Python modules are: %s\n "
1232
- "You can install all missing modules by running \" pip install -r %s\" in \" %s\" " % (', ' .join (missing ), fname , mbed_os_path ))
1246
+ "You can install all missing modules by running \" pip install -r %s\" in \" %s\" " % (', ' .join (missing ), req_file , req_path ))
1233
1247
1234
1248
def add_tools (self , path ):
1235
1249
if not os .path .exists (path ):
@@ -1631,14 +1645,15 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
1631
1645
# Publish command
1632
1646
@subcommand ('publish' ,
1633
1647
dict (name = ['-A' , '--all' ], dest = 'all_refs' , action = 'store_true' , help = 'Publish all branches, including new ones. Default: push only the current branch.' ),
1648
+ dict (name = ['-M' , '--message' ], dest = 'msg' , type = str , nargs = '?' , help = 'Commit message. Default: prompts for commit message.' ),
1634
1649
help = 'Publish program or library' ,
1635
1650
description = (
1636
1651
"Publishes this %s and all dependencies to their associated remote\n repository URLs.\n "
1637
1652
"This command performs various consistency checks for local uncommitted changes\n "
1638
1653
"and unpublished revisions and encourages to commit/push them.\n "
1639
1654
"Online guide about collaboration is available at:\n "
1640
1655
"www.mbed.com/collab_guide" % cwd_type ))
1641
- def publish (all_refs = None , top = True ):
1656
+ def publish (all_refs = None , msg = None , top = True ):
1642
1657
if top :
1643
1658
action ("Checking for local modifications..." )
1644
1659
@@ -1652,14 +1667,17 @@ def publish(all_refs=None, top=True):
1652
1667
if lib .check_repo ():
1653
1668
with cd (lib .path ):
1654
1669
progress ()
1655
- publish (False , all_refs )
1670
+ publish (all_refs , msg = msg , top = False )
1656
1671
1657
1672
sync (recursive = False )
1658
1673
1659
1674
if repo .dirty ():
1660
1675
action ("Uncommitted changes in %s \" %s\" in \" %s\" " % (repo .pathtype (repo .path ), repo .name , repo .path ))
1661
- raw_input ('Press enter to commit and publish: ' )
1662
- repo .commit ()
1676
+ if msg :
1677
+ repo .commit (msg )
1678
+ else :
1679
+ raw_input ('Press enter to commit and publish: ' )
1680
+ repo .commit ()
1663
1681
1664
1682
try :
1665
1683
outgoing = repo .outgoing ()
@@ -1886,18 +1904,14 @@ def status_(ignore=False):
1886
1904
dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current %s as a static library.' % cwd_type ),
1887
1905
dict (name = '--config' , dest = 'compile_config' , action = 'store_true' , help = 'Show run-time compile configuration' ),
1888
1906
dict (name = '--prefix' , dest = 'config_prefix' , action = 'append' , help = 'Restrict listing to parameters that have this prefix' ),
1889
- dict (name = '--tests' , dest = 'compile_tests' , action = 'store_true' , help = 'An alias to \' mbed test --compile\' ' ),
1890
1907
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
1891
1908
dict (name = '--build' , help = 'Build directory. Default: .build/' ),
1892
1909
dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
1910
+ dict (name = ['-N' , '--artifact-name' ], help = 'Name of the built program or library' ),
1893
1911
dict (name = ['-S' , '--supported' ], dest = 'supported' , action = 'store_true' , help = 'Shows supported matrix of targets and toolchains' ),
1894
1912
help = 'Compile code using the mbed build tools' ,
1895
1913
description = ("Compile this program using the mbed build tools." ))
1896
- def compile_ (toolchain = None , mcu = None , source = False , build = False , compile_library = False , compile_config = False , config_prefix = None , compile_tests = False , clean = False , supported = False ):
1897
- # Pipe --tests to mbed tests command
1898
- if compile_tests :
1899
- return test_ (toolchain = toolchain , mcu = mcu , source = source , build = build , clean = clean , compile_only = True )
1900
-
1914
+ def compile_ (toolchain = None , mcu = None , source = False , build = False , compile_library = False , compile_config = False , config_prefix = None , clean = False , artifact_name = None , supported = False ):
1901
1915
# Gather remaining arguments
1902
1916
args = remainder
1903
1917
# Find the root of the program
@@ -1944,6 +1958,7 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
1944
1958
+ (['-c' ] if clean else [])
1945
1959
+ list (chain .from_iterable (izip (repeat ('--source' ), source )))
1946
1960
+ ['--build' , build ]
1961
+ + (['--artifact-name' , artifact_name ] if artifact_name else [])
1947
1962
+ (['-v' ] if verbose else [])
1948
1963
+ args ,
1949
1964
env = env )
@@ -1958,6 +1973,7 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
1958
1973
+ (['-c' ] if clean else [])
1959
1974
+ list (chain .from_iterable (izip (repeat ('--source' ), source )))
1960
1975
+ ['--build' , build ]
1976
+ + (['--artifact-name' , artifact_name ] if artifact_name else [])
1961
1977
+ (['-v' ] if verbose else [])
1962
1978
+ args ,
1963
1979
env = env )
0 commit comments