Improve Project Generator when custom `--project-option is passed to platformio init` command

This commit is contained in:
Ivan Kravets
2016-09-13 19:22:19 +03:00
parent 8199272328
commit 05bbd4a7f8
5 changed files with 59 additions and 35 deletions

View File

@ -7,6 +7,9 @@ PlatformIO 3.0
3.0.2 (2016-09-??)
~~~~~~~~~~~~~~~~~~
* Improved Project Generator when custom ``--project-option`` is passed to
`platformio init <http://docs.platformio.org/en/stable/userguide/cmd_init.html>`_
command
* Disable SSL Server-Name-Indication for Python < 2.7.9
* Return valid exit code from ``plaformio test`` command

View File

@ -118,9 +118,9 @@ Buid project using pre-configured :ref:`projectconf`.
.. option::
-O, --project-option
Pass additional options from :ref:`projectconf` to
:option:`platformio init --project-option` command. For example,
automatically install dependent libraries
Pass additional options from :ref:`projectconf` to :ref:`cmd_init` command.
Use multiple ``--project-option`` options to pass multiple options to
:ref:`cmd_init` command. For example, automatically install dependent libraries
``platformio ci --project-option="lib_deps=ArduinoJSON"`` or ignore specific
library ``platformio ci --project-option="lib_ignore=SomeLib"``.

View File

@ -89,11 +89,11 @@ be ``[env:teensy_31]``.
Examples
--------
1. Create new project in the current working directory
1. Initialize new project in a current working directory
.. code-block:: bash
.. code::
$ platformio init
> platformio init
The current working directory *** will be used for the new project.
You can specify another project directory via
@ -110,38 +110,35 @@ Examples
`platformio run --target clean` - clean project (remove compiled files)
2. Create new project in the specified directory
2. Initialize new project in a specified directory
.. code-block:: bash
.. code::
$ platformio init -d %PATH_TO_DIR%
> platformio init -d %PATH_TO_DIR%
The next files/directories will be created in ***
platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
src - Put your source files here
lib - Put here project specific (private) libraries
Project has been successfully initialized!
Useful commands:
`platformio run` - process/build project from the current directory
`platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board
`platformio run --target clean` - clean project (remove compiled files)
...
3. Initialize project for Arduino Uno
.. code-block:: bash
.. code::
$ platformio init --board uno
> platformio init --board uno
The current working directory *** will be used for the new project.
You can specify another project directory via
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
...
4. Initialize project for Teensy 3.1 board with custom :ref:`framework_mbed`
.. code::
> platformio init --board teensy31 --project-option "framework=mbed"
The current working directory *** will be used for the new project.
You can specify another project directory via
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
The next files/directories will be created in ***
platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
src - Put your source files here
lib - Put here project specific (private) libraries
Project has been successfully initialized!
Useful commands:
`platformio run` - process/build project from the current directory
`platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board
`platformio run --target clean` - clean project (remove compiled files)
...

View File

@ -317,18 +317,25 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
continue
used_boards.append(id_)
content.append("")
content.append("[env:%s%s]" % (env_prefix, id_))
content.append("platform = %s" % manifest['platform'])
envopts = {
"platform": manifest['platform'],
"board": id_
}
# find default framework for board
frameworks = manifest.get("frameworks")
if frameworks:
content.append("framework = %s" % frameworks[0])
envopts['framework'] = frameworks[0]
content.append("board = %s" % id_)
if project_option:
content.extend(project_option)
for item in project_option:
if "=" not in item:
continue
_name, _value = item.split("=", 1)
envopts[_name.strip()] = _value.strip()
content.append("")
content.append("[env:%s%s]" % (env_prefix, id_))
for name, value in envopts.items():
content.append("%s = %s" % (name, value))
if force_download and used_platforms:
_install_dependent_platforms(ctx, used_platforms)

View File

@ -132,6 +132,23 @@ def test_init_enable_auto_uploading(clirunner, validate_cliresult):
set(config.items("env:uno")))) == 0
def test_init_custom_framework(clirunner, validate_cliresult):
with clirunner.isolated_filesystem():
result = clirunner.invoke(
cmd_init, ["-b", "teensy31", "--project-option", "framework=mbed"])
validate_cliresult(result)
validate_pioproject(getcwd())
config = util.load_project_config()
expected_result = [
("platform", "teensy"), ("framework", "mbed"),
("board", "teensy31")
]
assert config.has_section("env:teensy31")
assert len(
set(expected_result).symmetric_difference(
set(config.items("env:teensy31")))) == 0
def test_init_incorrect_board(clirunner):
result = clirunner.invoke(cmd_init, ["-b", "missed_board"])
assert result.exit_code == 2