forked from platformio/platformio-core
Add library dependencies using "install_libs" option in platformio.ini // Resolve #134
This commit is contained in:
@ -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>`_)
|
||||
|
@ -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``
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -9,8 +9,10 @@ from time import time
|
||||
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
|
||||
|
||||
|
||||
@ -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 (
|
||||
@ -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)
|
||||
|
Reference in New Issue
Block a user