Skip to content

Commit e535766

Browse files
committed
Change mbed config to mbed compile --config
Merge `mbed default` and `mbed global` to `mbed config` and use `mbed config --global` syntax similar to git Move `mbed compile --tests` to `mbed test --compile`
1 parent d316265 commit e535766

File tree

2 files changed

+90
-118
lines changed

2 files changed

+90
-118
lines changed

mbed/mbed.py

Lines changed: 89 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
# Application version
35-
ver = '0.6.3'
35+
ver = '0.6.5'
3636

3737
# Default paths to Mercurial and Git
3838
hg_cmd = 'hg'
@@ -1336,8 +1336,8 @@ def formaturl(url, format="default"):
13361336

13371337
# Subparser handling
13381338
parser = argparse.ArgumentParser(prog='mbed',
1339-
description="Command-line code management tool for ARM mbed OS - http://www.mbed.com\nversion %s\n\n" % ver,
1340-
formatter_class=argparse.RawTextHelpFormatter)
1339+
description="Command-line code management tool for ARM mbed OS - http://www.mbed.com\nversion %s\n\nUse 'mbed <command> -h|--help' for detailed help.\nOnline manual and guides at www.mbed.com/cli_help" % ver,
1340+
formatter_class=argparse.RawDescriptionHelpFormatter)
13411341
subparsers = parser.add_subparsers(title="Commands", metavar=" ")
13421342

13431343
# Process handling
@@ -1382,10 +1382,10 @@ def thunk(parsed_args):
13821382
dict(name='--program', action='store_true', help='Force creation of an mbed program. Default: auto.'),
13831383
dict(name='--library', action='store_true', help='Force creation of an mbed library. Default: auto.'),
13841384
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.'),
13861386
dict(name='--depth', nargs='?', help='Number of revisions to fetch the mbed OS repository when creating new program. Default: all revisions.'),
13871387
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.\nThe latest mbed-os release will be downloaded/added as well if a new program is created (unless --create-only is specified).\nSupported source control management: git, hg',
13891389
help='Create new mbed program or library')
13901390
def new(name, scm='git', program=False, library=False, mbedlib=False, create_only=False, depth=None, protocol=None):
13911391
global cwd_root
@@ -1814,15 +1814,15 @@ def status_(ignore=False):
18141814
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
18151815
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
18161816
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'),
18191817
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'),
18201820
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'),
18221823
description='Compile program using the native mbed OS build system.',
18231824
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):
18261826
# Gather remaining arguments
18271827
args = remainder
18281828
# Find the root of the program
@@ -1850,21 +1850,18 @@ def compile(toolchain=None, mcu=None, source=False, build=False, clean=False, su
18501850
macros = program.get_macros()
18511851

18521852
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)
18561854

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')]
18591858
+ ['-t', tchain, '-m', target]
1860-
+ (['-c'] if clean else [])
18611859
+ list(chain.from_iterable(izip(repeat('--source'), source)))
1862-
+ ['--build', build]
1863-
+ ['--test-spec', test_spec]
18641860
+ (['-v'] if verbose else [])
1865-
+ args,
1861+
+ (list(chain.from_iterable(izip(repeat('--prefix'), prefix))) if prefix else []),
18661862
env=env)
1867-
elif compile_library:
1863+
1864+
if compile_library:
18681865
# Compile as a library (current dir is default)
18691866
if not build:
18701867
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
18921889
env=env)
18931890

18941891

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'),
18971896
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, uARM, GCC_ARM, IAR'),
18981897
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
18991898
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
19041906
# Find the root of the program
19051907
program = Program(os.getcwd(), True)
19061908
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
19071909
orig_path = os.getcwd()
19081910

19091911
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()
19251913

19261914
env = os.environ.copy()
19271915
env['PYTHONPATH'] = os.path.abspath(program.path)
19281916

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')
19391923

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)
19531928

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)
19631939

19641940

19651941
# Export command
19661942
@subcommand('export',
19671943
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION,DS5,IAR', required=True),
19681944
dict(name=['-m', '--mcu'], help='Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
19691945
description='Generate project files for desktop IDEs for the current program.',
1970-
help='Generate IDE project')
1946+
help='Generate an IDE project')
19711947
def export(ide=None, mcu=None):
19721948
# Gather remaining arguments
19731949
args = remainder
@@ -2009,6 +1985,45 @@ def detect():
20091985
env=env)
20101986

20111987

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+
20122027
# Build system and exporters
20132028
@subcommand('target',
20142029
dict(name='name', nargs='?', help='Default target name. Example: K64F, NUCLEO_F401RE, NRF51822...'),
@@ -2022,49 +2037,6 @@ def target_(name=None):
20222037
def toolchain_(name=None):
20232038
return default_('toolchain', name)
20242039

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-
20682040

20692041
# Parse/run command
20702042
if len(sys.argv) <= 1:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def read(fname):
1919
setup(
2020
name="mbed-cli",
2121
packages=["mbed"],
22-
version="0.6.3",
22+
version="0.6.5",
2323
url='http://github.com/ARMmbed/mbed-cli',
2424
author='ARM mbed',
2525
author_email='[email protected]',

0 commit comments

Comments
 (0)