Skip to content

Commit a755832

Browse files
committed
Add -o to mbed compile and pass it to the underlying tools
Add documentation regarding `mbed compile -o` Rename --mcu references to --target (as per Simon's suggestion)
1 parent c69c904 commit a755832

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ The arguments for *compile* are:
315315
* `-t <TOOLCHAIN>` to select a toolchain (of those defined in `mbed_settings.py`, see above). The value can be either `ARM` (ARM Compiler 5), `GCC_ARM` (GNU ARM Embedded), or `IAR` (IAR Embedded Workbench for ARM).
316316
* `--source <SOURCE>` to select the source directory. The default is `.` (the current directorty). You can specify multiple source locations, even outside the program tree.
317317
* `--build <BUILD>` to select the build directory. Default: `.build/` inside your program.
318+
* `--options <OPTIONS>` to select compile options. Examples: "debug-info": will generate debugging information; "small-build" will use microlib/nanolib, but limit RTOS to single thread; "save-asm": will save the asm generated by the compiler
318319
* `--library` to compile the code as a [static .a/.ar library](#compiling-static-libraries).
319320
* `--config` to inspect the run-time compile configuration (see below).
320321
* `-S` or `--supported` shows a matrix of the supported targets and toolchains.

mbed/mbed.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,9 +1284,9 @@ def get_tools(self):
12841284
error('The mbed tools were not found in "%s". \n Run `mbed deploy` to install dependencies and tools. ' % self.path, -1)
12851285
return mbed_tools_path
12861286

1287-
def get_mcu(self, mcu=None):
1287+
def get_target(self, target=None):
12881288
target_cfg = self.get_cfg('TARGET')
1289-
target = mcu if mcu else target_cfg
1289+
target = target if target else target_cfg
12901290
if target is None:
12911291
error('Please specify compile target using the -m switch or set default target using command "target"', 1)
12921292
return target
@@ -1959,7 +1959,8 @@ def status_(ignore=False):
19591959
# Compile command which invokes the mbed OS native build system
19601960
@subcommand('compile',
19611961
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
1962-
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
1962+
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
1963+
dict(name=['-o', '--options'], action='append', help='Compile options. Examples: "debug-info": generate debugging information; "small-build" to use microlib/nanolib, but limit RTOS to single thread; "save-asm": save the asm generated by the compiler'),
19631964
dict(name='--library', dest='compile_library', action='store_true', help='Compile the current program or library as a static library.'),
19641965
dict(name='--config', dest='compile_config', action='store_true', help='Show run-time compile configuration'),
19651966
dict(name='--prefix', dest='config_prefix', action='append', help='Restrict listing to parameters that have this prefix'),
@@ -1970,7 +1971,7 @@ def status_(ignore=False):
19701971
dict(name=['-S', '--supported'], dest='supported', action='store_true', help='Shows supported matrix of targets and toolchains'),
19711972
help='Compile code using the mbed build tools',
19721973
description=("Compile this program using the mbed build tools."))
1973-
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):
1974+
def compile_(toolchain=None, target=None, options=False, compile_library=False, compile_config=False, config_prefix=None, source=False, build=False, clean=False, artifact_name=None, supported=False):
19741975
# Gather remaining arguments
19751976
args = remainder
19761977
# Find the root of the program
@@ -1994,14 +1995,15 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
19941995
env=env)
19951996
return
19961997

1997-
target = program.get_mcu(mcu)
1998+
target = program.get_target(target)
19981999
tchain = program.get_toolchain(toolchain)
19992000
macros = program.get_macros()
20002001

20012002
if compile_config:
20022003
# Compile configuration
20032004
popen(['python', os.path.join(tools_dir, 'get_config.py')]
20042005
+ ['-t', tchain, '-m', target]
2006+
+ list(chain.from_iterable(izip(repeat('-o'), options or [])))
20052007
+ list(chain.from_iterable(izip(repeat('--source'), source)))
20062008
+ (['-v'] if verbose else [])
20072009
+ (list(chain.from_iterable(izip(repeat('--prefix'), config_prefix))) if config_prefix else []),
@@ -2014,9 +2016,10 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
20142016
popen(['python', '-u', os.path.join(tools_dir, 'build.py')]
20152017
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
20162018
+ ['-t', tchain, '-m', target]
2017-
+ (['-c'] if clean else [])
2019+
+ list(chain.from_iterable(izip(repeat('-o'), options or [])))
20182020
+ list(chain.from_iterable(izip(repeat('--source'), source)))
20192021
+ ['--build', build]
2022+
+ (['-c'] if clean else [])
20202023
+ (['--artifact-name', artifact_name] if artifact_name else [])
20212024
+ (['-v'] if verbose else [])
20222025
+ args,
@@ -2029,9 +2032,10 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
20292032
popen(['python', '-u', os.path.join(tools_dir, 'make.py')]
20302033
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
20312034
+ ['-t', tchain, '-m', target]
2032-
+ (['-c'] if clean else [])
2035+
+ list(chain.from_iterable(izip(repeat('-o'), options or [])))
20332036
+ list(chain.from_iterable(izip(repeat('--source'), source)))
20342037
+ ['--build', build]
2038+
+ (['-c'] if clean else [])
20352039
+ (['--artifact-name', artifact_name] if artifact_name else [])
20362040
+ (['-v'] if verbose else [])
20372041
+ args,
@@ -2043,7 +2047,7 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
20432047
# Test command
20442048
@subcommand('test',
20452049
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
2046-
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2050+
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
20472051
dict(name='--compile-list', dest='compile_list', action='store_true', help='List all tests that can be built'),
20482052
dict(name='--run-list', dest='run_list', action='store_true', help='List all built tests that can be ran'),
20492053
dict(name='--compile', dest='compile_only', action='store_true', help='Only compile tests'),
@@ -2056,15 +2060,15 @@ def compile_(toolchain=None, mcu=None, source=False, build=False, compile_librar
20562060
dict(name='--test-spec', dest="test_spec", help="Path used for the test spec file used when building and running tests (the default path is the build directory)"),
20572061
help='Find, build and run tests',
20582062
description=("Find, build, and run tests in a program and libraries"))
2059-
def test_(toolchain=None, mcu=None, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, options=False, build=False, clean=False, test_spec=None):
2063+
def test_(toolchain=None, target=None, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, options=False, build=False, clean=False, test_spec=None):
20602064
# Gather remaining arguments
20612065
args = remainder
20622066
# Find the root of the program
20632067
program = Program(os.getcwd(), True)
20642068
# Save original working directory
20652069
orig_path = os.getcwd()
20662070

2067-
target = program.get_mcu(mcu)
2071+
target = program.get_target(target)
20682072
tchain = program.get_toolchain(toolchain)
20692073
macros = program.get_macros()
20702074
tools_dir = program.get_tools()
@@ -2134,14 +2138,14 @@ def test_(toolchain=None, mcu=None, compile_list=False, run_list=False, compile_
21342138
# Export command
21352139
@subcommand('export',
21362140
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION4, UVISION5, GCC_ARM, IAR, COIDE', required=True),
2137-
dict(name=['-m', '--mcu'], help='Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2141+
dict(name=['-m', '--target'], help='Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
21382142
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
21392143
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
21402144
dict(name=['-S', '--supported'], dest='supported', action='store_true', help='Shows supported matrix of targets and toolchains'),
21412145
help='Generate an IDE project',
21422146
description=(
21432147
"Generate IDE project files for the current program."))
2144-
def export(ide=None, mcu=None, source=False, clean=False, supported=False):
2148+
def export(ide=None, target=None, source=False, clean=False, supported=False):
21452149
# Gather remaining arguments
21462150
args = remainder
21472151
# Find the root of the program
@@ -2161,7 +2165,7 @@ def export(ide=None, mcu=None, source=False, clean=False, supported=False):
21612165
env=env)
21622166
return
21632167

2164-
target = program.get_mcu(mcu)
2168+
target = program.get_target(target)
21652169
macros = program.get_macros()
21662170

21672171
if not source or len(source) == 0:

0 commit comments

Comments
 (0)