Skip to content

Commit

Permalink
Add library dependencies using "install_libs" option in platformio.in…
Browse files Browse the repository at this point in the history
…i // Resolve #134
  • Loading branch information
ivankravets committed May 1, 2015
1 parent 7391dfa commit 424e87a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Release History
(`issue #174 <https://github.com/platformio/platformio/issues/174>`_)
* Added global ``-f, --force`` option which will force to accept any
confirmation prompts (`issue #152 <https://github.com/platformio/platformio/issues/152>`_)
* Added library dependencies using ``install_libs`` option in
`platformio.ini <http://docs.platformio.org/en/latest/projectconf.html#install-libs>`__
(`issue #134 <https://github.com/platformio/platformio/issues/134>`_)
* Allowed to add more boards to existing
`platformio.ini <http://docs.platformio.org/en/latest/projectconf.html>`__
(`issue #167 <https://github.com/platformio/platformio/issues/167>`_)
Expand Down
16 changes: 16 additions & 0 deletions docs/projectconf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,22 @@ but will be applied only for the project source code from
This option can be overridden by global environment variable
:ref:`envvar_PLATFORMIO_SRCBUILD_FLAGS`.

``install_libs``
^^^^^^^^^^^^^^^^

Specify dependent libraries which should be installed before environment
process. The only library IDs are allowed. Multiple libraries can be passed
using comma ``,`` sign.

You can obtain library IDs using :ref:`cmd_lib_search` command.

Example:

.. code-block:: ini
[env:depends_on_some_libs]
install_libs = 1,13,19
``ignore_libs``
^^^^^^^^^^^^^^^

Expand Down
32 changes: 30 additions & 2 deletions platformio/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import click

from platformio import app, exception, telemetry, util
from platformio.commands.lib import lib_install as cmd_lib_install
from platformio.commands.platforms import \
platforms_install as cmd_platforms_install
from platformio.libmanager import LibraryManager
from platformio.platforms.base import PlatformFactory


Expand Down Expand Up @@ -115,6 +117,16 @@ def _run_environment(ctx, name, options, targets, upload_port):

telemetry.on_run_environment(options, envtargets)

# install platform and libs dependencies
_autoinstall_env_platform(ctx, platform)
if "install_libs" in options:
_autoinstall_env_libs(ctx, options['install_libs'])

p = PlatformFactory.newPlatform(platform)
return p.run(variables, envtargets)


def _autoinstall_env_platform(ctx, platform):
installed_platforms = PlatformFactory.get_platforms(
installed=True).keys()
if (platform not in installed_platforms and (
Expand All @@ -123,5 +135,21 @@ def _run_environment(ctx, name, options, targets, upload_port):
"Would you like to install it now?" % platform))):
ctx.invoke(cmd_platforms_install, platforms=[platform])

p = PlatformFactory.newPlatform(platform)
return p.run(variables, envtargets)

def _autoinstall_env_libs(ctx, libids_list):
require_libs = [int(l.strip()) for l in libids_list.split(",")]
installed_libs = [
l['id'] for l in LibraryManager().get_installed().values()
]

not_intalled_libs = set(require_libs) - set(installed_libs)
if not require_libs or not not_intalled_libs:
return

if (not app.get_setting("enable_prompts") or
click.confirm(
"The libraries with IDs '%s' have not been installed yet. "
"Would you like to install them now?" %
", ".join([str(i) for i in not_intalled_libs])
)):
ctx.invoke(cmd_lib_install, libid=not_intalled_libs)

0 comments on commit 424e87a

Please sign in to comment.