Skip to content

Commit 6990026

Browse files
committed
Add options to mbed export to match project.py (#200)
1 parent a9ea7ed commit 6990026

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

mbed/mbed.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,30 +2022,46 @@ def test_(toolchain=None, mcu=None, compile_list=False, run_list=False, compile_
20222022

20232023
# Export command
20242024
@subcommand('export',
2025-
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION,DS5,IAR', required=True),
2025+
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION4, UVISION5, GCC_ARM, IAR, COIDE', required=True),
20262026
dict(name=['-m', '--mcu'], help='Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2027+
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
2028+
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
2029+
dict(name=['-S', '--supported'], dest='supported', action='store_true', help='Shows supported matrix of targets and toolchains'),
20272030
help='Generate an IDE project',
20282031
description=(
20292032
"Generate IDE project files for the current program."))
2030-
def export(ide=None, mcu=None):
2033+
def export(ide=None, mcu=None, source=False, clean=False, supported=False):
20312034
# Gather remaining arguments
20322035
args = remainder
20332036
# Find the root of the program
20342037
program = Program(os.getcwd(), True)
2038+
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
2039+
orig_path = os.getcwd()
20352040
# Change directories to the program root to use mbed OS tools
20362041
with cd(program.path):
20372042
tools_dir = program.get_tools()
2038-
target = program.get_mcu(mcu)
2039-
macros = program.get_macros()
2040-
20412043
env = os.environ.copy()
20422044
env['PYTHONPATH'] = os.path.abspath(program.path)
20432045

2046+
if supported:
20442047
popen(['python', '-u', os.path.join(tools_dir, 'project.py')]
2045-
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2046-
+ ['-i', ide, '-m', target, '--source=%s' % program.path]
2047-
+ args,
2048+
+ (['-S'] if supported else []) + (['-v'] if very_verbose else []),
20482049
env=env)
2050+
return
2051+
2052+
target = program.get_mcu(mcu)
2053+
macros = program.get_macros()
2054+
2055+
if not source or len(source) == 0:
2056+
source = [os.path.relpath(program.path, orig_path)]
2057+
2058+
popen(['python', '-u', os.path.join(tools_dir, 'project.py')]
2059+
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2060+
+ ['-i', ide.lower(), '-m', target]
2061+
+ (['-c'] if clean else [])
2062+
+ list(chain.from_iterable(izip(repeat('--source'), source)))
2063+
+ args,
2064+
env=env)
20492065

20502066

20512067
# Test command

0 commit comments

Comments
 (0)