diff --git a/HISTORY.rst b/HISTORY.rst index 82e88c12..c56a4597 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -17,11 +17,14 @@ PlatformIO 3.0 that were installed from repository * Add support for ``.*cc`` extension (`issue #939 `_) +* Handle ``env_default`` in `Project Configuration File "platformio.ini" `__ + when re-initializing a project + (`issue #950 `_) +* Don't warn about known ``boards_dir`` option + (`pull #949 `_) * Fixed infinite dependency installing when repository consists of multiple libraries (`issue #935 `_) -* Don't warn about known ``boards_dir`` option - (`pull #949 `_) * Fixed linter error "unity.h does not exist" for Unit Testing (`issue #947 `_) * Fixed issue when `Library Dependency Finder (LDF) `__ diff --git a/platformio/commands/init.py b/platformio/commands/init.py index fb303641..0ee751c0 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -96,21 +96,10 @@ def cli( ide is not None) if ide: - if not board: - board = get_first_board(project_dir) - if board: - board = [board] - if not board: + env_name = get_best_envname(project_dir, board) + if not env_name: 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 " - "linter) 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 = ProjectGenerator(project_dir, ide, env_name) pg.generate() if not silent: @@ -126,13 +115,20 @@ def cli( fg="green") -def get_first_board(project_dir): +def get_best_envname(project_dir, boards=None): config = util.load_project_config(project_dir) + env_default = None + if config.has_option("platformio", "env_default"): + env_default = config.get("platformio", + "env_default").split(", ")[0].strip() + if env_default: + return env_default for section in config.sections(): if not section.startswith("env:"): continue - elif config.has_option(section, "board"): - return config.get(section, "board") + elif config.has_option(section, "board") and (not boards or config.get( + section, "board") in boards): + return section[4:] return None diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 711e01af..6020a7e4 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -27,10 +27,10 @@ from platformio.commands.run import cli as cmd_run class ProjectGenerator(object): - def __init__(self, project_dir, ide, board): + def __init__(self, project_dir, ide, env_name): self.project_dir = project_dir self.ide = ide - self.board = board + self.env_name = env_name self._tplvars = {} with util.cd(self.project_dir): @@ -46,23 +46,23 @@ class ProjectGenerator(object): @util.memoized def get_project_env(self): - data = {"env_name": "PlatformIO"} + data = None config = util.load_project_config(self.project_dir) for section in config.sections(): if not section.startswith("env:"): continue + if self.env_name != section[4:]: + continue data = {"env_name": section[4:]} for k, v in config.items(section): data[k] = v - if self.board == data.get("board"): - break return data @util.memoized def get_project_build_data(self): data = {"defines": [], "includes": [], "cxx_path": None} envdata = self.get_project_env() - if "env_name" not in envdata: + if not envdata: return data out = StringIO()