Skip to content

Commit

Permalink
Resolved an issue where the PlatformIO Debugging solution was not esc…
Browse files Browse the repository at this point in the history
…aping the tool installation process into MI2 correctly // Resolve #4565
  • Loading branch information
ivankravets committed Apr 15, 2023
1 parent 0d9ee75 commit 7e9b637
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 62 deletions.
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release Notes
.. |LDF| replace:: `LDF <https://docs.platformio.org/en/latest/librarymanager/ldf.html>`__
.. |INTERPOLATION| replace:: `Interpolation of Values <https://docs.platformio.org/en/latest/projectconf/interpolation.html>`__
.. |UNITTESTING| replace:: `Unit Testing <https://docs.platformio.org/en/latest/advanced/unit-testing/index.html>`__
.. |DEBUGGING| replace:: `Debugging <https://docs.platformio.org/en/latest/plus/debugging.html>`__

.. _release_notes_6:

Expand All @@ -26,9 +27,10 @@ PlatformIO Core 6
* Implemented a fix for shell injection vulnerabilities when converting INO files to CPP, ensuring your code is safe and secure (`issue #4532 <https://github.com/platformio/platformio-core/issues/4532>`_)
* Restored the project generator for the `NetBeans IDE <https://docs.platformio.org/en/latest/integration/ide/netbeans.html>`__, providing you with more flexibility and options for your development workflow
* Resolved an issue where the `build_cache_dir <https://docs.platformio.org/en/latest/projectconf/sections/platformio/options/directory/build_cache_dir.html>`__ setting was not being recognized consistently across multiple environments (`issue #4574 <https://github.com/platformio/platformio-core/issues/4574>`_)
* Fixed an issue where organization details could not be updated using the `pio org update <https://docs.platformio.org/en/latest/core/userguide/org/cmd_update.html>`__ command
* Resolved an issue where organization details could not be updated using the `pio org update <https://docs.platformio.org/en/latest/core/userguide/org/cmd_update.html>`__ command
* Resolved an issue where the incorrect debugging environment was generated for VSCode in "Auto" mode (`issue #4597 <https://github.com/platformio/platformio-core/issues/4597>`_)
* Resolved an issue where native tests would fail if a custom program name was specified (`issue #4546 <https://github.com/platformio/platformio-core/issues/4546>`_)
* Resolved an issue where the PlatformIO |DEBUGGING| solution was not escaping the tool installation process into MI2 correctly (`issue #4565 <https://github.com/platformio/platformio-core/issues/4565>`_)

6.1.6 (2023-01-23)
~~~~~~~~~~~~~~~~~~
Expand Down
99 changes: 41 additions & 58 deletions platformio/debug/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from platformio.debug.config.factory import DebugConfigFactory
from platformio.debug.exception import DebugInvalidOptionsError
from platformio.debug.process.gdb import GDBClientProcess
from platformio.exception import ReturnErrorCode
from platformio.platform.factory import PlatformFactory
from platformio.project.config import ProjectConfig
from platformio.project.exception import ProjectEnvsNotAvailableError
from platformio.project.helpers import is_platformio_project
from platformio.project.options import ProjectOptions

Expand Down Expand Up @@ -81,61 +81,57 @@ def cli(
project_dir = os.getenv(name)

with fs.cd(project_dir):
return _debug_in_project_dir(
project_config = ProjectConfig.get_instance(project_conf)
project_config.validate(envs=[environment] if environment else None)
env_name = environment or helpers.get_default_debug_env(project_config)

if not interface:
return helpers.predebug_project(
ctx, project_dir, project_config, env_name, False, verbose
)

configure_args = (
ctx,
project_dir,
project_conf,
environment,
project_config,
env_name,
load_mode,
verbose,
interface,
__unprocessed,
)
if helpers.is_gdbmi_mode():
os.environ["PLATFORMIO_DISABLE_PROGRESSBAR"] = "true"
stream = helpers.GDBMIConsoleStream()
with proc.capture_std_streams(stream):
debug_config = _configure(*configure_args)
stream.close()
else:
debug_config = _configure(*configure_args)

_run(project_dir, debug_config, __unprocessed)

def _debug_in_project_dir(
ctx,
project_dir,
project_conf,
environment,
load_mode,
verbose,
interface,
__unprocessed,
):
project_config = ProjectConfig.get_instance(project_conf)
project_config.validate(envs=[environment] if environment else None)
env_name = environment or helpers.get_default_debug_env(project_config)

if not interface:
return helpers.predebug_project(
ctx, project_dir, project_config, env_name, False, verbose
)
return None

env_options = project_config.items(env=env_name, as_dict=True)
if "platform" not in env_options:
raise ProjectEnvsNotAvailableError()

def _configure(ctx, project_config, env_name, load_mode, verbose, __unprocessed):
platform = PlatformFactory.new(
project_config.get(f"env:{env_name}", "platform"), autoinstall=True
)
debug_config = DebugConfigFactory.new(
PlatformFactory.new(env_options["platform"], autoinstall=True),
platform,
project_config,
env_name,
)

if "--version" in __unprocessed:
return subprocess.run(
[debug_config.client_executable_path, "--version"], check=True
raise ReturnErrorCode(
subprocess.run(
[debug_config.client_executable_path, "--version"], check=True
).returncode
)

try:
fs.ensure_udev_rules()
except exception.InvalidUdevRules as exc:
click.echo(
helpers.escape_gdbmi_stream("~", str(exc) + "\n")
if helpers.is_gdbmi_mode()
else str(exc) + "\n",
nl=False,
)
click.echo(str(exc))

rebuild_prog = False
preload = debug_config.load_cmds == ["preload"]
Expand All @@ -157,32 +153,21 @@ def _debug_in_project_dir(
debug_config.load_cmds = []

if rebuild_prog:
if helpers.is_gdbmi_mode():
click.echo(
helpers.escape_gdbmi_stream(
"~", "Preparing firmware for debugging...\n"
),
nl=False,
)
stream = helpers.GDBMIConsoleStream()
with proc.capture_std_streams(stream):
helpers.predebug_project(
ctx, project_dir, project_config, env_name, preload, verbose
)
stream.close()
else:
click.echo("Preparing firmware for debugging...")
helpers.predebug_project(
ctx, project_dir, project_config, env_name, preload, verbose
)

click.echo("Preparing firmware for debugging...")
helpers.predebug_project(
ctx, os.getcwd(), project_config, env_name, preload, verbose
)
# save SHA sum of newly created prog
if load_mode == "modified":
helpers.is_prog_obsolete(debug_config.program_path)

if not os.path.isfile(debug_config.program_path):
raise DebugInvalidOptionsError("Program/firmware is missed")

return debug_config


def _run(project_dir, debug_config, __unprocessed):
loop = asyncio.ProactorEventLoop() if IS_WINDOWS else asyncio.get_event_loop()
asyncio.set_event_loop(loop)

Expand All @@ -199,5 +184,3 @@ def _debug_in_project_dir(
finally:
client.close()
loop.close()

return True
6 changes: 3 additions & 3 deletions platformio/debug/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ def server_ready_pattern(self):

def _load_build_data(self):
data = load_build_metadata(os.getcwd(), self.env_name, cache=True, debug=True)
if data:
return data
raise DebugInvalidOptionsError("Could not load a build configuration")
if not data:
raise DebugInvalidOptionsError("Could not load a build configuration")
return data

def _configure_server(self):
# user disabled server in platformio.ini
Expand Down

0 comments on commit 7e9b637

Please sign in to comment.