Implement autodetecting of default debug tool

This commit is contained in:
Ivan Kravets
2018-02-09 21:47:59 +02:00
parent cc08bb0fd0
commit 231bd8b294
7 changed files with 63 additions and 16 deletions

View File

@ -64,7 +64,11 @@ commonvars.AddVariables(
("UPLOAD_PROTOCOL",), ("UPLOAD_PROTOCOL",),
("UPLOAD_SPEED",), ("UPLOAD_SPEED",),
("UPLOAD_FLAGS",), ("UPLOAD_FLAGS",),
("UPLOAD_RESETMETHOD",) ("UPLOAD_RESETMETHOD",),
# debug options
("DEBUG_TOOL",),
) # yapf: disable ) # yapf: disable

View File

@ -832,9 +832,9 @@ def BuildProjectLibraries(env):
project.env = env project.env = env
ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project) ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project)
print "Library Dependency Finder -> http://bit.ly/configure-pio-ldf" print "Library Dependency Finder (LDF) -> http://bit.ly/configure-pio-ldf"
print "Modes: Finder/%s Compatibility/%s" % (ldf_mode, print "LDF MODES: FINDER/%s COMPATIBILITY/%s" % (ldf_mode,
project.lib_compat_mode) project.lib_compat_mode)
lib_builders = env.GetLibBuilders() lib_builders = env.GetLibBuilders()
print "Collected %d compatible libraries" % len(lib_builders) print "Collected %d compatible libraries" % len(lib_builders)

View File

@ -99,8 +99,8 @@ def LoadPioPlatform(env, variables):
def PrintConfiguration(env): # pylint: disable=too-many-branches def PrintConfiguration(env): # pylint: disable=too-many-branches
platform_data = ["Platform: %s >" % env.PioPlatform().title] platform_data = ["PLATFORM: %s >" % env.PioPlatform().title]
system_data = ["System:"] system_data = ["SYSTEM:"]
mcu = env.subst("$BOARD_MCU") mcu = env.subst("$BOARD_MCU")
f_cpu = env.subst("$BOARD_F_CPU") f_cpu = env.subst("$BOARD_F_CPU")
if mcu: if mcu:
@ -131,7 +131,10 @@ def PrintConfiguration(env): # pylint: disable=too-many-branches
if not debug_tools: if not debug_tools:
return return
data = [] data = [
"CURRENT/%s" % board_config.get_debug_tool_name(
env.subst("$DEBUG_TOOL"))
]
onboard = [] onboard = []
external = [] external = []
for key, value in debug_tools.items(): for key, value in debug_tools.items():
@ -144,7 +147,7 @@ def PrintConfiguration(env): # pylint: disable=too-many-branches
if external: if external:
data.append("EXTERNAL/%s" % ", ".join(sorted(external))) data.append("EXTERNAL/%s" % ", ".join(sorted(external)))
print "Debug: %s" % " ".join(data) print "DEBUG: %s" % " ".join(data)
def exists(_): def exists(_):

View File

@ -220,9 +220,9 @@ def PrintUploadInfo(env):
available.extend(env.BoardConfig().get("upload", {}).get( available.extend(env.BoardConfig().get("upload", {}).get(
"protocols", [])) "protocols", []))
if available: if available:
print "Available: %s" % ", ".join(sorted(available)) print "AVAILABLE: %s" % ", ".join(sorted(available))
if configured: if configured:
print "Configured: upload_protocol = %s" % configured print "CURRENT: upload_protocol = %s" % configured
def exists(_): def exists(_):

View File

@ -141,12 +141,11 @@ class EnvironmentProcessor(object):
"monitor_dtr") "monitor_dtr")
IGNORE_BUILD_OPTIONS = ("test_transport", "test_filter", "test_ignore", IGNORE_BUILD_OPTIONS = ("test_transport", "test_filter", "test_ignore",
"test_port", "test_speed", "debug_tool", "test_port", "test_speed", "debug_port",
"debug_port", "debug_init_cmds", "debug_init_cmds", "debug_extra_cmds",
"debug_extra_cmds", "debug_server", "debug_server", "debug_init_break",
"debug_init_break", "debug_load_cmd", "debug_load_cmd", "monitor_port", "monitor_baud",
"monitor_port", "monitor_baud", "monitor_rts", "monitor_rts", "monitor_dtr")
"monitor_dtr")
REMAPED_OPTIONS = {"framework": "pioframework", "platform": "pioplatform"} REMAPED_OPTIONS = {"framework": "pioframework", "platform": "pioplatform"}

View File

@ -238,3 +238,15 @@ class CygwinEnvDetected(PlatformioException):
MESSAGE = ("PlatformIO does not work within Cygwin environment. " MESSAGE = ("PlatformIO does not work within Cygwin environment. "
"Use native Terminal instead.") "Use native Terminal instead.")
class DebugSupportError(PlatformioException):
MESSAGE = ("Currently, PlatformIO does not support debugging for `{0}`.\n"
"Please mail contact@pioplus.com or visit "
"< http://docs.platformio.org/page/plus/debugging.html >")
class DebugInvalidOptions(PlatformioException):
pass

View File

@ -715,3 +715,32 @@ class PlatformBoardConfig(object):
if key in ("default", "onboard"): if key in ("default", "onboard"):
tools[name][key] = value tools[name][key] = value
return {"tools": tools} return {"tools": tools}
def get_debug_tool_name(self, custom=None):
debug_tools = self._manifest.get("debug", {}).get("tools")
tool_name = custom
if tool_name == "custom":
return tool_name
if not debug_tools:
raise exception.DebugSupportError(self._manifest['name'])
if tool_name:
if tool_name in debug_tools:
return tool_name
raise exception.DebugInvalidOptions(
"Unknown debug tool `%s`. Please use one of `%s` or `custom`" %
(tool_name, ", ".join(sorted(debug_tools.keys()))))
# automatically select best tool
default = []
onboard = []
external = []
for key, value in debug_tools.items():
if value.get("default"):
default.append(key)
elif value.get("onboard"):
onboard.append(key)
external.append(key)
assert default or onboard or external
return (default[0] if default else onboard[0]
if onboard else external[0])