Skip to content

Commit 0d5afb9

Browse files
committed
Merge pull request #171 from ARMmbed/get_config_command
Added 'config' subcommand for viewing the project configuration
2 parents 31a84f0 + 15de42b commit 0d5afb9

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

mbed/mbed.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Default paths to Mercurial and Git
2020
hg_cmd = 'hg'
2121
git_cmd = 'git'
22-
ver = '0.3.2'
22+
ver = '0.4.0'
2323

2424
ignores = [
2525
# Version control folders
@@ -1842,6 +1842,49 @@ def default_(name, value=None):
18421842
program.set_cfg(var, value)
18431843
action('%s now set as default %s in program "%s"' % (value, name, program.name))
18441844

1845+
# 'config' command (calls into tools/get_config.py)
1846+
@subcommand('config',
1847+
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, uARM, GCC_ARM, IAR'),
1848+
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
1849+
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
1850+
dict(name='--prefix', action='append', help='Restrict listing to parameters that have this prefix'),
1851+
help='Compile program using the native mbed OS build system.')
1852+
def config(toolchain=None, mcu=None, source=False, prefix=None):
1853+
# Find the root of the program
1854+
program = Program(os.getcwd(), True)
1855+
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
1856+
orig_path = os.getcwd()
1857+
1858+
with cd(program.path):
1859+
mbed_tools_path = program.get_tools_dir()
1860+
if not mbed_tools_path:
1861+
error('The mbed tools were not found in "%s". \n Run `mbed deploy` to install dependencies and tools. ' % program.path, -1)
1862+
tools_dir = os.path.abspath(mbed_tools_path)
1863+
1864+
if not os.path.isfile(os.path.join(tools_dir, 'get_config.py')):
1865+
error("'get_config_py' not found in tools/. Please update your mbed-os clone.", -1)
1866+
1867+
target = mcu if mcu else program.get_cfg('TARGET')
1868+
if target is None:
1869+
error('Please specify compile target using the -m switch or set default target using command "target"', 1)
1870+
1871+
tchain = toolchain if toolchain else program.get_cfg('TOOLCHAIN')
1872+
if tchain is None:
1873+
error('Please specify compile toolchain using the -t switch or set default toolchain using command "toolchain"', 1)
1874+
1875+
env = os.environ.copy()
1876+
env['PYTHONPATH'] = os.path.abspath(program.path)
1877+
1878+
if not source or len(source) == 0:
1879+
source = [os.path.relpath(program.path, orig_path)]
1880+
1881+
popen(['python', os.path.join(tools_dir, 'get_config.py')]
1882+
+ ['-t', tchain, '-m', target]
1883+
+ list(chain.from_iterable(izip(repeat('--source'), source)))
1884+
+ (['-v'] if verbose else [])
1885+
+ (list(chain.from_iterable(izip(repeat('--prefix'), prefix))) if prefix else []),
1886+
env=env)
1887+
18451888
# Parse/run command
18461889
if len(sys.argv) <= 1:
18471890
parser.print_help()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def read(fname):
1111
setup(
1212
name="mbed-cli",
1313
packages=["mbed"],
14-
version="0.3.2",
14+
version="0.4.0",
1515
url='http://github.com/ARMmbed/mbed-cli',
1616
author='ARM mbed',
1717
author_email='[email protected]',
@@ -24,4 +24,4 @@ def read(fname):
2424
]
2525
},
2626
long_description=read('pypi_readme.rst'),
27-
)
27+
)

0 commit comments

Comments
 (0)