Skip to content

Commit f2b53d3

Browse files
authored
Merge pull request #188 from screamerbg/development
Add command 'detect' and -S/--supported to `mbed compile`
2 parents a6a5b55 + 5c766dc commit f2b53d3

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

mbed/mbed.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,11 +1158,11 @@ def post_action(self):
11581158

11591159
if len(missing):
11601160
warning(
1161-
"-------------------------------------------------------------------------------\n"
1161+
"-----------------------------------------------------------------\n"
11621162
"The mbed build tools in this program require Python modules that are not installed.\n"
1163-
"This might prevent you from compiling your code or exporting to IDEs and other toolchains.\n"
1163+
"This might prevent compiling code or exporting to IDEs and other toolchains.\n"
11641164
"The missing Python modules are: %s\n"
1165-
"You can install all missing modules by opening a command prompt in \"%s\" and running \"pip install -r %s\"" % (', '.join(missing), mbed_os_path, fname))
1165+
"You can install all missing modules by running \"pip install -r %s\" in \"%s\"" % (', '.join(missing), mbed_os_path, fname))
11661166

11671167
def add_tools(self, path):
11681168
with cd(path):
@@ -1709,14 +1709,15 @@ def status_(ignore=False):
17091709
@subcommand('compile',
17101710
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, uARM, GCC_ARM, IAR'),
17111711
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
1712-
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
17131712
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
17141713
dict(name='--build', help='Build directory. Default: .build/'),
1714+
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
1715+
dict(name=['-S', '--supported'], dest='supported', action='store_true', help='Displays supported matrix of targets and toolchains'),
17151716
dict(name='--library', dest='compile_library', action='store_true', help='Compile the current %s as a static library.' % cwd_type),
17161717
dict(name='--tests', dest='compile_tests', action='store_true', help='Compile tests in TESTS directory.'),
17171718
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')"),
17181719
help='Compile program using the native mbed OS build system.')
1719-
def compile(toolchain=None, mcu=None, clean=False, source=False, build=False, compile_library=False, compile_tests=False, test_spec="test_spec.json"):
1720+
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"):
17201721
args = remainder
17211722
# Gather remaining arguments
17221723
args = remainder
@@ -1727,16 +1728,23 @@ def compile(toolchain=None, mcu=None, clean=False, source=False, build=False, co
17271728

17281729
with cd(program.path):
17291730
tools_dir = os.path.abspath(program.get_tools())
1730-
target = program.get_mcu(mcu)
1731-
tchain = program.get_toolchain(toolchain)
1732-
macros = program.get_macros()
1733-
17341731
env = os.environ.copy()
17351732
env['PYTHONPATH'] = os.path.abspath(program.path)
17361733

17371734
if not source or len(source) == 0:
17381735
source = [os.path.relpath(program.path, orig_path)]
17391736

1737+
if supported:
1738+
popen(['python', '-u', os.path.join(tools_dir, 'make.py')]
1739+
+ (['-S'] if supported else []) + (['-v'] if verbose else [])
1740+
+ args,
1741+
env=env)
1742+
return
1743+
1744+
target = program.get_mcu(mcu)
1745+
tchain = program.get_toolchain(toolchain)
1746+
macros = program.get_macros()
1747+
17401748
if compile_tests:
17411749
# Compile tests
17421750
if not build:
@@ -1829,6 +1837,26 @@ def export(ide=None, mcu=None):
18291837
env=env)
18301838

18311839

1840+
# Test command
1841+
@subcommand('detect',
1842+
help='Detect mbed targets/boards connected to this system.')
1843+
def detect():
1844+
# Gather remaining arguments
1845+
args = remainder
1846+
# Find the root of the program
1847+
program = Program(os.getcwd(), True)
1848+
# Change directories to the program root to use mbed OS tools
1849+
with cd(program.path):
1850+
tools_dir = program.get_tools()
1851+
1852+
# Prepare environment variables
1853+
env = os.environ.copy()
1854+
env['PYTHONPATH'] = '.'
1855+
popen(['python', '-u', os.path.join(tools_dir, 'detect_targets.py')]
1856+
+ args,
1857+
env=env)
1858+
1859+
18321860
# Build system and exporters
18331861
@subcommand('target',
18341862
dict(name='name', nargs='?', help='Default target name. Example: K64F, NUCLEO_F401RE, NRF51822...'),
@@ -1929,5 +1957,9 @@ def config(toolchain=None, mcu=None, source=False, prefix=None):
19291957
error('OS Error: %s' % e[1], e[0])
19301958
except KeyboardInterrupt as e:
19311959
error('User aborted!', 255)
1932-
1960+
except Exception as e:
1961+
if verbose:
1962+
import traceback
1963+
traceback.print_exc(file=sys.stdout)
1964+
error("Unknown Error: %s" % e, 255)
19331965
sys.exit(status or 0)

0 commit comments

Comments
 (0)