From 8d33a3d151af9a22dc4c26bd4961884e858f0fb3 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 18 Mar 2023 22:41:14 -0600 Subject: [PATCH] Do not build project when only "monitor" target is passed --- HISTORY.rst | 9 +-- docs | 2 +- platformio/run/cli.py | 127 +++++++++++++++++++++--------------------- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 57126d54..317e9a4b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -17,10 +17,11 @@ PlatformIO Core 6 6.1.7 (2023-??-??) ~~~~~~~~~~~~~~~~~~ -* Show detailed library dependency tree only in the `verbose mode `__ (`issue #4517 `_) -* Prevented shell injection when converting INO file to CPP (`issue #4532 `_) -* Restored project generator for `NetBeans IDE `__ -* Improved source file filtering functionality for `Static Code Analysis `__ feature +* Improved source file filtering functionality for the `Static Code Analysis `__ feature, making it easier to analyze only the code you need to +* Added the ability to show a detailed library dependency tree only in `verbose mode `__, which can help you understand the relationship between libraries and troubleshoot issues more effectively (`issue #4517 `_) +* Added the ability to run only the `device monitor `__ when using the `pio run -t monitor `__ command, saving you time and resources by skipping the build process +* Implemented a fix for shell injection vulnerabilities when converting INO files to CPP, ensuring your code is safe and secure (`issue #4532 `_) +* Restored the project generator for the `NetBeans IDE `__, providing you with more flexibility and options for your development workflow 6.1.6 (2023-01-23) ~~~~~~~~~~~~~~~~~~ diff --git a/docs b/docs index e9b309b5..ea46b38c 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit e9b309b59307a0da69a0d28b2e19fc5f25dc1b27 +Subproject commit ea46b38c806aff3f944ffba3de776cf7e1a03947 diff --git a/platformio/run/cli.py b/platformio/run/cli.py index 6c647431..bf237ac9 100644 --- a/platformio/run/cli.py +++ b/platformio/run/cli.py @@ -104,6 +104,8 @@ def cli( is_test_running = CTX_META_TEST_IS_RUNNING in ctx.meta results = [] + only_monitor = "monitor" in target and len(target) == 1 + command_failed = False with fs.cd(project_dir): config = ProjectConfig.get_instance(project_conf) config.validate(environment) @@ -111,65 +113,75 @@ def cli( if list_targets: return print_target_list(list(environment) or config.envs()) - # clean obsolete build dir - if not disable_auto_clean: - build_dir = config.get("platformio", "build_dir") - try: - clean_build_dir(build_dir, config) - except ProjectError as exc: - raise exc - except: # pylint: disable=bare-except - click.secho( - "Can not remove temporary directory `%s`. Please remove " - "it manually to avoid build issues" % build_dir, - fg="yellow", + if not only_monitor: + # clean obsolete build dir + if not disable_auto_clean: + build_dir = config.get("platformio", "build_dir") + try: + clean_build_dir(build_dir, config) + except ProjectError as exc: + raise exc + except: # pylint: disable=bare-except + click.secho( + "Can not remove temporary directory `%s`. Please remove " + "it manually to avoid build issues" % build_dir, + fg="yellow", + ) + + handle_legacy_libdeps(project_dir, config) + + default_envs = config.default_envs() + for env in config.envs(): + skipenv = any( + [ + environment and env not in environment, + not environment and default_envs and env not in default_envs, + ] + ) + if skipenv: + results.append({"env": env}) + continue + + # print empty line between multi environment project + if not silent and any(r.get("succeeded") is not None for r in results): + click.echo() + + results.append( + process_env( + ctx, + env, + config, + target, + upload_port, + jobs, + program_args, + is_test_running, + silent, + verbose, + ) ) - handle_legacy_libdeps(project_dir, config) - - default_envs = config.default_envs() - for env in config.envs(): - skipenv = any( - [ - environment and env not in environment, - not environment and default_envs and env not in default_envs, - ] - ) - if skipenv: - results.append({"env": env}) - continue - - # print empty line between multi environment project - if not silent and any(r.get("succeeded") is not None for r in results): - click.echo() - - results.append( - process_env( - ctx, - env, - config, - environment, - target, - upload_port, - monitor_port, - jobs, - program_args, - is_test_running, - silent, - verbose, - ) - ) - - command_failed = any(r.get("succeeded") is False for r in results) - - if not is_test_running and (command_failed or not silent) and len(results) > 1: - print_processing_summary(results, verbose) + command_failed = any(r.get("succeeded") is False for r in results) + if ( + not is_test_running + and (command_failed or not silent) + and len(results) > 1 + ): + print_processing_summary(results, verbose) # Reset custom project config app.set_session_var("custom_project_conf", None) if command_failed: raise exception.ReturnErrorCode(1) + + if "monitor" in target and "nobuild" not in target: + ctx.invoke( + device_monitor_cmd, + port=monitor_port, + environment=environment[0] if environment else None, + ) + return True @@ -177,10 +189,8 @@ def process_env( ctx, name, config, - environments, targets, upload_port, - monitor_port, jobs, program_args, is_test_running, @@ -208,17 +218,6 @@ def process_env( if not is_test_running and (not silent or not result["succeeded"]): print_processing_footer(result) - if ( - result["succeeded"] - and "monitor" in ep.get_build_targets() - and "nobuild" not in ep.get_build_targets() - ): - ctx.invoke( - device_monitor_cmd, - port=monitor_port, - environment=environments[0] if environments else None, - ) - return result