Project dependencies per build environment using "lib_deps" option // Resolve #413

This commit is contained in:
Ivan Kravets
2016-08-08 16:03:17 +03:00
parent 0b749c3888
commit 65e0daa06d
7 changed files with 85 additions and 44 deletions

View File

@ -26,10 +26,12 @@ PlatformIO 3.0
* Library Manager 3.0
+ Project dependencies per build environment using `lib_deps <http://docs.platformio.org/en/latest/projectconf.html#lib-deps>`__ option
(`issue #413 <https://github.com/platformio/platformio/issues/413>`_)
+ `Semantic Versioning <http://semver.org/>`__ for library commands and
dependencies
(`issue #410 <https://github.com/platformio/platformio/issues/410>`_)
+ Multiple library storages: project's local, PlatformIO global or custom
+ Multiple library storages: Project's Local, PlatformIO's Global or Custom
(`issue #475 <https://github.com/platformio/platformio/issues/475>`_)
+ Install library by name
(`issue #414 <https://github.com/platformio/platformio/issues/414>`_)

View File

@ -57,6 +57,10 @@ Allows to override :ref:`projectconf` option :ref:`projectconf_pio_home_dir`.
Allows to override :ref:`projectconf` option :ref:`projectconf_pio_lib_dir`.
.. envvar:: PLATFORMIO_LIBDEPS_DIR
Allows to override :ref:`projectconf` option :ref:`projectconf_pio_libdeps_dir`.
.. envvar:: PLATFORMIO_SRC_DIR
Allows to override :ref:`projectconf` option :ref:`projectconf_pio_src_dir`.

View File

@ -30,6 +30,7 @@ Library Dependency Finder has controls that can be set up in :ref:`projectconf`:
.. hlist::
:columns: 3
* :ref:`projectconf_lib_deps`
* :ref:`projectconf_lib_extra_dirs`
* :ref:`projectconf_lib_force`
* :ref:`projectconf_lib_ignore`
@ -43,12 +44,13 @@ Library Dependency Finder has controls that can be set up in :ref:`projectconf`:
Storage
-------
There are different storages/folders where Library Dependency Finder looks for
libraries. These folders/path have priority and LDF operates in the next order:
There are different storages where Library Dependency Finder looks for
libraries. These storages (folders) have priority and LDF operates in the next
order:
1. :ref:`projectconf_lib_extra_dirs` - extra storages per build environment
2. :ref:`projectconf_pio_lib_dir` - own/private library storage per project
3. :ref:`projectconf_pio_piolibdeps_dir` - project dependencies storage used by
3. :ref:`projectconf_pio_libdeps_dir` - project dependencies storage used by
:ref:`librarymanager`
4. ":ref:`projectconf_pio_home_dir`/lib" - global storage per all projects.

View File

@ -102,17 +102,17 @@ Then in ``src/main.c`` you should use:
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
.. _projectconf_pio_piolibdeps_dir:
.. _projectconf_pio_libdeps_dir:
``piolibdeps_dir``
^^^^^^^^^^^^^^^^^^
``libdeps_dir``
^^^^^^^^^^^^^^^
Internal storage where :ref:`librarymanager` will install project dependencies.
A default value is ``.piolibdeps`` that means that folder is located in the root of
project.
Internal storage where :ref:`librarymanager` will install project dependencies
(:ref:`projectconf_lib_deps`). A default value is ``.piolibdeps`` that means
that folder is located in the root of project.
This option can be overridden by global environment variable
:envvar:`PLATFORMIO_PIOLIBDEPS_DIR`.
:envvar:`PLATFORMIO_LIBDEPS_DIR`.
.. _projectconf_pio_src_dir:
@ -639,21 +639,40 @@ Library options
.. contents::
:local:
``lib_install``
^^^^^^^^^^^^^^^
.. _projectconf_lib_deps:
Specify dependent libraries which should be installed before environment
process. The only library IDs are allowed. Multiple libraries can be passed
using comma ``,`` sign.
``lib_deps``
^^^^^^^^^^^^
You can obtain library IDs using :ref:`cmd_lib_search` command.
Specify project dependencies that should be installed automatically to
:ref:`projectconf_pio_libdeps_dir` before an environment process.
Multiple dependencies are allowed (multi-lines).
**Valid forms**
.. code-block:: ini
[env:***]
lib_deps =
LIBRARY_1
LIBRARY_2
LIBRARY_N
The each line with ``LIBRARY_1... LIBRARY_N`` will be passed automatically to
:ref:`cmd_lib_install` command. Please follow to :ref:`cmd_lib_install` for
detailed documentation about possible values.
Example:
.. code-block:: ini
[env:depends_on_some_libs]
lib_install = 1,13,19
[env:depends_on_some_libs]
lib_deps =
1
PubSubClient
Json@~5.6,!=5.4
https://github.com/gioblu/PJON.git@v2.0
https://github.com/me-no-dev/ESPAsyncTCP.git
.. _projectconf_lib_force:
@ -663,12 +682,12 @@ Example:
.. seealso::
Please make sure to read :ref:`ldf` guide first.
Force Library Dependency Finder to depend on the specified libraries if
they even are not included in the project source code. Also, these
libraries will be processed in the first order.
Force Library Dependency Finder to depend on the specified library if it even
is not included in the project source code. Also, this library will be
processed in the first order.
The correct value for this option is library name (not
folder name). In the most cases, library name is pre-defined in manifest file
The correct value for this option is library name (not folder name). In the
most cases, library name is pre-defined in manifest file
(:ref:`library_config`, ``library.properties``, ``module.json``). The multiple
library names are allowed, split them with comma ``,`` separator.

View File

@ -38,6 +38,7 @@ Usage
# [LIBRARY...] forms
platformio lib [STORAGE_OPTIONS] install (with no args, project dependencies)
platformio lib [STORAGE_OPTIONS] install <id>
platformio lib [STORAGE_OPTIONS] install id=<id>
platformio lib [STORAGE_OPTIONS] install <id>@<version>
platformio lib [STORAGE_OPTIONS] install <id>@<version range>
platformio lib [STORAGE_OPTIONS] install <name>
@ -47,7 +48,7 @@ Usage
platformio lib [STORAGE_OPTIONS] install file://<zip or tarball file>
platformio lib [STORAGE_OPTIONS] install file://<folder>
platformio lib [STORAGE_OPTIONS] install <repository>
platformio lib [STORAGE_OPTIONS] install <name=repository> (name it should have locally)
platformio lib [STORAGE_OPTIONS] install <name>=<repository> (name it should have locally)
platformio lib [STORAGE_OPTIONS] install <repository#tag> ("tag" can be commit, branch or tag)
Description

View File

@ -14,7 +14,7 @@
import sys
VERSION = (3, 0, "0.dev21")
VERSION = (3, 0, "0.dev22")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -111,13 +111,14 @@ def cli(ctx, # pylint: disable=R0913,R0914
class EnvironmentProcessor(object):
KNOWN_OPTIONS = (
"platform", "framework", "board", "board_mcu", "board_f_cpu",
"board_f_flash", "board_flash_mode", "build_flags", "src_build_flags",
"build_unflags", "src_filter", "extra_script", "targets",
"upload_port", "upload_protocol", "upload_speed", "upload_flags",
"upload_resetmethod", "lib_install", "lib_force", "lib_ignore",
"lib_extra_dirs", "lib_ldf_mode", "lib_compat_mode", "piotest")
KNOWN_OPTIONS = ("platform", "framework", "board", "board_mcu",
"board_f_cpu", "board_f_flash", "board_flash_mode",
"build_flags", "src_build_flags", "build_unflags",
"src_filter", "extra_script", "targets", "upload_port",
"upload_protocol", "upload_speed", "upload_flags",
"upload_resetmethod", "lib_install", "lib_deps",
"lib_force", "lib_ignore", "lib_extra_dirs",
"lib_ldf_mode", "lib_compat_mode", "piotest")
REMAPED_OPTIONS = {"framework": "pioframework", "platform": "pioplatform"}
@ -141,10 +142,18 @@ class EnvironmentProcessor(object):
terminal_width, _ = click.get_terminal_size()
start_time = time()
click.echo("[%s] Processing %s (%s)" % (
datetime.now().strftime("%c"), click.style(
self.name, fg="cyan", bold=True), ", ".join(
["%s: %s" % (k, v) for k, v in self.options.iteritems()])))
process_opts = []
for k, v in self.options.items():
if "\n" in v:
process_opts.append((k, "; ".join(
[s.strip() for s in v.split("\n") if s.strip()])))
else:
process_opts.append((k, v))
click.echo("[%s] Processing %s (%s)" %
(datetime.now().strftime("%c"), click.style(
self.name, fg="cyan", bold=True),
", ".join(["%s: %s" % opts for opts in process_opts])))
click.secho("-" * terminal_width, bold=True)
self.options = self._validate_options(self.options)
@ -212,8 +221,15 @@ class EnvironmentProcessor(object):
# install dependent libraries
if "lib_install" in self.options:
_autoinstall_libs(self.cmd_ctx, self.options['lib_install'],
self.verbose)
_autoinstall_libdeps(self.cmd_ctx, [
int(d.strip()) for d in self.options['lib_install'].split(",")
if d.strip()
], self.verbose)
if "lib_deps" in self.options:
_autoinstall_libdeps(self.cmd_ctx, [
d.strip() for d in self.options['lib_deps'].split("\n")
if d.strip()
], self.verbose)
try:
p = PlatformFactory.newPlatform(self.options['platform'])
@ -225,15 +241,12 @@ class EnvironmentProcessor(object):
return p.run(build_vars, build_targets, self.verbose)
def _autoinstall_libs(ctx, libids_list, verbose=False):
def _autoinstall_libdeps(ctx, libraries, verbose=False):
storage_dir = util.get_projectlibdeps_dir()
ctx.obj = LibraryManager(storage_dir)
if verbose:
click.echo("Library Storage: " + storage_dir)
ctx.invoke(
cmd_lib_install,
libraries=[int(l.strip()) for l in libids_list.split(",")],
quiet=not verbose)
ctx.invoke(cmd_lib_install, libraries=libraries, quiet=not verbose)
def _clean_pioenvs_dir(pioenvs_dir):