diff --git a/HISTORY.rst b/HISTORY.rst index b765373a7d..2cf461a371 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,9 @@ Release History (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) +* Added library dependencies using ``install_libs`` option in + `platformio.ini `__ + (`issue #134 `_) * Allowed to add more boards to existing `platformio.ini `__ (`issue #167 `_) diff --git a/docs/projectconf.rst b/docs/projectconf.rst index b33f0ea745..5242e3aa8e 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -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`` ^^^^^^^^^^^^^^^ diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 8d3d792fdd..0a49d513c4 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -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 @@ -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)