Skip to content

Add command 'detect' and -S/--supported to mbed compile #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,11 +1158,11 @@ def post_action(self):

if len(missing):
warning(
"-------------------------------------------------------------------------------\n"
"-----------------------------------------------------------------\n"
"The mbed build tools in this program require Python modules that are not installed.\n"
"This might prevent you from compiling your code or exporting to IDEs and other toolchains.\n"
"This might prevent compiling code or exporting to IDEs and other toolchains.\n"
"The missing Python modules are: %s\n"
"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))
"You can install all missing modules by running \"pip install -r %s\" in \"%s\"" % (', '.join(missing), mbed_os_path, fname))

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

with cd(program.path):
tools_dir = os.path.abspath(program.get_tools())
target = program.get_mcu(mcu)
tchain = program.get_toolchain(toolchain)
macros = program.get_macros()

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

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

if supported:
popen(['python', '-u', os.path.join(tools_dir, 'make.py')]
+ (['-S'] if supported else []) + (['-v'] if verbose else [])
+ args,
env=env)
return

target = program.get_mcu(mcu)
tchain = program.get_toolchain(toolchain)
macros = program.get_macros()

if compile_tests:
# Compile tests
if not build:
Expand Down Expand Up @@ -1829,6 +1837,26 @@ def export(ide=None, mcu=None):
env=env)


# Test command
@subcommand('detect',
help='Detect mbed targets/boards connected to this system.')
def detect():
# Gather remaining arguments
args = remainder
# Find the root of the program
program = Program(os.getcwd(), True)
# Change directories to the program root to use mbed OS tools
with cd(program.path):
tools_dir = program.get_tools()

# Prepare environment variables
env = os.environ.copy()
env['PYTHONPATH'] = '.'
popen(['python', '-u', os.path.join(tools_dir, 'detect_targets.py')]
+ args,
env=env)


# Build system and exporters
@subcommand('target',
dict(name='name', nargs='?', help='Default target name. Example: K64F, NUCLEO_F401RE, NRF51822...'),
Expand Down Expand Up @@ -1929,5 +1957,9 @@ def config(toolchain=None, mcu=None, source=False, prefix=None):
error('OS Error: %s' % e[1], e[0])
except KeyboardInterrupt as e:
error('User aborted!', 255)

except Exception as e:
if verbose:
import traceback
traceback.print_exc(file=sys.stdout)
error("Unknown Error: %s" % e, 255)
sys.exit(status or 0)