3535
3636
3737# Application version
38- ver = '0.7.17 '
38+ ver = '0.8.0 '
3939
4040# Default paths to Mercurial and Git
4141hg_cmd = 'hg'
103103
104104# mbed url is subset of hg. mbed doesn't support ssh transport
105105regex_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)?/?$'
107107
108108# base url for all mbed related repos (used as sort of index)
109109mbed_base_url = 'https://github.com/ARMmbed'
@@ -384,8 +384,8 @@ def remove(dest):
384384 except ProcessException :
385385 pass
386386
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' ])))
389389
390390 def publish (all_refs = None ):
391391 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):
553553 except ProcessException :
554554 pass
555555
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' ])))
558558
559559 def publish (all_refs = None ):
560560 if all_refs :
@@ -783,6 +783,8 @@ def fromurl(cls, url, path=None):
783783 repo .path = os .path .abspath (path or os .path .join (os .getcwd (), repo .name ))
784784 repo .url = formaturl (m_repo_url .group (1 ))
785785 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 )
786788 else :
787789 error ('Invalid repository (%s)' % url .strip (), - 1 )
788790
@@ -870,8 +872,8 @@ def pathtype(cls, path=None):
870872 def revtype (cls , rev , ret_rev = False ):
871873 if rev is None or len (rev ) == 0 :
872874 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 '' )
875877 else :
876878 return 'branch' + (' ' + rev if ret_rev else '' )
877879
@@ -1170,12 +1172,27 @@ def get_tools_dir(self):
11701172 # mbed Classic deployed tools
11711173 paths .append ([self .path , '.temp' , 'tools' ])
11721174
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 ):
11741192 for p in paths :
11751193 path = os .path .join (* p )
11761194 if os .path .isdir (path ) and os .path .isfile (os .path .join (path , fl )):
11771195 return os .path .join (path )
1178-
11791196 return None
11801197
11811198 def get_env (self ):
@@ -1184,7 +1201,7 @@ def get_env(self):
11841201 compilers = ['ARM' , 'GCC_ARM' , 'IAR' ]
11851202 for c in compilers :
11861203 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' )
11881205
11891206 return env
11901207
@@ -1204,16 +1221,13 @@ def post_action(self):
12041221 os .path .isfile (os .path .join (mbed_tools_path , 'default_settings.py' ))):
12051222 shutil .copy (os .path .join (mbed_tools_path , 'default_settings.py' ), os .path .join (self .path , 'mbed_settings.py' ))
12061223
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'
12111226 missing = []
1212- fname = 'requirements.txt'
12131227 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 ()]
12171231 for line in f .read ().splitlines ():
12181232 pkg = re .sub (r'^([\w-]+).*$' , r'\1' , line ).lower ()
12191233 if not pkg in installed_packages :
@@ -1229,7 +1243,7 @@ def post_action(self):
12291243 "The mbed build tools in this program require Python modules that are not installed.\n "
12301244 "This might prevent compiling code or exporting to IDEs and other toolchains.\n "
12311245 "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 ))
12331247
12341248 def add_tools (self , path ):
12351249 if not os .path .exists (path ):
@@ -1631,14 +1645,15 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
16311645# Publish command
16321646@subcommand ('publish' ,
16331647 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.' ),
16341649 help = 'Publish program or library' ,
16351650 description = (
16361651 "Publishes this %s and all dependencies to their associated remote\n repository URLs.\n "
16371652 "This command performs various consistency checks for local uncommitted changes\n "
16381653 "and unpublished revisions and encourages to commit/push them.\n "
16391654 "Online guide about collaboration is available at:\n "
16401655 "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 ):
16421657 if top :
16431658 action ("Checking for local modifications..." )
16441659
@@ -1652,14 +1667,17 @@ def publish(all_refs=None, top=True):
16521667 if lib .check_repo ():
16531668 with cd (lib .path ):
16541669 progress ()
1655- publish (False , all_refs )
1670+ publish (all_refs , msg = msg , top = False )
16561671
16571672 sync (recursive = False )
16581673
16591674 if repo .dirty ():
16601675 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 ()
16631681
16641682 try :
16651683 outgoing = repo .outgoing ()
@@ -1886,18 +1904,14 @@ def status_(ignore=False):
18861904 dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current %s as a static library.' % cwd_type ),
18871905 dict (name = '--config' , dest = 'compile_config' , action = 'store_true' , help = 'Show run-time compile configuration' ),
18881906 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\' ' ),
18901907 dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
18911908 dict (name = '--build' , help = 'Build directory. Default: .build/' ),
18921909 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' ),
18931911 dict (name = ['-S' , '--supported' ], dest = 'supported' , action = 'store_true' , help = 'Shows supported matrix of targets and toolchains' ),
18941912 help = 'Compile code using the mbed build tools' ,
18951913 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 ):
19011915 # Gather remaining arguments
19021916 args = remainder
19031917 # Find the root of the program
@@ -1944,6 +1958,7 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
19441958 + (['-c' ] if clean else [])
19451959 + list (chain .from_iterable (izip (repeat ('--source' ), source )))
19461960 + ['--build' , build ]
1961+ + (['--artifact-name' , artifact_name ] if artifact_name else [])
19471962 + (['-v' ] if verbose else [])
19481963 + args ,
19491964 env = env )
@@ -1958,6 +1973,7 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
19581973 + (['-c' ] if clean else [])
19591974 + list (chain .from_iterable (izip (repeat ('--source' ), source )))
19601975 + ['--build' , build ]
1976+ + (['--artifact-name' , artifact_name ] if artifact_name else [])
19611977 + (['-v' ] if verbose else [])
19621978 + args ,
19631979 env = env )
0 commit comments