forked from platformio/platformio-core
Fixed an issue when VSCode's debugger does not honor default environment // Resolve #4098
This commit is contained in:
1 parent
1d80da2559
commit
973f77012f
36 files changed
+34
-48
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
@@ -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"):
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -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)"
|
||||
Reference in new issue
Block a user