32
32
33
33
34
34
# Application version
35
- ver = '0.6.3 '
35
+ ver = '0.6.5 '
36
36
37
37
# Default paths to Mercurial and Git
38
38
hg_cmd = 'hg'
@@ -1336,8 +1336,8 @@ def formaturl(url, format="default"):
1336
1336
1337
1337
# Subparser handling
1338
1338
parser = argparse .ArgumentParser (prog = 'mbed' ,
1339
- description = "Command-line code management tool for ARM mbed OS - http://www.mbed.com\n version %s\n \n " % ver ,
1340
- formatter_class = argparse .RawTextHelpFormatter )
1339
+ description = "Command-line code management tool for ARM mbed OS - http://www.mbed.com\n version %s\n \n Use 'mbed <command> -h|--help' for detailed help. \n Online manual and guides at www.mbed.com/cli_help " % ver ,
1340
+ formatter_class = argparse .RawDescriptionHelpFormatter )
1341
1341
subparsers = parser .add_subparsers (title = "Commands" , metavar = " " )
1342
1342
1343
1343
# Process handling
@@ -1382,10 +1382,10 @@ def thunk(parsed_args):
1382
1382
dict (name = '--program' , action = 'store_true' , help = 'Force creation of an mbed program. Default: auto.' ),
1383
1383
dict (name = '--library' , action = 'store_true' , help = 'Force creation of an mbed library. Default: auto.' ),
1384
1384
dict (name = '--mbedlib' , action = 'store_true' , help = 'Add the mbed library instead of mbed-os into the program.' ),
1385
- dict (name = '--create-only' , action = 'store_true' , help = 'Only create program, do not import mbed-os or mbed library.' ),
1385
+ dict (name = '--create-only' , action = 'store_true' , help = 'Only create a program, do not import mbed-os or mbed library.' ),
1386
1386
dict (name = '--depth' , nargs = '?' , help = 'Number of revisions to fetch the mbed OS repository when creating new program. Default: all revisions.' ),
1387
1387
dict (name = '--protocol' , nargs = '?' , help = 'Transport protocol when fetching the mbed OS repository when creating new program. Supported: https, http, ssh, git. Default: inferred from URL.' ),
1388
- description = 'Create new mbed program or library. Will create a new library when called from inside a program. Supported SCMs: %s.' % ( ', ' . join ([ s . name for s in scms . values ()])) ,
1388
+ description = 'Creates a new mbed program if executed within a non-program location. Alternatively creates an mbed library if executed within an existing mbed program.\n The latest mbed-os release will be downloaded/added as well if a new program is created (unless --create-only is specified). \n Supported source control management: git, hg' ,
1389
1389
help = 'Create new mbed program or library' )
1390
1390
def new (name , scm = 'git' , program = False , library = False , mbedlib = False , create_only = False , depth = None , protocol = None ):
1391
1391
global cwd_root
@@ -1814,15 +1814,15 @@ def status_(ignore=False):
1814
1814
dict (name = ['-m' , '--mcu' ], help = 'Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
1815
1815
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
1816
1816
dict (name = '--build' , help = 'Build directory. Default: .build/' ),
1817
- dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
1818
- dict (name = ['-S' , '--supported' ], dest = 'supported' , action = 'store_true' , help = 'Displays supported matrix of targets and toolchains' ),
1819
1817
dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current %s as a static library.' % cwd_type ),
1818
+ dict (name = '--config' , dest = 'compile_config' , help = 'Show run-time compile configuration' ),
1819
+ dict (name = '--prefix' , dest = 'config_prefix' , action = 'append' , help = 'Restrict listing to parameters that have this prefix' ),
1820
1820
dict (name = '--tests' , dest = 'compile_tests' , action = 'store_true' , help = 'Compile tests in TESTS directory.' ),
1821
- dict (name = '--test_spec' , dest = "test_spec" , help = "Destination path for a test spec file that can be used by the Greentea automated test tool. (Default is 'test_spec.json')" ),
1821
+ dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
1822
+ dict (name = ['-S' , '--supported' ], dest = 'supported' , action = 'store_true' , help = 'Shows supported matrix of targets and toolchains' ),
1822
1823
description = 'Compile program using the native mbed OS build system.' ,
1823
1824
help = 'Compile program using the mbed build tools' )
1824
- def compile (toolchain = None , mcu = None , source = False , build = False , clean = False , supported = False , compile_library = False , compile_tests = False , test_spec = "test_spec.json" ):
1825
- args = remainder
1825
+ 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 ):
1826
1826
# Gather remaining arguments
1827
1827
args = remainder
1828
1828
# Find the root of the program
@@ -1850,21 +1850,18 @@ def compile(toolchain=None, mcu=None, source=False, build=False, clean=False, su
1850
1850
macros = program .get_macros ()
1851
1851
1852
1852
if compile_tests :
1853
- # Compile tests
1854
- if not build :
1855
- build = os .path .join (os .path .relpath (program .path , orig_path ), '.build/tests' , target , tchain )
1853
+ return test_ (toolchain = toolchain , mcu = mcu , source = source , build = build , compile_tests = True )
1856
1854
1857
- popen (['python' , '-u' , os .path .join (tools_dir , 'test.py' )]
1858
- + list (chain .from_iterable (izip (repeat ('-D' ), macros )))
1855
+ if compile_config :
1856
+ # Compile configuration
1857
+ popen (['python' , os .path .join (tools_dir , 'get_config.py' )]
1859
1858
+ ['-t' , tchain , '-m' , target ]
1860
- + (['-c' ] if clean else [])
1861
1859
+ list (chain .from_iterable (izip (repeat ('--source' ), source )))
1862
- + ['--build' , build ]
1863
- + ['--test-spec' , test_spec ]
1864
1860
+ (['-v' ] if verbose else [])
1865
- + args ,
1861
+ + ( list ( chain . from_iterable ( izip ( repeat ( '--prefix' ), prefix ))) if prefix else []) ,
1866
1862
env = env )
1867
- elif compile_library :
1863
+
1864
+ if compile_library :
1868
1865
# Compile as a library (current dir is default)
1869
1866
if not build :
1870
1867
build = os .path .join (os .path .relpath (program .path , orig_path ), '.build' , 'libraries' , os .path .basename (orig_path ), target , tchain )
@@ -1892,82 +1889,61 @@ def compile(toolchain=None, mcu=None, source=False, build=False, clean=False, su
1892
1889
env = env )
1893
1890
1894
1891
1895
- # 'config' command (calls into tools/get_config.py)
1896
- @subcommand ('config' ,
1892
+ # Test command
1893
+ @subcommand ('test' ,
1894
+ dict (name = ['-L' , '--list' ], dest = 'list_tests' , action = 'store_true' , help = 'List all of the available tests' ),
1895
+ dict (name = ['-C' , '--compile' ], dest = 'compile_tests' , action = 'store_true' , help = 'List all of the available tests' ),
1897
1896
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, uARM, GCC_ARM, IAR' ),
1898
1897
dict (name = ['-m' , '--mcu' ], help = 'Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
1899
1898
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
1900
- dict (name = '--prefix' , action = 'append' , help = 'Restrict listing to parameters that have this prefix' ),
1901
- description = 'Show program\' s compile configuration.' ,
1902
- help = 'Show compile configuration.' )
1903
- def config (toolchain = None , mcu = None , source = False , prefix = None ):
1899
+ dict (name = '--build' , help = 'Build directory. Default: .build/' ),
1900
+ dict (name = '--test_spec' , dest = "test_spec" , help = "Destination path for a test spec file that can be used by the Greentea automated test tool. (Default is 'test_spec.json')" ),
1901
+ description = 'Find and build tests in a program and its libraries.' ,
1902
+ help = 'List, build and run tests' )
1903
+ def test_ (list_tests = False , compile_tests = False , test_spec = "test_spec.json" ):
1904
+ # Gather remaining arguments
1905
+ args = remainder
1904
1906
# Find the root of the program
1905
1907
program = Program (os .getcwd (), True )
1906
1908
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
1907
1909
orig_path = os .getcwd ()
1908
1910
1909
1911
with cd (program .path ):
1910
- mbed_tools_path = program .get_tools_dir ()
1911
- if not mbed_tools_path :
1912
- error ('The mbed tools were not found in "%s". \n Run `mbed deploy` to install dependencies and tools. ' % program .path , - 1 )
1913
- tools_dir = os .path .abspath (mbed_tools_path )
1914
-
1915
- if not os .path .isfile (os .path .join (tools_dir , 'get_config.py' )):
1916
- error ("'get_config_py' not found in tools/. Please update mbed-os to get the latest tools." , - 1 )
1917
-
1918
- target = mcu if mcu else program .get_cfg ('TARGET' )
1919
- if target is None :
1920
- error ('Please specify compile target using the -m switch or set default target using command "target"' , 1 )
1921
-
1922
- tchain = toolchain if toolchain else program .get_cfg ('TOOLCHAIN' )
1923
- if tchain is None :
1924
- error ('Please specify compile toolchain using the -t switch or set default toolchain using command "toolchain"' , 1 )
1912
+ tools_dir = program .get_tools ()
1925
1913
1926
1914
env = os .environ .copy ()
1927
1915
env ['PYTHONPATH' ] = os .path .abspath (program .path )
1928
1916
1929
- if not source or len (source ) == 0 :
1930
- source = [os .path .relpath (program .path , orig_path )]
1931
-
1932
- popen (['python' , os .path .join (tools_dir , 'get_config.py' )]
1933
- + ['-t' , tchain , '-m' , target ]
1934
- + list (chain .from_iterable (izip (repeat ('--source' ), source )))
1935
- + (['-v' ] if verbose else [])
1936
- + (list (chain .from_iterable (izip (repeat ('--prefix' ), prefix ))) if prefix else []),
1937
- env = env )
1938
-
1917
+ if list_tests :
1918
+ # List all available tests (by default in a human-readable format)
1919
+ try :
1920
+ popen (['python' , '-u' , os .path .join (tools_dir , 'test.py' ), '-l' ] + args , env = env )
1921
+ except ProcessException :
1922
+ error ('Failed to run test script' )
1939
1923
1940
- # Test command
1941
- @subcommand ('test' ,
1942
- dict (name = ['-l' , '--list' ], dest = 'tlist' , action = 'store_true' , help = 'List all of the available tests' ),
1943
- description = 'Find and build tests in a program and its libraries.' ,
1944
- help = 'Find and build tests' )
1945
- def test (tlist = False ):
1946
- # Gather remaining arguments
1947
- args = remainder
1948
- # Find the root of the program
1949
- program = Program (os .getcwd (), True )
1950
- # Change directories to the program root to use mbed OS tools
1951
- with cd (program .path ):
1952
- tools_dir = program .get_tools ()
1924
+ if compile_tests :
1925
+ # Compile tests
1926
+ if not build :
1927
+ build = os .path .join (os .path .relpath (program .path , orig_path ), '.build/tests' , target , tchain )
1953
1928
1954
- # Prepare environment variables
1955
- env = os .environ .copy ()
1956
- env ['PYTHONPATH' ] = '.'
1957
- if tlist :
1958
- # List all available tests (by default in a human-readable format)
1959
- try :
1960
- popen (['python' , '-u' , os .path .join (tools_dir , 'test.py' ), '-l' ] + args , env = env )
1961
- except ProcessException :
1962
- error ('Failed to run test script' )
1929
+ popen (['python' , '-u' , os .path .join (tools_dir , 'test.py' )]
1930
+ + list (chain .from_iterable (izip (repeat ('-D' ), macros )))
1931
+ + ['-t' , tchain , '-m' , target ]
1932
+ + (['-c' ] if clean else [])
1933
+ + list (chain .from_iterable (izip (repeat ('--source' ), source )))
1934
+ + ['--build' , build ]
1935
+ + ['--test-spec' , test_spec ]
1936
+ + (['-v' ] if verbose else [])
1937
+ + args ,
1938
+ env = env )
1963
1939
1964
1940
1965
1941
# Export command
1966
1942
@subcommand ('export' ,
1967
1943
dict (name = ['-i' , '--ide' ], help = 'IDE to create project files for. Example: UVISION,DS5,IAR' , required = True ),
1968
1944
dict (name = ['-m' , '--mcu' ], help = 'Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
1969
1945
description = 'Generate project files for desktop IDEs for the current program.' ,
1970
- help = 'Generate IDE project' )
1946
+ help = 'Generate an IDE project' )
1971
1947
def export (ide = None , mcu = None ):
1972
1948
# Gather remaining arguments
1973
1949
args = remainder
@@ -2009,6 +1985,45 @@ def detect():
2009
1985
env = env )
2010
1986
2011
1987
1988
+ # Generic config command
1989
+ @subcommand ('config' ,
1990
+ dict (name = 'var' , help = 'Variable name. E.g. "target", "toolchain", "protocol"' ),
1991
+ dict (name = 'value' , nargs = '?' , help = 'Value. Will show the currently set default value for a variable if not specified.' ),
1992
+ dict (name = ['-G' , '--global' ], dest = 'global_cfg' , action = 'store_true' , help = 'Use global settings, not local' ),
1993
+ dict (name = ['-U' , '--unset' ], dest = 'unset' , action = 'store_true' , help = 'Unset the specified variable.' ),
1994
+ description = 'Set or get global options for all programs. Global options may be overridden by program defaults.' ,
1995
+ help = 'Tool configuration' )
1996
+ def config_ (var , value = None , global_cfg = False , unset = False ):
1997
+ name = var
1998
+ var = str (var ).upper ()
1999
+
2000
+ if global_cfg :
2001
+ # Global configuration
2002
+ g = Global ()
2003
+ if unset :
2004
+ g .set_cfg (var , None )
2005
+ action ('Unset global %s' % name )
2006
+ elif value :
2007
+ g .set_cfg (var , value )
2008
+ action ('%s now set as global %s' % (value , name ))
2009
+ else :
2010
+ value = g .get_cfg (var )
2011
+ action (('%s' % value ) if value else 'No global %s set' % (name ))
2012
+ else :
2013
+ # Find the root of the program
2014
+ program = Program (os .getcwd ())
2015
+ with cd (program .path ):
2016
+ if unset :
2017
+ program .set_cfg (var , None )
2018
+ action ('Unset default %s in program "%s"' % (name , program .name ))
2019
+ elif value :
2020
+ program .set_cfg (var , value )
2021
+ action ('%s now set as default %s in program "%s"' % (value , name , program .name ))
2022
+ else :
2023
+ value = program .get_cfg (var )
2024
+ action (('%s' % value ) if value else 'No default %s set in program "%s"' % (name , program .name ))
2025
+
2026
+
2012
2027
# Build system and exporters
2013
2028
@subcommand ('target' ,
2014
2029
dict (name = 'name' , nargs = '?' , help = 'Default target name. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
@@ -2022,49 +2037,6 @@ def target_(name=None):
2022
2037
def toolchain_ (name = None ):
2023
2038
return default_ ('toolchain' , name )
2024
2039
2025
- # Generic config command
2026
- @subcommand ('default' ,
2027
- dict (name = 'name' , help = 'Variable name. E.g. "target", "toolchain", "protocol"' ),
2028
- dict (name = 'value' , nargs = '?' , help = 'Value. Will show the currently set default value for a variable if not specified.' ),
2029
- dict (name = ['-u' , '--unset' ], dest = 'unset' , action = 'store_true' , help = 'Unset the specified variable.' ),
2030
- description = 'Set or get program default options.' ,
2031
- help = 'Program options' )
2032
- def default_ (name , value = None , unset = False ):
2033
- # Find the root of the program
2034
- program = Program (os .getcwd ())
2035
- # Change current dir to program root
2036
- with cd (program .path ):
2037
- var = str (name ).upper ()
2038
- if unset :
2039
- program .set_cfg (var , None )
2040
- action ('Unset default %s in program "%s"' % (name , program .name ))
2041
- elif value :
2042
- program .set_cfg (var , value )
2043
- action ('%s now set as default %s in program "%s"' % (value , name , program .name ))
2044
- else :
2045
- value = program .get_cfg (var )
2046
- action (('%s' % value ) if value else 'No default %s set in program "%s"' % (name , program .name ))
2047
-
2048
- # Generic config command
2049
- @subcommand ('global' ,
2050
- dict (name = 'name' , help = 'Variable name. E.g. "target", "toolchain", "protocol"' ),
2051
- dict (name = 'value' , nargs = '?' , help = 'Value. Will show the currently set default value for a variable if not specified.' ),
2052
- dict (name = ['-u' , '--unset' ], dest = 'unset' , action = 'store_true' , help = 'Unset the specified variable.' ),
2053
- description = 'Set or get global options for all programs. Global options may be overridden by program defaults.' ,
2054
- help = 'Global options' )
2055
- def default_ (name , value = None , unset = False ):
2056
- g = Global ()
2057
- var = str (name ).upper ()
2058
- if unset :
2059
- g .set_cfg (var , None )
2060
- action ('Unset global %s' % name )
2061
- elif value :
2062
- g .set_cfg (var , value )
2063
- action ('%s now set as global %s' % (value , name ))
2064
- else :
2065
- value = g .get_cfg (var )
2066
- action (('%s' % value ) if value else 'No global %s set' % (name ))
2067
-
2068
2040
2069
2041
# Parse/run command
2070
2042
if len (sys .argv ) <= 1 :
0 commit comments