diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 45fa1fe0..96493d49 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -93,10 +93,24 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 if board: fill_project_envs( - ctx, project_file, board, enable_auto_uploading, env_prefix) + ctx, project_file, board, enable_auto_uploading, env_prefix, + ide is not None + ) if ide: - pg = ProjectGenerator(project_dir, ide, board[0] if board else None) + if not board: + raise exception.BoardNotDefined() + if len(board) > 1: + click.secho( + "Warning! You have initialised project with more than 1 board" + " for the specified IDE.\n" + "However, the IDE features (code autocompletion, syntax lint)" + " have been configured for the first board '%s' from your list" + " '%s'." % (board[0], ", ".join(board)), + fg="yellow" + ) + pg = ProjectGenerator( + project_dir, ide, board[0]) pg.generate() click.secho( @@ -113,7 +127,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 def fill_project_envs(ctx, project_file, board_types, enable_auto_uploading, - env_prefix): + env_prefix, force_download): builtin_boards = get_boards() content = [] used_envs = [] @@ -144,7 +158,8 @@ def fill_project_envs(ctx, project_file, board_types, enable_auto_uploading, if enable_auto_uploading: content.append("targets = upload") - _install_dependent_platforms(ctx, used_platforms) + if force_download and used_platforms: + _install_dependent_platforms(ctx, used_platforms) if not content: return diff --git a/platformio/exception.py b/platformio/exception.py index afba9b61..48d109ae 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -48,6 +48,13 @@ class PlatformNotInstalledYet(PlatformioException): "Use `platformio platforms install` command" +class BoardNotDefined(PlatformioException): + + MESSAGE = "You need to specify board type using `-b` or `--board` "\ + "option. Supported boards list is available via "\ + " `platformio boards` command" + + class UnknownBoard(PlatformioException): MESSAGE = "Unknown board type '%s'" diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 7e90574c..28132e58 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -20,12 +20,12 @@ from os.path import abspath, basename, expanduser, isdir, join, relpath import bottle import click -from platformio import util +from platformio import exception, util class ProjectGenerator(object): - def __init__(self, project_dir, ide, board=None): + def __init__(self, project_dir, ide, board): self.project_dir = project_dir self.ide = ide self.board = board @@ -50,7 +50,7 @@ class ProjectGenerator(object): data = {"env_name": section[4:]} for k, v in config.items(section): data[k] = v - if self.board and self.board == data.get("board"): + if self.board == data.get("board"): break return data @@ -68,16 +68,15 @@ class ProjectGenerator(object): ["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 + raise exception.PlatformioException( + "\n".join([result['out'], result['err']])) output = result['out'] - try: - start_index = output.index('\n{"') - stop_index = output.rindex('}') - data = json.loads(output[start_index + 1:stop_index + 1]) - except ValueError: - pass + start_index = output.index('\n{"') + stop_index = output.rindex('}') + data = json.loads(output[start_index + 1:stop_index + 1]) return data