forked from platformio/platformio-core
Install all project dependencies declared via "lib_deps" option using "platformio lib install" command // Resolve #2147
This commit is contained in:
@ -18,6 +18,7 @@ PlatformIO 4.0
|
|||||||
|
|
||||||
* **Library Management**
|
* **Library Management**
|
||||||
|
|
||||||
|
- Install all project dependencies declared via `lib_deps <http://docs.platformio.org/page/projectconf/section_env_library.html#lib-deps>`__ option using `platformio lib install <http://docs.platformio.org/page/userguide/lib/cmd_install.html>`__ command (`issue #2147 <https://github.com/platformio/platformio-core/issues/2147>`_)
|
||||||
- Use isolated library dependency storage per project build environment (`issue #1696 <https://github.com/platformio/platformio-core/issues/1696>`_)
|
- Use isolated library dependency storage per project build environment (`issue #1696 <https://github.com/platformio/platformio-core/issues/1696>`_)
|
||||||
- Override default source and include directories for a library via `library.json <http://docs.platformio.org/page/librarymanager/config.html>`__ manifest using ``includeDir`` and ``srcDir`` fields
|
- Override default source and include directories for a library via `library.json <http://docs.platformio.org/page/librarymanager/config.html>`__ manifest using ``includeDir`` and ``srcDir`` fields
|
||||||
- Use workspace ``.pio/libdeps`` folder for project dependencies instead of ``.piolibdeps``
|
- Use workspace ``.pio/libdeps`` folder for project dependencies instead of ``.piolibdeps``
|
||||||
|
2
docs
2
docs
Submodule docs updated: bbf0f91e9f...51593ac34b
@ -21,7 +21,8 @@ from os.path import isdir, join
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import exception, util
|
from platformio import exception, util
|
||||||
from platformio.managers.lib import LibraryManager, get_builtin_libs
|
from platformio.managers.lib import (LibraryManager, get_builtin_libs,
|
||||||
|
is_builtin_lib)
|
||||||
from platformio.proc import is_ci
|
from platformio.proc import is_ci
|
||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
from platformio.project.helpers import (
|
from platformio.project.helpers import (
|
||||||
@ -33,6 +34,7 @@ except ImportError:
|
|||||||
from urllib import quote
|
from urllib import quote
|
||||||
|
|
||||||
CTX_META_STORAGE_DIRS_KEY = __name__ + ".storage_dirs"
|
CTX_META_STORAGE_DIRS_KEY = __name__ + ".storage_dirs"
|
||||||
|
CTX_META_STORAGE_LIBDEPS_KEY = __name__ + ".storage_lib_deps"
|
||||||
|
|
||||||
|
|
||||||
@click.group(short_help="Library Manager")
|
@click.group(short_help="Library Manager")
|
||||||
@ -86,20 +88,24 @@ def cli(ctx, **options):
|
|||||||
ctx.invoked_subcommand)
|
ctx.invoked_subcommand)
|
||||||
|
|
||||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = []
|
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = []
|
||||||
|
ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY] = {}
|
||||||
for storage_dir in storage_dirs:
|
for storage_dir in storage_dirs:
|
||||||
if is_platformio_project(storage_dir):
|
if not is_platformio_project(storage_dir):
|
||||||
with util.cd(storage_dir):
|
|
||||||
config = ProjectConfig.get_instance(
|
|
||||||
join(storage_dir, "platformio.ini"))
|
|
||||||
config.validate(options['environment'])
|
|
||||||
libdeps_dir = get_projectlibdeps_dir()
|
|
||||||
for env in config.envs():
|
|
||||||
if (not options['environment']
|
|
||||||
or env in options['environment']):
|
|
||||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(
|
|
||||||
join(libdeps_dir, env))
|
|
||||||
else:
|
|
||||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir)
|
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir)
|
||||||
|
continue
|
||||||
|
with util.cd(storage_dir):
|
||||||
|
libdeps_dir = get_projectlibdeps_dir()
|
||||||
|
config = ProjectConfig.get_instance(
|
||||||
|
join(storage_dir, "platformio.ini"))
|
||||||
|
config.validate(options['environment'])
|
||||||
|
for env in config.envs():
|
||||||
|
if options['environment'] and env not in options['environment']:
|
||||||
|
continue
|
||||||
|
storage_dir = join(libdeps_dir, env)
|
||||||
|
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir)
|
||||||
|
if config.has_option("env:" + env, "lib_deps"):
|
||||||
|
ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY][
|
||||||
|
storage_dir] = config.getlist("env:" + env, "lib_deps")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("install", short_help="Install library")
|
@cli.command("install", short_help="Install library")
|
||||||
@ -122,13 +128,30 @@ def cli(ctx, **options):
|
|||||||
help="Reinstall/redownload library if exists")
|
help="Reinstall/redownload library if exists")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def lib_install(ctx, libraries, silent, interactive, force):
|
def lib_install(ctx, libraries, silent, interactive, force):
|
||||||
|
storage_libdeps = ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY]
|
||||||
storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
|
storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
|
||||||
for storage_dir in storage_dirs:
|
for storage_dir in storage_dirs:
|
||||||
print_storage_header(storage_dirs, storage_dir)
|
if not silent and (libraries or storage_dir in storage_libdeps):
|
||||||
|
print_storage_header(storage_dirs, storage_dir)
|
||||||
lm = LibraryManager(storage_dir)
|
lm = LibraryManager(storage_dir)
|
||||||
for library in libraries:
|
if libraries:
|
||||||
lm.install(
|
for library in libraries:
|
||||||
library, silent=silent, interactive=interactive, force=force)
|
lm.install(
|
||||||
|
library,
|
||||||
|
silent=silent,
|
||||||
|
interactive=interactive,
|
||||||
|
force=force)
|
||||||
|
elif storage_dir in storage_libdeps:
|
||||||
|
for library in storage_libdeps[storage_dir]:
|
||||||
|
try:
|
||||||
|
lm.install(
|
||||||
|
library,
|
||||||
|
silent=silent,
|
||||||
|
interactive=interactive,
|
||||||
|
force=force)
|
||||||
|
except exception.LibNotFound as e:
|
||||||
|
if not silent or not is_builtin_lib(library):
|
||||||
|
click.secho("Warning! %s" % e, fg="yellow")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("uninstall", short_help="Uninstall libraries")
|
@cli.command("uninstall", short_help="Uninstall libraries")
|
||||||
|
@ -20,11 +20,11 @@ import click
|
|||||||
|
|
||||||
from platformio import exception, telemetry, util
|
from platformio import exception, telemetry, util
|
||||||
from platformio.commands.device import device_monitor as cmd_device_monitor
|
from platformio.commands.device import device_monitor as cmd_device_monitor
|
||||||
from platformio.commands.lib import CTX_META_STORAGE_DIRS_KEY
|
from platformio.commands.lib import (CTX_META_STORAGE_DIRS_KEY,
|
||||||
|
CTX_META_STORAGE_LIBDEPS_KEY)
|
||||||
from platformio.commands.lib import lib_install as cmd_lib_install
|
from platformio.commands.lib import lib_install as cmd_lib_install
|
||||||
from platformio.commands.platform import \
|
from platformio.commands.platform import \
|
||||||
platform_install as cmd_platform_install
|
platform_install as cmd_platform_install
|
||||||
from platformio.managers.lib import is_builtin_lib
|
|
||||||
from platformio.managers.platform import PlatformFactory
|
from platformio.managers.platform import PlatformFactory
|
||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
from platformio.project.helpers import (
|
from platformio.project.helpers import (
|
||||||
@ -273,17 +273,17 @@ def _handle_legacy_libdeps(project_dir, config):
|
|||||||
def _autoinstall_libdeps(ctx, envname, libraries, verbose=False):
|
def _autoinstall_libdeps(ctx, envname, libraries, verbose=False):
|
||||||
if not libraries:
|
if not libraries:
|
||||||
return
|
return
|
||||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [
|
libdeps_dir = join(get_projectlibdeps_dir(), envname)
|
||||||
join(get_projectlibdeps_dir(), envname)
|
ctx.meta.update({
|
||||||
]
|
CTX_META_STORAGE_DIRS_KEY: [libdeps_dir],
|
||||||
for lib in libraries:
|
CTX_META_STORAGE_LIBDEPS_KEY: {
|
||||||
try:
|
libdeps_dir: libraries
|
||||||
ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
|
}
|
||||||
except exception.LibNotFound as e:
|
})
|
||||||
if verbose or not is_builtin_lib(lib):
|
try:
|
||||||
click.secho("Warning! %s" % e, fg="yellow")
|
ctx.invoke(cmd_lib_install, silent=not verbose)
|
||||||
except exception.InternetIsOffline as e:
|
except exception.InternetIsOffline as e:
|
||||||
click.secho(str(e), fg="yellow")
|
click.secho(str(e), fg="yellow")
|
||||||
|
|
||||||
|
|
||||||
def _clean_build_dir(build_dir):
|
def _clean_build_dir(build_dir):
|
||||||
|
Reference in New Issue
Block a user