Skip to content

UX: Fallback to detect connected target when none specified #774

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 2 commits into from
Nov 1, 2018
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
15 changes: 8 additions & 7 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,13 +1714,11 @@ def get_target(self, target=None):
target_cfg = self.get_cfg('TARGET')
target = target if target else target_cfg

if target and (target.lower() == 'detect' or target.lower() == 'auto'):
if not target or (target.lower() == 'detect' or target.lower() == 'auto'):
detected = self.detect_single_target()
if detected:
target = detected['name']

if target is None:
error("Please specify target using the -m switch or set default target using command \"mbed target\"", 1)
return target

def get_toolchain(self, toolchain=None):
Expand Down Expand Up @@ -1762,7 +1760,7 @@ def detect_single_target(self, info=None):
elif len(targets) > 1:
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system.", 1)
elif len(targets) == 0:
error("No targets were detected.\nPlease make sure a target board is connected to this system.", 1)
error("No targets were detected.\nPlease make sure a target board is connected to this system.\nAlternatively, you can specify target using the -m switch or set default target using command \"mbed target\"", 1)
else:
action("Detected \"%s\" connected to \"%s\" and using com port \"%s\"" % (targets[0]['name'], targets[0]['mount'], targets[0]['serial']))
info = targets[0]
Expand Down Expand Up @@ -2610,6 +2608,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
program.check_requirements(True)
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
orig_path = getcwd()
orig_target = target

with cd(program.path):
tools_dir = os.path.abspath(program.get_tools())
Expand Down Expand Up @@ -2716,7 +2715,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
if not connected:
error("The target board you compiled for is not connected to your system.\nPlease reconnect it and retry the last command.", 1)

program.set_defaults(target=target, toolchain=tchain)
program.set_defaults(target=orig_target, toolchain=tchain)


# Test command
Expand Down Expand Up @@ -2780,6 +2779,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,

# Save original working directory
orig_path = getcwd()
orig_target = target

macros = program.get_macros()
tools_dir = program.get_tools()
Expand Down Expand Up @@ -2934,7 +2934,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
if run_only or build_and_run_tests:
popen(icetea_command)

program.set_defaults(target=target, toolchain=tchain)
program.set_defaults(target=orig_target, toolchain=tchain)


# device management commands
Expand Down Expand Up @@ -3010,6 +3010,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False, ap
program.check_requirements(True)
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
orig_path = getcwd()
orig_target = target
# Change directories to the program root to use mbed OS tools
with cd(program.path):
tools_dir = program.get_tools()
Expand Down Expand Up @@ -3044,7 +3045,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False, ap
+ args,
env=env)

program.set_defaults(target=target)
program.set_defaults(target=orig_target)


# Detect command
Expand Down