From 973f77012f4ca9cdc07dab2a250cd898a26efb77 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 5 Nov 2021 14:46:57 +0200 Subject: [PATCH] Fixed an issue when VSCode's debugger does not honor default environment // Resolve #4098 --- HISTORY.rst | 2 ++ .../commands/home/rpc/handlers/project.py | 2 +- platformio/commands/project.py | 27 ++---------------- platformio/ide/__init__.py | 13 --------- .../generator.py} | 28 ++++++++++++++++--- .../tpls/atom/.clang_complete.tpl | 0 .../tpls/atom/.gcc-flags.json.tpl | 0 .../{ide => project}/tpls/atom/.gitignore.tpl | 0 .../tpls/clion/.gitignore.tpl | 0 .../tpls/clion/CMakeLists.txt.tpl | 0 .../tpls/clion/CMakeListsPrivate.txt.tpl | 0 .../tpls/codeblocks/platformio.cbp.tpl | 0 .../tpls/eclipse/.cproject.tpl | 0 .../tpls/eclipse/.project.tpl | 0 .../.settings/PlatformIO Debugger.launch.tpl | 0 .../.settings/language.settings.xml.tpl | 0 .../.settings/org.eclipse.cdt.core.prefs.tpl | 0 .../{ide => project}/tpls/emacs/.ccls.tpl | 0 .../tpls/emacs/.gitignore.tpl | 0 .../netbeans/nbproject/configurations.xml.tpl | 0 .../nbproject/private/configurations.xml.tpl | 0 .../nbproject/private/launcher.properties.tpl | 0 .../nbproject/private/private.xml.tpl | 0 .../tpls/netbeans/nbproject/project.xml.tpl | 0 .../tpls/qtcreator/platformio.pro.tpl | 0 .../tpls/sublimetext/.ccls.tpl | 0 .../platformio.sublime-project.tpl | 0 .../{ide => project}/tpls/vim/.ccls.tpl | 0 .../{ide => project}/tpls/vim/.gitignore.tpl | 0 .../platformio.vcxproj.filters.tpl | 0 .../tpls/visualstudio/platformio.vcxproj.tpl | 0 .../tpls/vscode/.gitignore.tpl | 0 .../vscode/.vscode/c_cpp_properties.json.tpl | 0 .../tpls/vscode/.vscode/extensions.json.tpl | 0 .../tpls/vscode/.vscode/launch.json.tpl | 2 +- setup.py | 8 +++--- 36 files changed, 34 insertions(+), 48 deletions(-) delete mode 100644 platformio/ide/__init__.py rename platformio/{ide/projectgenerator.py => project/generator.py} (84%) rename platformio/{ide => project}/tpls/atom/.clang_complete.tpl (100%) rename platformio/{ide => project}/tpls/atom/.gcc-flags.json.tpl (100%) rename platformio/{ide => project}/tpls/atom/.gitignore.tpl (100%) rename platformio/{ide => project}/tpls/clion/.gitignore.tpl (100%) rename platformio/{ide => project}/tpls/clion/CMakeLists.txt.tpl (100%) rename platformio/{ide => project}/tpls/clion/CMakeListsPrivate.txt.tpl (100%) rename platformio/{ide => project}/tpls/codeblocks/platformio.cbp.tpl (100%) rename platformio/{ide => project}/tpls/eclipse/.cproject.tpl (100%) rename platformio/{ide => project}/tpls/eclipse/.project.tpl (100%) rename platformio/{ide => project}/tpls/eclipse/.settings/PlatformIO Debugger.launch.tpl (100%) rename platformio/{ide => project}/tpls/eclipse/.settings/language.settings.xml.tpl (100%) rename platformio/{ide => project}/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl (100%) rename platformio/{ide => project}/tpls/emacs/.ccls.tpl (100%) rename platformio/{ide => project}/tpls/emacs/.gitignore.tpl (100%) rename platformio/{ide => project}/tpls/netbeans/nbproject/configurations.xml.tpl (100%) rename platformio/{ide => project}/tpls/netbeans/nbproject/private/configurations.xml.tpl (100%) rename platformio/{ide => project}/tpls/netbeans/nbproject/private/launcher.properties.tpl (100%) rename platformio/{ide => project}/tpls/netbeans/nbproject/private/private.xml.tpl (100%) rename platformio/{ide => project}/tpls/netbeans/nbproject/project.xml.tpl (100%) rename platformio/{ide => project}/tpls/qtcreator/platformio.pro.tpl (100%) rename platformio/{ide => project}/tpls/sublimetext/.ccls.tpl (100%) rename platformio/{ide => project}/tpls/sublimetext/platformio.sublime-project.tpl (100%) rename platformio/{ide => project}/tpls/vim/.ccls.tpl (100%) rename platformio/{ide => project}/tpls/vim/.gitignore.tpl (100%) rename platformio/{ide => project}/tpls/visualstudio/platformio.vcxproj.filters.tpl (100%) rename platformio/{ide => project}/tpls/visualstudio/platformio.vcxproj.tpl (100%) rename platformio/{ide => project}/tpls/vscode/.gitignore.tpl (100%) rename platformio/{ide => project}/tpls/vscode/.vscode/c_cpp_properties.json.tpl (100%) rename platformio/{ide => project}/tpls/vscode/.vscode/extensions.json.tpl (100%) rename platformio/{ide => project}/tpls/vscode/.vscode/launch.json.tpl (98%) diff --git a/HISTORY.rst b/HISTORY.rst index 9a5a7b96..0115ce67 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -16,10 +16,12 @@ PlatformIO Core 5 - 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 `_) +- Added "inc" as sign that it's the root of the library (`issue #4093 `_) - 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 `_) +- Fixed an issue when VSCode's debugger does not honor default environment (`issue #4098 `_) 5.2.2 (2021-10-20) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/commands/home/rpc/handlers/project.py b/platformio/commands/home/rpc/handlers/project.py index 535bc9be..1c033f51 100644 --- a/platformio/commands/home/rpc/handlers/project.py +++ b/platformio/commands/home/rpc/handlers/project.py @@ -23,10 +23,10 @@ from ajsonrpc.core import JSONRPC20DispatchException from platformio import exception, fs from platformio.commands.home.rpc.handlers.app import AppRPC from platformio.commands.home.rpc.handlers.piocore import PIOCoreRPC -from platformio.ide.projectgenerator import ProjectGenerator from platformio.package.manager.platform import PlatformPackageManager from platformio.project.config import ProjectConfig from platformio.project.exception import ProjectError +from platformio.project.generator import ProjectGenerator from platformio.project.helpers import get_project_dir, is_platformio_project from platformio.project.options import get_config_options_schema diff --git a/platformio/commands/project.py b/platformio/commands/project.py index c79979fd..22b06ee2 100644 --- a/platformio/commands/project.py +++ b/platformio/commands/project.py @@ -22,11 +22,11 @@ from tabulate import tabulate from platformio import fs from platformio.commands.platform import platform_install as cli_platform_install -from platformio.ide.projectgenerator import ProjectGenerator from platformio.package.manager.platform import PlatformPackageManager from platformio.platform.exception import UnknownBoard from platformio.project.config import ProjectConfig from platformio.project.exception import NotPlatformIOProjectError +from platformio.project.generator import ProjectGenerator from platformio.project.helpers import is_platformio_project, load_project_ide_data @@ -191,10 +191,7 @@ def project_init( os.path.join(project_dir, "platformio.ini") ) config.validate() - pg = ProjectGenerator( - config, environment or get_best_envname(config, board), ide - ) - pg.generate() + ProjectGenerator(config, environment, ide, board).generate() if is_new_project: init_cvs_ignore(project_dir) @@ -441,23 +438,3 @@ def update_project_env(project_dir, environment, project_option): config.set(section, _name.strip(), _value.strip()) config.save() - - -def get_best_envname(config, board_ids=None): - envname = None - default_envs = config.default_envs() - if default_envs: - envname = default_envs[0] - if not board_ids: - return envname - - for env in config.envs(): - if not board_ids: - return env - if not envname: - envname = env - items = config.items(env=env, as_dict=True) - if "board" in items and items.get("board") in board_ids: - return env - - return envname diff --git a/platformio/ide/__init__.py b/platformio/ide/__init__.py deleted file mode 100644 index b0514903..00000000 --- a/platformio/ide/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2014-present PlatformIO -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/platformio/ide/projectgenerator.py b/platformio/project/generator.py similarity index 84% rename from platformio/ide/projectgenerator.py rename to platformio/project/generator.py index f6112196..adf54e10 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/project/generator.py @@ -24,15 +24,34 @@ from platformio.project.helpers import load_project_ide_data class ProjectGenerator(object): - def __init__(self, config, env_name, ide): + def __init__(self, config, env_name, ide, board_ids=None): self.config = config self.project_dir = os.path.dirname(config.path) - self.env_name = str(env_name) + self.original_env_name = env_name + self.env_name = str(env_name or self.get_best_envname(board_ids)) self.ide = str(ide) + def get_best_envname(self, board_ids=None): + envname = None + default_envs = self.config.default_envs() + if default_envs: + envname = default_envs[0] + if not board_ids: + return envname + + for env in self.config.envs(): + if not board_ids: + return env + if not envname: + envname = env + items = self.config.items(env=env, as_dict=True) + if "board" in items and items.get("board") in board_ids: + return env + return envname + @staticmethod def get_supported_ides(): - tpls_dir = os.path.join(fs.get_source_dir(), "ide", "tpls") + tpls_dir = os.path.join(fs.get_source_dir(), "project", "tpls") return sorted( [ d @@ -61,6 +80,7 @@ class ProjectGenerator(object): "systype": util.get_systype(), "project_name": os.path.basename(self.project_dir), "project_dir": self.project_dir, + "original_env_name": self.original_env_name, "env_name": self.env_name, "user_home_dir": os.path.realpath(fs.expanduser("~")), "platformio_path": sys.argv[0] @@ -110,7 +130,7 @@ class ProjectGenerator(object): def get_tpls(self): tpls = [] - tpls_dir = os.path.join(fs.get_source_dir(), "ide", "tpls", self.ide) + tpls_dir = os.path.join(fs.get_source_dir(), "project", "tpls", self.ide) for root, _, files in os.walk(tpls_dir): for f in files: if not f.endswith(".tpl"): diff --git a/platformio/ide/tpls/atom/.clang_complete.tpl b/platformio/project/tpls/atom/.clang_complete.tpl similarity index 100% rename from platformio/ide/tpls/atom/.clang_complete.tpl rename to platformio/project/tpls/atom/.clang_complete.tpl diff --git a/platformio/ide/tpls/atom/.gcc-flags.json.tpl b/platformio/project/tpls/atom/.gcc-flags.json.tpl similarity index 100% rename from platformio/ide/tpls/atom/.gcc-flags.json.tpl rename to platformio/project/tpls/atom/.gcc-flags.json.tpl diff --git a/platformio/ide/tpls/atom/.gitignore.tpl b/platformio/project/tpls/atom/.gitignore.tpl similarity index 100% rename from platformio/ide/tpls/atom/.gitignore.tpl rename to platformio/project/tpls/atom/.gitignore.tpl diff --git a/platformio/ide/tpls/clion/.gitignore.tpl b/platformio/project/tpls/clion/.gitignore.tpl similarity index 100% rename from platformio/ide/tpls/clion/.gitignore.tpl rename to platformio/project/tpls/clion/.gitignore.tpl diff --git a/platformio/ide/tpls/clion/CMakeLists.txt.tpl b/platformio/project/tpls/clion/CMakeLists.txt.tpl similarity index 100% rename from platformio/ide/tpls/clion/CMakeLists.txt.tpl rename to platformio/project/tpls/clion/CMakeLists.txt.tpl diff --git a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl b/platformio/project/tpls/clion/CMakeListsPrivate.txt.tpl similarity index 100% rename from platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl rename to platformio/project/tpls/clion/CMakeListsPrivate.txt.tpl diff --git a/platformio/ide/tpls/codeblocks/platformio.cbp.tpl b/platformio/project/tpls/codeblocks/platformio.cbp.tpl similarity index 100% rename from platformio/ide/tpls/codeblocks/platformio.cbp.tpl rename to platformio/project/tpls/codeblocks/platformio.cbp.tpl diff --git a/platformio/ide/tpls/eclipse/.cproject.tpl b/platformio/project/tpls/eclipse/.cproject.tpl similarity index 100% rename from platformio/ide/tpls/eclipse/.cproject.tpl rename to platformio/project/tpls/eclipse/.cproject.tpl diff --git a/platformio/ide/tpls/eclipse/.project.tpl b/platformio/project/tpls/eclipse/.project.tpl similarity index 100% rename from platformio/ide/tpls/eclipse/.project.tpl rename to platformio/project/tpls/eclipse/.project.tpl diff --git a/platformio/ide/tpls/eclipse/.settings/PlatformIO Debugger.launch.tpl b/platformio/project/tpls/eclipse/.settings/PlatformIO Debugger.launch.tpl similarity index 100% rename from platformio/ide/tpls/eclipse/.settings/PlatformIO Debugger.launch.tpl rename to platformio/project/tpls/eclipse/.settings/PlatformIO Debugger.launch.tpl diff --git a/platformio/ide/tpls/eclipse/.settings/language.settings.xml.tpl b/platformio/project/tpls/eclipse/.settings/language.settings.xml.tpl similarity index 100% rename from platformio/ide/tpls/eclipse/.settings/language.settings.xml.tpl rename to platformio/project/tpls/eclipse/.settings/language.settings.xml.tpl diff --git a/platformio/ide/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl b/platformio/project/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl similarity index 100% rename from platformio/ide/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl rename to platformio/project/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl diff --git a/platformio/ide/tpls/emacs/.ccls.tpl b/platformio/project/tpls/emacs/.ccls.tpl similarity index 100% rename from platformio/ide/tpls/emacs/.ccls.tpl rename to platformio/project/tpls/emacs/.ccls.tpl diff --git a/platformio/ide/tpls/emacs/.gitignore.tpl b/platformio/project/tpls/emacs/.gitignore.tpl similarity index 100% rename from platformio/ide/tpls/emacs/.gitignore.tpl rename to platformio/project/tpls/emacs/.gitignore.tpl diff --git a/platformio/ide/tpls/netbeans/nbproject/configurations.xml.tpl b/platformio/project/tpls/netbeans/nbproject/configurations.xml.tpl similarity index 100% rename from platformio/ide/tpls/netbeans/nbproject/configurations.xml.tpl rename to platformio/project/tpls/netbeans/nbproject/configurations.xml.tpl diff --git a/platformio/ide/tpls/netbeans/nbproject/private/configurations.xml.tpl b/platformio/project/tpls/netbeans/nbproject/private/configurations.xml.tpl similarity index 100% rename from platformio/ide/tpls/netbeans/nbproject/private/configurations.xml.tpl rename to platformio/project/tpls/netbeans/nbproject/private/configurations.xml.tpl diff --git a/platformio/ide/tpls/netbeans/nbproject/private/launcher.properties.tpl b/platformio/project/tpls/netbeans/nbproject/private/launcher.properties.tpl similarity index 100% rename from platformio/ide/tpls/netbeans/nbproject/private/launcher.properties.tpl rename to platformio/project/tpls/netbeans/nbproject/private/launcher.properties.tpl diff --git a/platformio/ide/tpls/netbeans/nbproject/private/private.xml.tpl b/platformio/project/tpls/netbeans/nbproject/private/private.xml.tpl similarity index 100% rename from platformio/ide/tpls/netbeans/nbproject/private/private.xml.tpl rename to platformio/project/tpls/netbeans/nbproject/private/private.xml.tpl diff --git a/platformio/ide/tpls/netbeans/nbproject/project.xml.tpl b/platformio/project/tpls/netbeans/nbproject/project.xml.tpl similarity index 100% rename from platformio/ide/tpls/netbeans/nbproject/project.xml.tpl rename to platformio/project/tpls/netbeans/nbproject/project.xml.tpl diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.tpl b/platformio/project/tpls/qtcreator/platformio.pro.tpl similarity index 100% rename from platformio/ide/tpls/qtcreator/platformio.pro.tpl rename to platformio/project/tpls/qtcreator/platformio.pro.tpl diff --git a/platformio/ide/tpls/sublimetext/.ccls.tpl b/platformio/project/tpls/sublimetext/.ccls.tpl similarity index 100% rename from platformio/ide/tpls/sublimetext/.ccls.tpl rename to platformio/project/tpls/sublimetext/.ccls.tpl diff --git a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl b/platformio/project/tpls/sublimetext/platformio.sublime-project.tpl similarity index 100% rename from platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl rename to platformio/project/tpls/sublimetext/platformio.sublime-project.tpl diff --git a/platformio/ide/tpls/vim/.ccls.tpl b/platformio/project/tpls/vim/.ccls.tpl similarity index 100% rename from platformio/ide/tpls/vim/.ccls.tpl rename to platformio/project/tpls/vim/.ccls.tpl diff --git a/platformio/ide/tpls/vim/.gitignore.tpl b/platformio/project/tpls/vim/.gitignore.tpl similarity index 100% rename from platformio/ide/tpls/vim/.gitignore.tpl rename to platformio/project/tpls/vim/.gitignore.tpl diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl b/platformio/project/tpls/visualstudio/platformio.vcxproj.filters.tpl similarity index 100% rename from platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl rename to platformio/project/tpls/visualstudio/platformio.vcxproj.filters.tpl diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/project/tpls/visualstudio/platformio.vcxproj.tpl similarity index 100% rename from platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl rename to platformio/project/tpls/visualstudio/platformio.vcxproj.tpl diff --git a/platformio/ide/tpls/vscode/.gitignore.tpl b/platformio/project/tpls/vscode/.gitignore.tpl similarity index 100% rename from platformio/ide/tpls/vscode/.gitignore.tpl rename to platformio/project/tpls/vscode/.gitignore.tpl diff --git a/platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl b/platformio/project/tpls/vscode/.vscode/c_cpp_properties.json.tpl similarity index 100% rename from platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl rename to platformio/project/tpls/vscode/.vscode/c_cpp_properties.json.tpl diff --git a/platformio/ide/tpls/vscode/.vscode/extensions.json.tpl b/platformio/project/tpls/vscode/.vscode/extensions.json.tpl similarity index 100% rename from platformio/ide/tpls/vscode/.vscode/extensions.json.tpl rename to platformio/project/tpls/vscode/.vscode/extensions.json.tpl diff --git a/platformio/ide/tpls/vscode/.vscode/launch.json.tpl b/platformio/project/tpls/vscode/.vscode/launch.json.tpl similarity index 98% rename from platformio/ide/tpls/vscode/.vscode/launch.json.tpl rename to platformio/project/tpls/vscode/.vscode/launch.json.tpl index eb654808..15756575 100644 --- a/platformio/ide/tpls/vscode/.vscode/launch.json.tpl +++ b/platformio/project/tpls/vscode/.vscode/launch.json.tpl @@ -28,7 +28,7 @@ % debug["name"] = "PIO Debug" % debug["preLaunchTask"] = { % "type": "PlatformIO", -% "task": ("Pre-Debug (%s)" % env_name) if len(config.envs()) > 1 else "Pre-Debug", +% "task": ("Pre-Debug (%s)" % env_name) if len(config.envs()) > 1 and original_env_name else "Pre-Debug", % } % noloading = predebug.copy() % noloading["name"] = "PIO Debug (without uploading)" diff --git a/setup.py b/setup.py index 44a67e68..79bc7092 100644 --- a/setup.py +++ b/setup.py @@ -62,10 +62,10 @@ setup( packages=find_packages(exclude=["tests.*", "tests"]) + ["scripts"], package_data={ "platformio": [ - "ide/tpls/*/.*.tpl", - "ide/tpls/*/*.tpl", - "ide/tpls/*/*/*.tpl", - "ide/tpls/*/.*/*.tpl", + "project/tpls/*/.*.tpl", + "project/tpls/*/*.tpl", + "project/tpls/*/*/*.tpl", + "project/tpls/*/.*/*.tpl", ], "scripts": ["99-platformio-udev.rules"], },