Skip to content

Commit e993263

Browse files
authored
Merge pull request #774 from screamerbg/f/detected_target
UX: Fallback to detect connected target when none specified
2 parents 629d2a8 + f014738 commit e993263

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

mbed/mbed.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,13 +1722,11 @@ def get_target(self, target=None):
17221722
target_cfg = self.get_cfg('TARGET')
17231723
target = target if target else target_cfg
17241724

1725-
if target and (target.lower() == 'detect' or target.lower() == 'auto'):
1725+
if not target or (target.lower() == 'detect' or target.lower() == 'auto'):
17261726
detected = self.detect_single_target()
17271727
if detected:
17281728
target = detected['name']
17291729

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

17341732
def get_toolchain(self, toolchain=None):
@@ -1770,7 +1768,7 @@ def detect_single_target(self, info=None):
17701768
elif len(targets) > 1:
17711769
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system.", 1)
17721770
elif len(targets) == 0:
1773-
error("No targets were detected.\nPlease make sure a target board is connected to this system.", 1)
1771+
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)
17741772
else:
17751773
action("Detected \"%s\" connected to \"%s\" and using com port \"%s\"" % (targets[0]['name'], targets[0]['mount'], targets[0]['serial']))
17761774
info = targets[0]
@@ -2618,6 +2616,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
26182616
program.check_requirements(True)
26192617
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
26202618
orig_path = getcwd()
2619+
orig_target = target
26212620

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

2727-
program.set_defaults(target=target, toolchain=tchain)
2726+
program.set_defaults(target=orig_target, toolchain=tchain)
27282727

27292728

27302729
# Test command
@@ -2787,6 +2786,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
27872786

27882787
# Save original working directory
27892788
orig_path = getcwd()
2789+
orig_target = target
27902790

27912791
macros = program.get_macros()
27922792
tools_dir = program.get_tools()
@@ -2940,7 +2940,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
29402940
if run_only or build_and_run_tests:
29412941
popen(icetea_command)
29422942

2943-
program.set_defaults(target=target, toolchain=tchain)
2943+
program.set_defaults(target=orig_target, toolchain=tchain)
29442944

29452945

29462946
# device management commands
@@ -3016,6 +3016,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False, ap
30163016
program.check_requirements(True)
30173017
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
30183018
orig_path = getcwd()
3019+
orig_target = target
30193020
# Change directories to the program root to use mbed OS tools
30203021
with cd(program.path):
30213022
tools_dir = program.get_tools()
@@ -3050,7 +3051,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False, ap
30503051
+ args,
30513052
env=env)
30523053

3053-
program.set_defaults(target=target)
3054+
program.set_defaults(target=orig_target)
30543055

30553056

30563057
# Detect command

0 commit comments

Comments
 (0)