diff --git a/HISTORY.rst b/HISTORY.rst index 2c946a5b..5dbb1ba7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,7 +18,8 @@ PlatformIO 4.0 * **Library Management** - - Install all project dependencies declared via `lib_deps `__ option using `platformio lib install `__ command (`issue #2147 `_) + - Save libraries passed to `platformio lib install `__ command into the project dependency list (`lib_deps `__) with a new ``--save`` flag (`issue #1028 `_) + - Install all project dependencies declared via `lib_deps `__ option using a simple `platformio lib install `__ command (`issue #2147 `_) - Use isolated library dependency storage per project build environment (`issue #1696 `_) - Override default source and include directories for a library via `library.json `__ manifest using ``includeDir`` and ``srcDir`` fields - Use workspace ``.pio/libdeps`` folder for project dependencies instead of ``.piolibdeps`` diff --git a/docs b/docs index 51593ac3..2ed6a490 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 51593ac34b0a5db3dbff589e7b2672d940ce635e +Subproject commit 2ed6a490e5853bd71afaa08bc34750970293d43d diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 777ab237..af0e2105 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -33,6 +33,8 @@ try: except ImportError: from urllib import quote +CTX_META_INPUT_DIRS_KEY = __name__ + ".input_dirs" +CTX_META_PROJECT_ENVIRONMENTS_KEY = __name__ + ".project_environments" CTX_META_STORAGE_DIRS_KEY = __name__ + ".storage_dirs" CTX_META_STORAGE_LIBDEPS_KEY = __name__ + ".storage_lib_deps" @@ -87,6 +89,8 @@ def cli(ctx, **options): join(util.get_home_dir(), "lib"), ctx.invoked_subcommand) + ctx.meta[CTX_META_PROJECT_ENVIRONMENTS_KEY] = options['environment'] + ctx.meta[CTX_META_INPUT_DIRS_KEY] = storage_dirs ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [] ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY] = {} for storage_dir in storage_dirs: @@ -110,11 +114,10 @@ def cli(ctx, **options): @cli.command("install", short_help="Install library") @click.argument("libraries", required=False, nargs=-1, metavar="[LIBRARY...]") -# @click.option( -# "--save", -# is_flag=True, -# help="Save installed libraries into the project's platformio.ini " -# "library dependencies") +@click.option( + "--save", + is_flag=True, + help="Save installed libraries into the `platformio.ini` dependency list") @click.option( "-s", "--silent", is_flag=True, help="Suppress progress reporting") @click.option( @@ -127,9 +130,29 @@ def cli(ctx, **options): is_flag=True, help="Reinstall/redownload library if exists") @click.pass_context -def lib_install(ctx, libraries, silent, interactive, force): - storage_libdeps = ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY] +def lib_install( # pylint: disable=too-many-arguments + ctx, libraries, save, silent, interactive, force): storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY] + input_dirs = ctx.meta.get(CTX_META_INPUT_DIRS_KEY, []) + storage_libdeps = ctx.meta.get(CTX_META_STORAGE_LIBDEPS_KEY, []) + + if save and libraries: + project_environments = ctx.meta[CTX_META_PROJECT_ENVIRONMENTS_KEY] + for input_dir in input_dirs: + config = ProjectConfig.get_instance( + join(input_dir, "platformio.ini")) + config.validate(project_environments) + for env in config.envs(): + if project_environments and env not in project_environments: + continue + config.expand_interpolations = False + lib_deps = (config.getlist( + "env:" + env, "lib_deps") if config.has_option( + "env:" + env, "lib_deps") else []) + lib_deps.extend(l for l in libraries if l not in lib_deps) + config.set("env:" + env, "lib_deps", lib_deps) + config.save() + for storage_dir in storage_dirs: if not silent and (libraries or storage_dir in storage_libdeps): print_storage_header(storage_dirs, storage_dir) diff --git a/platformio/project/config.py b/platformio/project/config.py index a7f9b7b8..27557d56 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -230,6 +230,8 @@ class ProjectConfig(object): def set(self, section, option, value): if isinstance(value, (list, tuple)): value = "\n".join(value) + if value: + value = "\n" + value # start from a new line self._parser.set(section, option, value) def get(self, section, option): diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 6bdb48a1..7564a03d 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -391,7 +391,7 @@ def backup_reports(items): for params in items: # skip static options - for key in params.keys(): + for key in list(params.keys()): if key in ("v", "tid", "cid", "cd1", "cd2", "sr", "an"): del params[key]