Fix critical issue when platformio init --ide__ command hangs PlatformIO // Resolve #283

This commit is contained in:
Ivan Kravets
2015-09-06 18:16:09 +03:00
parent bc449fec48
commit 0311418bfc
5 changed files with 32 additions and 8 deletions

View File

@ -4,6 +4,12 @@ Release History
PlatformIO 2.0
--------------
2.3.1 (2015-09-??)
~~~~~~~~~~~~~~~~~~
* Fixed critical issue when `platformio init --ide <http://docs.platformio.org/en/latest/userguide/cmd_init.html>`__ command hangs PlatformIO
(`issue #283 <https://github.com/platformio/platformio/issues/283>`_)
2.3.0 (2015-09-05)
~~~~~~~~~~~~~~~~~~

View File

@ -1,7 +1,7 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
VERSION = (2, 3, 0)
VERSION = (2, 3, "1.dev0")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -8,7 +8,10 @@ from shutil import copyfile
import click
from platformio import app, exception
from platformio.commands.platforms import \
platforms_install as cli_platforms_install
from platformio.ide.projectgenerator import ProjectGenerator
from platformio.platforms.base import PlatformFactory
from platformio.util import get_boards, get_source_dir
@ -33,7 +36,9 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
type=click.Choice(ProjectGenerator.get_supported_ides()))
@click.option("--disable-auto-uploading", is_flag=True)
@click.option("--env-prefix", default="")
def cli(project_dir, board, ide, disable_auto_uploading, env_prefix):
@click.pass_context
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
disable_auto_uploading, env_prefix):
# ask about auto-uploading
if board and app.get_setting("enable_prompts"):
@ -95,7 +100,7 @@ For example, "lib/private_lib/[here are source files]".
if board:
fill_project_envs(
project_file, board, disable_auto_uploading, env_prefix)
ctx, project_file, board, disable_auto_uploading, env_prefix)
if ide:
pg = ProjectGenerator(project_dir, ide, board[0] if board else None)
@ -113,11 +118,12 @@ For example, "lib/private_lib/[here are source files]".
)
def fill_project_envs(project_file, board_types, disable_auto_uploading,
def fill_project_envs(ctx, project_file, board_types, disable_auto_uploading,
env_prefix):
builtin_boards = get_boards()
content = []
used_envs = []
used_platforms = []
with open(project_file) as f:
used_envs = [l.strip() for l in f.read().splitlines() if
@ -125,6 +131,7 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading,
for type_ in board_types:
data = builtin_boards[type_]
used_platforms.append(data['platform'])
env_name = "[env:%s%s]" % (env_prefix, type_)
if env_name in used_envs:
@ -143,9 +150,21 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading,
content.append("%stargets = upload" % ("# " if disable_auto_uploading
else ""))
_install_dependent_platforms(ctx, used_platforms)
if not content:
return
with open(project_file, "a") as f:
content.append("")
f.write("\n".join(content))
def _install_dependent_platforms(ctx, platforms):
installed_platforms = PlatformFactory.get_platforms(installed=True).keys()
if set(platforms) <= set(installed_platforms):
return
ctx.invoke(
cli_platforms_install,
platforms=list(set(platforms) - set(installed_platforms))
)

View File

@ -174,8 +174,7 @@ class EnvironmentProcessor(object):
def _autoinstall_platform(ctx, platform, targets):
installed_platforms = PlatformFactory.get_platforms(
installed=True).keys()
installed_platforms = PlatformFactory.get_platforms(installed=True).keys()
cmd_options = {}
p = PlatformFactory.newPlatform(platform)

View File

@ -53,8 +53,8 @@ class ProjectGenerator(object):
if "env_name" not in envdata:
return data
result = util.exec_command(
["platformio", "run", "-t", "idedata", "-e", envdata['env_name'],
"--project-dir", self.project_dir]
["platformio", "-f", "run", "-t", "idedata",
"-e", envdata['env_name'], "-d", self.project_dir]
)
if result['returncode'] != 0 or '"includes":' not in result['out']:
return data