From 65e0daa06dde68e409cd43bf8b7256f48283f9a4 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 8 Aug 2016 16:03:17 +0300 Subject: [PATCH] Project dependencies per build environment using "lib_deps" option // Resolve #413 --- HISTORY.rst | 4 +- docs/envvars.rst | 4 ++ docs/librarymanager/ldf.rst | 8 ++-- docs/projectconf.rst | 59 ++++++++++++++++++++---------- docs/userguide/lib/cmd_install.rst | 3 +- platformio/__init__.py | 2 +- platformio/commands/run.py | 49 ++++++++++++++++--------- 7 files changed, 85 insertions(+), 44 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 395e28be..9ee0df5c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -26,10 +26,12 @@ PlatformIO 3.0 * Library Manager 3.0 + + Project dependencies per build environment using `lib_deps `__ option + (`issue #413 `_) + `Semantic Versioning `__ for library commands and dependencies (`issue #410 `_) - + Multiple library storages: project's local, PlatformIO global or custom + + Multiple library storages: Project's Local, PlatformIO's Global or Custom (`issue #475 `_) + Install library by name (`issue #414 `_) diff --git a/docs/envvars.rst b/docs/envvars.rst index 771f043e..5931e391 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -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`. diff --git a/docs/librarymanager/ldf.rst b/docs/librarymanager/ldf.rst index c3dd7504..bd5889ff 100644 --- a/docs/librarymanager/ldf.rst +++ b/docs/librarymanager/ldf.rst @@ -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. diff --git a/docs/projectconf.rst b/docs/projectconf.rst index 439ced3d..09c8f35f 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -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. diff --git a/docs/userguide/lib/cmd_install.rst b/docs/userguide/lib/cmd_install.rst index c43122c0..6f007bbe 100644 --- a/docs/userguide/lib/cmd_install.rst +++ b/docs/userguide/lib/cmd_install.rst @@ -38,6 +38,7 @@ Usage # [LIBRARY...] forms platformio lib [STORAGE_OPTIONS] install (with no args, project dependencies) platformio lib [STORAGE_OPTIONS] install + platformio lib [STORAGE_OPTIONS] install id= platformio lib [STORAGE_OPTIONS] install @ platformio lib [STORAGE_OPTIONS] install @ platformio lib [STORAGE_OPTIONS] install @@ -47,7 +48,7 @@ Usage platformio lib [STORAGE_OPTIONS] install file:// platformio lib [STORAGE_OPTIONS] install file:// platformio lib [STORAGE_OPTIONS] install - platformio lib [STORAGE_OPTIONS] install (name it should have locally) + platformio lib [STORAGE_OPTIONS] install = (name it should have locally) platformio lib [STORAGE_OPTIONS] install ("tag" can be commit, branch or tag) Description diff --git a/platformio/__init__.py b/platformio/__init__.py index d3eaf0e4..706fe860 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -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" diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 180d01a9..3309cf07 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -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):