From ceb3a19b8166700d24a717e45c557a5bd1aa0250 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 2 Nov 2021 20:05:40 +0200 Subject: [PATCH] Automatically synchronize active projects between IDE and `PlatformIO Home` --- HISTORY.rst | 117 ++++++++++--------- platformio/__init__.py | 2 +- platformio/commands/home/rpc/handlers/ide.py | 42 ++++--- platformio/commands/home/rpc/server.py | 2 +- platformio/commands/home/run.py | 14 +-- 5 files changed, 91 insertions(+), 86 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 07021307..9a5a7b96 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,33 +11,34 @@ PlatformIO Core 5 5.2.3 (2021-??-??) ~~~~~~~~~~~~~~~~~~ -- Added support for custom `device monitor filters `__ (`issue #3924 `_) -- Show human-readable message when infinite recursion is detected while processing `Interpolation of Values `__ (`issue #3883 `_) -- Improved directory interpolation (``${platformio.***_dir}``) in `"platformio.ini" `__ configuration file (`issue #3934 `_) +- Automatically synchronize active projects between IDE and `PlatformIO Home `__ +- Added support for custom `device monitor filters `__ (`issue #3924 `_) +- Show human-readable message when infinite recursion is detected while processing `Interpolation of Values `__ (`issue #3883 `_) +- Improved directory interpolation (``${platformio.***_dir}``) in `"platformio.ini" `__ configuration file (`issue #3934 `_) - Ignore resolving of SCons variables (e.g., ``${(SOURCE.get_abspath())}``) when preprocessing interpolations (`issue #3933 `_) -- Fixed an issue when the ``$PROJECT_DIR`` variable was not properly replaced in the `debug_server `__ option (`issue #4086 `_) -- Fixed an issue when `PIO Remote `__ device monitor crashes on the first keypress (`issue #3832 `_) -- Fixed "Do not know how to make File target 'debug'" issue when debugging project using `CLion IDE `__ (`pull #4089 `_) +- Fixed an issue when the ``$PROJECT_DIR`` variable was not properly replaced in the `debug_server `__ option (`issue #4086 `_) +- Fixed an issue when `PIO Remote `__ device monitor crashes on the first keypress (`issue #3832 `_) +- Fixed "Do not know how to make File target 'debug'" issue when debugging project using `CLion IDE `__ (`pull #4089 `_) - Fixed "UnicodeEncodeError" when a build output contains non-ASCII characters (`issue #3971 `_) 5.2.2 (2021-10-20) ~~~~~~~~~~~~~~~~~~ -- Override debugging firmware loading mode using ``--load-mode`` option for `pio debug `__ command +- Override debugging firmware loading mode using ``--load-mode`` option for `pio debug `__ command - Added support for CLion IDE 2021.3 (`pull #4085 `_) - Removed debugging "legacy Click" message from CLI (`issue #4083 `_) -- Fixed a "TypeError: sequence item 1: expected str instance, list found" issue when extending configuration option in `"platformio.ini" `__ with the multi-line default value (`issue #4082 `_) +- Fixed a "TypeError: sequence item 1: expected str instance, list found" issue when extending configuration option in `"platformio.ini" `__ with the multi-line default value (`issue #4082 `_) 5.2.1 (2021-10-11) ~~~~~~~~~~~~~~~~~~ - Clean a build environment and installed library dependencies using a new ``cleanall`` target (`issue #4062 `_) -- Override a default library builder via a new ``builder`` field in a ``build`` group of `library.json `__ manifest (`issue #3957 `_) -- Updated `Cppcheck `__ v2.6 with new checks, increased reliability of advanced addons (MISRA/CERT) and various improvements +- Override a default library builder via a new ``builder`` field in a ``build`` group of `library.json `__ manifest (`issue #3957 `_) +- Updated `Cppcheck `__ v2.6 with new checks, increased reliability of advanced addons (MISRA/CERT) and various improvements - Handle the "test" folder as a part of CLion project (`issue #4005 `_) - Improved handling of a library root based on "Conan" or "CMake" build systems (`issue #3887 `_) - Fixed a "KeyError: Invalid board option 'build.cpu'" when using a precompiled library with a board that does not have a CPU field in the manifest (`issue #4056 `_) -- Fixed a "FileExist" error when the `platformio ci `__ command is used in pair with the ``--keep-build-dir`` option (`issue #4011 `_) +- Fixed a "FileExist" error when the `platformio ci `__ command is used in pair with the ``--keep-build-dir`` option (`issue #4011 `_) - Fixed an issue with draft values of C++ language standards that broke static analysis via Cppcheck (`issue #3944 `_) 5.2.0 (2021-09-13) @@ -45,11 +46,11 @@ PlatformIO Core 5 * **PlatformIO Debugging** - - Boosted `PlatformIO Debugging `__ performance thanks to migrating the codebase to the pure Python 3 Asynchronous I/O stack - - `Debug unit tests `__ created with `PlatformIO Unit Testing `__ solution (`issue #948 `_) + - Boosted `PlatformIO Debugging `__ performance thanks to migrating the codebase to the pure Python 3 Asynchronous I/O stack + - `Debug unit tests `__ created with `PlatformIO Unit Testing `__ solution (`issue #948 `_) - Debug native (desktop) applications on a host machine (`issue #980 `_) - - Support debugging on Windows using Windows CMD/CLI (`pio debug `__) (`issue #3793 `_) - - Configure a custom pattern to determine when debugging server is started with a new `debug_server_ready_pattern `__ option + - Support debugging on Windows using Windows CMD/CLI (`pio debug `__) (`issue #3793 `_) + - Configure a custom pattern to determine when debugging server is started with a new `debug_server_ready_pattern `__ option - Fixed an issue with silent hanging when a custom debug server is not found (`issue #3756 `_) * **Package Management** @@ -61,7 +62,7 @@ PlatformIO Core 5 * Check for duplicates and used version * Validate package manifest - - Added a new option ``--non-interactive`` to `pio package publish `__ command + - Added a new option ``--non-interactive`` to `pio package publish `__ command * **Build System** @@ -74,9 +75,9 @@ PlatformIO Core 5 - Updated analysis tools: - * `Clang-Tidy `__ v12.0.1 with new modules and extended checks list - * `Cppcheck `__ v2.5.0 with improved code analysis and MISRA improvements - * `PVS-Studio `__ v7.14 with support for intermodular analysis, improved MISRA support and new diagnostics + * `Clang-Tidy `__ v12.0.1 with new modules and extended checks list + * `Cppcheck `__ v2.5.0 with improved code analysis and MISRA improvements + * `PVS-Studio `__ v7.14 with support for intermodular analysis, improved MISRA support and new diagnostics * **Miscellaneous** @@ -88,7 +89,7 @@ PlatformIO Core 5 ~~~~~~~~~~~~~~~~~~ * Fixed a "The command line is too long" issue with a linking process on Windows (`issue #3827 `_) -* Fixed an issue with `device monitor `__ when the "send_on_enter" filter didn't send EOL chars (`issue #3787 `_) +* Fixed an issue with `device monitor `__ when the "send_on_enter" filter didn't send EOL chars (`issue #3787 `_) * Fixed an issue with silent mode when unwanted data is printed to stdout (`issue #3837 `_) * Fixed an issue when code inspection fails with "Bad JSON" (`issue #3790 `_) * Fixed an issue with overriding user-specified debugging configuration information in VSCode (`issue #3824 `_) @@ -98,8 +99,8 @@ PlatformIO Core 5 * **PlatformIO Home** - - Boosted `PlatformIO Home `__ performance thanks to migrating the codebase to the pure Python 3 Asynchronous I/O stack - - Added a new ``--session-id`` option to `pio home `__ command that helps to keep PlatformIO Home isolated from other instances and protect from 3rd party access (`issue #3397 `_) + - Boosted `PlatformIO Home `__ performance thanks to migrating the codebase to the pure Python 3 Asynchronous I/O stack + - Added a new ``--session-id`` option to `pio home `__ command that helps to keep PlatformIO Home isolated from other instances and protect from 3rd party access (`issue #3397 `_) * **Build System** @@ -109,28 +110,28 @@ PlatformIO Core 5 * **Package Management** - - New options for `pio system prune `__ command: + - New options for `pio system prune `__ command: + ``--dry-run`` option to show data that will be removed + ``--core-packages`` option to remove unnecessary core packages + ``--platform-packages`` option to remove unnecessary development platform packages (`issue #923 `_) - - Added new `check_prune_system_threshold `__ setting + - Added new `check_prune_system_threshold `__ setting - Disabled automatic removal of unnecessary development platform packages (`issue #3708 `_, `issue #3770 `_) - Fixed an issue when unnecessary packages were removed in ``update --dry-run`` mode (`issue #3809 `_) - Fixed a "ValueError: Invalid simple block" when uninstalling a package with a custom name and external source (`issue #3816 `_) * **Debugging** - - Configure a custom debug adapter speed using a new `debug_speed `__ option (`issue #3799 `_) + - Configure a custom debug adapter speed using a new `debug_speed `__ option (`issue #3799 `_) - Handle debugging server's "ready_pattern" in "stderr" output * **Miscellaneous** - - Improved listing of `multicast DNS services `_ + - Improved listing of `multicast DNS services `_ - Fixed a "UnicodeDecodeError: 'utf-8' codec can't decode byte" when using J-Link for firmware uploading on Linux (`issue #3804 `_) - Fixed an issue with a compiler driver for ".ccls" language server (`issue #3808 `_) - - Fixed an issue when `pio device monitor --eol `__ and "send_on_enter" filter do not work properly (`issue #3787 `_) + - Fixed an issue when `pio device monitor --eol `__ and "send_on_enter" filter do not work properly (`issue #3787 `_) 5.0.4 (2020-12-30) ~~~~~~~~~~~~~~~~~~ @@ -139,8 +140,8 @@ PlatformIO Core 5 - Improved ".ccls" configuration file for Emacs, Vim, and Sublime Text integrations - Updated analysis tools: - * `Cppcheck `__ v2.3 with improved C++ parser and several new MISRA rules - * `PVS-Studio `__ v7.11 with new diagnostics and updated mass suppression mechanism + * `Cppcheck `__ v2.3 with improved C++ parser and several new MISRA rules + * `PVS-Studio `__ v7.11 with new diagnostics and updated mass suppression mechanism - Show a warning message about deprecated support for Python 2 and Python 3.5 - Do not provide "intelliSenseMode" option when generating configuration for VSCode C/C++ extension @@ -150,12 +151,12 @@ PlatformIO Core 5 5.0.3 (2020-11-12) ~~~~~~~~~~~~~~~~~~ -- Added an error selector for `Sublime Text `__ build runner (`issue #3733 `_) +- Added an error selector for `Sublime Text `__ build runner (`issue #3733 `_) - Generate a working "projectEnvName" for PlatformIO IDE's debugger for VSCode - Force VSCode's intelliSenseMode to "gcc-x64" when GCC toolchain is used - Print ignored test suites and environments in the test summary report only in verbose mode (`issue #3726 `_) - Fixed an issue when the package manager tries to install a built-in library from the registry (`issue #3662 `_) -- Fixed an issue when `pio package pack `__ ignores some folders (`issue #3730 `_) +- Fixed an issue when `pio package pack `__ ignores some folders (`issue #3730 `_) 5.0.2 (2020-10-30) ~~~~~~~~~~~~~~~~~~ @@ -163,21 +164,21 @@ PlatformIO Core 5 - Initialize a new project or update the existing passing working environment name and its options (`issue #3686 `_) - Automatically build PlatformIO Core extra Python dependencies on a host machine if they are missed in the registry (`issue #3700 `_) - Improved "core.call" RPC for PlatformIO Home (`issue #3671 `_) -- Fixed a "PermissionError: [WinError 5]" on Windows when an external repository is used with `lib_deps `__ option (`issue #3664 `_) +- Fixed a "PermissionError: [WinError 5]" on Windows when an external repository is used with `lib_deps `__ option (`issue #3664 `_) - Fixed a "KeyError: 'versions'" when dependency does not exist in the registry (`issue #3666 `_) - Fixed an issue with GCC linker when "native" dev-platform is used in pair with library dependencies (`issue #3669 `_) - Fixed an "AssertionError: ensure_dir_exists" when checking library updates from simultaneous subprocesses (`issue #3677 `_) -- Fixed an issue when `pio package publish `__ command removes original archive after submitting to the registry (`issue #3716 `_) -- Fixed an issue when multiple `pio lib install `__ command with the same local library results in duplicates in ``lib_deps`` (`issue #3715 `_) -- Fixed an issue with a "wrong" timestamp in device monitor output using `"time" filter `__ (`issue #3712 `_) +- Fixed an issue when `pio package publish `__ command removes original archive after submitting to the registry (`issue #3716 `_) +- Fixed an issue when multiple `pio lib install `__ command with the same local library results in duplicates in ``lib_deps`` (`issue #3715 `_) +- Fixed an issue with a "wrong" timestamp in device monitor output using `"time" filter `__ (`issue #3712 `_) 5.0.1 (2020-09-10) ~~~~~~~~~~~~~~~~~~ -- Added support for "owner" requirement when declaring ``dependencies`` using `library.json `__ -- Fixed an issue when using a custom git/ssh package with `platform_packages `__ option (`issue #3624 `_) -- Fixed an issue with "ImportError: cannot import name '_get_backend' from 'cryptography.hazmat.backends'" when using `Remote Development `__ on RaspberryPi device (`issue #3652 `_) -- Fixed an issue when `pio package unpublish `__ command crashes (`issue #3660 `_) +- Added support for "owner" requirement when declaring ``dependencies`` using `library.json `__ +- Fixed an issue when using a custom git/ssh package with `platform_packages `__ option (`issue #3624 `_) +- Fixed an issue with "ImportError: cannot import name '_get_backend' from 'cryptography.hazmat.backends'" when using `Remote Development `__ on RaspberryPi device (`issue #3652 `_) +- Fixed an issue when `pio package unpublish `__ command crashes (`issue #3660 `_) - Fixed an issue when the package manager tries to install a built-in library from the registry (`issue #3662 `_) - Fixed an issue with incorrect value for C++ language standard in IDE projects when an in-progress language standard is used (`issue #3653 `_) - Fixed an issue with "Invalid simple block (semantic_version)" from library dependency that refs to an external source (repository, ZIP/Tar archives) (`issue #3658 `_) @@ -186,7 +187,7 @@ PlatformIO Core 5 5.0.0 (2020-09-03) ~~~~~~~~~~~~~~~~~~ -Please check `Migration guide from 4.x to 5.0 `__. +Please check `Migration guide from 4.x to 5.0 `__. * Integration with the new **PlatformIO Trusted Registry** @@ -201,19 +202,19 @@ Please check `Migration guide from 4.x to 5.0 `__ – manage packages in the registry - * `pio access `__ – manage package access for users, teams, and maintainers + * `pio package `__ – manage packages in the registry + * `pio access `__ – manage package access for users, teams, and maintainers * Integration with the new **Account Management System** - - `Manage organizations `__ - - `Manage teams and team memberships `__ + - `Manage organizations `__ + - `Manage teams and team memberships `__ * New **Package Management System** - Integrated PlatformIO Core with the new PlatformIO Registry - Support for owner-based dependency declaration (resolves name conflicts) (`issue #1824 `_) - - Automatically save dependencies to `"platformio.ini" `__ when installing using PlatformIO CLI (`issue #2964 `_) + - Automatically save dependencies to `"platformio.ini" `__ when installing using PlatformIO CLI (`issue #2964 `_) - Follow SemVer complaint version constraints when checking library updates `issue #1281 `_) - Dropped support for "packageRepositories" section in "platform.json" manifest (please publish packages directly to the registry) @@ -221,29 +222,29 @@ Please check `Migration guide from 4.x to 5.0 `__ - * `Configuration files are Python scripts `__ – use the power of a real programming language to solve build problems + * `Configuration files are Python scripts `__ – use the power of a real programming language to solve build problems * Built-in reliable and automatic dependency analysis * Improved support for parallel builds - * Ability to `share built files in a cache `__ to speed up multiple builds + * Ability to `share built files in a cache `__ to speed up multiple builds - - New `Custom Targets `__ + - New `Custom Targets `__ * Pre/Post processing based on dependent sources (another target, source file, etc.) * Command launcher with own arguments - * Launch command with custom options declared in `"platformio.ini" `__ + * Launch command with custom options declared in `"platformio.ini" `__ * Python callback as a target (use the power of Python interpreter and PlatformIO Build API) - * List available project targets (including dev-platform specific and custom targets) with a new `pio run --list-targets `__ command (`issue #3544 `_) + * List available project targets (including dev-platform specific and custom targets) with a new `pio run --list-targets `__ command (`issue #3544 `_) - Enable "cyclic reference" for GCC linker only for the embedded dev-platforms (`issue #3570 `_) - - Automatically enable LDF dependency `chain+ mode (evaluates C/C++ Preprocessor conditional syntax) `__ for Arduino library when "library.property" has "depends" field (`issue #3607 `_) + - Automatically enable LDF dependency `chain+ mode (evaluates C/C++ Preprocessor conditional syntax) `__ for Arduino library when "library.property" has "depends" field (`issue #3607 `_) - Fixed an issue with improper processing of source files added via multiple Build Middlewares (`issue #3531 `_) - Fixed an issue with the ``clean`` target on Windows when project and build directories are located on different logical drives (`issue #3542 `_) * **Project Management** - - Added support for "globstar/`**`" (recursive) pattern for the different commands and configuration options (`pio ci `__, `src_filter `__, `check_patterns `__, `library.json > srcFilter `__). Python 3.5+ is required - - Added a new ``-e, --environment`` option to `pio project init `__ command that helps to update a PlatformIO project using the existing environment - - Dump build system data intended for IDE extensions/plugins using a new `pio project data `__ command + - Added support for "globstar/`**`" (recursive) pattern for the different commands and configuration options (`pio ci `__, `src_filter `__, `check_patterns `__, `library.json > srcFilter `__). Python 3.5+ is required + - Added a new ``-e, --environment`` option to `pio project init `__ command that helps to update a PlatformIO project using the existing environment + - Dump build system data intended for IDE extensions/plugins using a new `pio project data `__ command - Do not generate ".travis.yml" for a new project, let the user have a choice * **Unit Testing** @@ -256,16 +257,16 @@ Please check `Migration guide from 4.x to 5.0 `__ v2.1 with a new "soundy" analysis option and improved code parser - * `PVS-Studio `__ v7.09 with a new file list analysis mode and an extended list of analysis diagnostics + * `Cppcheck `__ v2.1 with a new "soundy" analysis option and improved code parser + * `PVS-Studio `__ v7.09 with a new file list analysis mode and an extended list of analysis diagnostics - Added Cppcheck package for ARM-based single-board computers (`issue #3559 `_) - Fixed an issue with PIO Check when a defect with a multiline error message is not reported in verbose mode (`issue #3631 `_) * **Miscellaneous** - - Display system-wide information using a new `pio system info `__ command (`issue #3521 `_) - - Remove unused data using a new `pio system prune `__ command (`issue #3522 `_) + - Display system-wide information using a new `pio system info `__ command (`issue #3521 `_) + - Remove unused data using a new `pio system prune `__ command (`issue #3522 `_) - Show ignored project environments only in the verbose mode (`issue #3641 `_) - Do not escape compiler arguments in VSCode template on Windows - Drop support for Python 2 and 3.5. diff --git a/platformio/__init__.py b/platformio/__init__.py index 62230494..aa7301fb 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -47,7 +47,7 @@ __pioremote_endpoint__ = "ssl:host=remote.platformio.org:port=4413" __default_requests_timeout__ = (10, None) # (connect, read) __core_packages__ = { - "contrib-piohome": "~3.3.4", + "contrib-piohome": "~3.4.0", "contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor), "tool-unity": "~1.20500.0", "tool-scons": "~4.40200.0", diff --git a/platformio/commands/home/rpc/handlers/ide.py b/platformio/commands/home/rpc/handlers/ide.py index 59a52df5..44286dd8 100644 --- a/platformio/commands/home/rpc/handlers/ide.py +++ b/platformio/commands/home/rpc/handlers/ide.py @@ -21,28 +21,32 @@ from platformio.compat import aio_get_running_loop class IDERPC: def __init__(self): - self._queue = {} + self._cmd_queue = [] + self._result_queue = {} - def send_command(self, sid, command, params): - if not self._queue.get(sid): + async def listen_commands(self): + self._cmd_queue.append(aio_get_running_loop().create_future()) + return await self._cmd_queue[-1] + + async def send_command(self, command, params=None): + if not self._cmd_queue: raise JSONRPC20DispatchException( code=4005, message="PIO Home IDE agent is not started" ) - while self._queue[sid]: - self._queue[sid].pop().set_result( - {"id": time.time(), "method": command, "params": params} + cmd_id = None + while self._cmd_queue: + cmd_id = f"ide-{command}-{time.time()}" + self._cmd_queue.pop().set_result( + { + "id": cmd_id, + "method": command, + "params": params, + } ) + if not cmd_id: + return + self._result_queue[cmd_id] = aio_get_running_loop().create_future() + return await self._result_queue[cmd_id] - async def listen_commands(self, sid=0): - if sid not in self._queue: - self._queue[sid] = [] - self._queue[sid].append(aio_get_running_loop().create_future()) - return await self._queue[sid][-1] - - def open_project(self, sid, project_dir): - return self.send_command(sid, "open_project", project_dir) - - def open_text_document(self, sid, path, line=None, column=None): - return self.send_command( - sid, "open_text_document", dict(path=path, line=line, column=column) - ) + def on_command_result(self, cmd_id, value): + self._result_queue[cmd_id].set_result(value) diff --git a/platformio/commands/home/rpc/server.py b/platformio/commands/home/rpc/server.py index 8e0dd44f..c10fa176 100644 --- a/platformio/commands/home/rpc/server.py +++ b/platformio/commands/home/rpc/server.py @@ -35,7 +35,7 @@ class JSONRPCServerFactoryBase: def __call__(self, *args, **kwargs): raise NotImplementedError - def addObjectHandler(self, handler, namespace): + def add_object_handler(self, handler, namespace): self.manager.dispatcher.add_object(handler, prefix="%s." % namespace) def on_client_connect(self): diff --git a/platformio/commands/home/run.py b/platformio/commands/home/run.py index b923cd99..64d820ea 100644 --- a/platformio/commands/home/run.py +++ b/platformio/commands/home/run.py @@ -65,13 +65,13 @@ def run_server(host, port, no_open, shutdown_timeout, home_url): raise PlatformioException("Invalid path to PIO Home Contrib") ws_rpc_factory = WebSocketJSONRPCServerFactory(shutdown_timeout) - ws_rpc_factory.addObjectHandler(AccountRPC(), namespace="account") - ws_rpc_factory.addObjectHandler(AppRPC(), namespace="app") - ws_rpc_factory.addObjectHandler(IDERPC(), namespace="ide") - ws_rpc_factory.addObjectHandler(MiscRPC(), namespace="misc") - ws_rpc_factory.addObjectHandler(OSRPC(), namespace="os") - ws_rpc_factory.addObjectHandler(PIOCoreRPC(), namespace="core") - ws_rpc_factory.addObjectHandler(ProjectRPC(), namespace="project") + ws_rpc_factory.add_object_handler(AccountRPC(), namespace="account") + ws_rpc_factory.add_object_handler(AppRPC(), namespace="app") + ws_rpc_factory.add_object_handler(IDERPC(), namespace="ide") + ws_rpc_factory.add_object_handler(MiscRPC(), namespace="misc") + ws_rpc_factory.add_object_handler(OSRPC(), namespace="os") + ws_rpc_factory.add_object_handler(PIOCoreRPC(), namespace="core") + ws_rpc_factory.add_object_handler(ProjectRPC(), namespace="project") path = urlparse(home_url).path routes = [