Handle `env_default` in "platformio.ini" when re-initializing a project // Resolve #950

This commit is contained in:
Ivan Kravets
2017-04-28 18:10:37 +03:00
parent 46e82e08ce
commit 1e5df747cd
3 changed files with 24 additions and 25 deletions

View File

@ -17,11 +17,14 @@ PlatformIO 3.0
that were installed from repository
* Add support for ``.*cc`` extension
(`issue #939 <https://github.com/platformio/platformio-core/issues/939>`_)
* Handle ``env_default`` in `Project Configuration File "platformio.ini" <http://docs.platformio.org/page/projectconf.html>`__
when re-initializing a project
(`issue #950 <https://github.com/platformio/platformio-core/issues/950>`_)
* Don't warn about known ``boards_dir`` option
(`pull #949 <https://github.com/platformio/platformio-core/pull/949>`_)
* Fixed infinite dependency installing when repository consists of multiple
libraries
(`issue #935 <https://github.com/platformio/platformio-core/issues/935>`_)
* Don't warn about known ``boards_dir`` option
(`pull #949 <https://github.com/platformio/platformio-core/pull/949>`_)
* Fixed linter error "unity.h does not exist" for Unit Testing
(`issue #947 <https://github.com/platformio/platformio-core/issues/947>`_)
* Fixed issue when `Library Dependency Finder (LDF) <http://docs.platformio.org/page/librarymanager/ldf.html>`__

View File

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

View File

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