Fixed an issue when VSCode's debugger does not honor default environment // Resolve #4098

This commit is contained in:
Ivan Kravets
2021-11-05 14:46:57 +02:00
parent 1d80da2559
commit 973f77012f
36 changed files with 34 additions and 48 deletions

View File

@ -16,10 +16,12 @@ PlatformIO Core 5
- Show human-readable message when infinite recursion is detected while processing `Interpolation of Values <https://docs.platformio.org/en/latest/projectconf/interpolation.html>`__ (`issue #3883 <https://github.com/platformio/platformio-core/issues/3883>`_)
- Improved directory interpolation (``${platformio.***_dir}``) in `"platformio.ini" <https://docs.platformio.org/en/latest/projectconf.html>`__ configuration file (`issue #3934 <https://github.com/platformio/platformio-core/issues/3934>`_)
- Ignore resolving of SCons variables (e.g., ``${(SOURCE.get_abspath())}``) when preprocessing interpolations (`issue #3933 <https://github.com/platformio/platformio-core/issues/3933>`_)
- Added "inc" as sign that it's the root of the library (`issue #4093 <https://github.com/platformio/platformio-core/issues/4093>`_)
- Fixed an issue when the ``$PROJECT_DIR`` variable was not properly replaced in the `debug_server <https://docs.platformio.org/en/latest/projectconf/section_env_debug.html#debug-server>`__ option (`issue #4086 <https://github.com/platformio/platformio-core/issues/4086>`_)
- Fixed an issue when `PIO Remote <https://docs.platformio.org/en/latest/plus/pio-remote.html>`__ device monitor crashes on the first keypress (`issue #3832 <https://github.com/platformio/platformio-core/issues/3832>`_)
- Fixed "Do not know how to make File target 'debug'" issue when debugging project using `CLion IDE <https://docs.platformio.org/en/latest/integration/ide/clion.html>`__ (`pull #4089 <https://github.com/platformio/platformio-core/issues/4089>`_)
- Fixed "UnicodeEncodeError" when a build output contains non-ASCII characters (`issue #3971 <https://github.com/platformio/platformio-core/issues/3971>`_)
- Fixed an issue when VSCode's debugger does not honor default environment (`issue #4098 <https://github.com/platformio/platformio-core/issues/4098>`_)
5.2.2 (2021-10-20)
~~~~~~~~~~~~~~~~~~

View File

@ -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

View File

@ -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

View File

@ -1,13 +0,0 @@
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# 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.

View File

@ -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"):

View File

@ -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)"

View File

@ -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"],
},