Exemplo n.º 1
0
    def install_dependencies(self):
        def _is_builtin(uri):
            for lb in self.env.GetLibBuilders():
                if lb.name == uri:
                    return True
            return False

        not_found_uri = []
        for uri in self.dependencies:
            # check if built-in library
            if _is_builtin(uri):
                continue

            found = False
            for storage_dir in self.env.GetLibSourceDirs():
                lm = LibraryManager(storage_dir)
                if lm.get_package_dir(*lm.parse_pkg_uri(uri)):
                    found = True
                    break
            if not found:
                not_found_uri.append(uri)

        did_install = False
        lm = LibraryManager(
            self.env.subst(join("$PROJECT_LIBDEPS_DIR", "$PIOENV")))
        for uri in not_found_uri:
            try:
                lm.install(uri)
                did_install = True
            except (exception.LibNotFound, exception.InternetIsOffline) as e:
                click.secho("Warning! %s" % e, fg="yellow")

        # reset cache
        if did_install:
            DefaultEnvironment().Replace(__PIO_LIB_BUILDERS=None)
Exemplo n.º 2
0
def lib_install(  # pylint: disable=too-many-arguments
        ctx, libraries, save, silent, interactive, force):
    storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
    storage_libdeps = ctx.meta.get(CTX_META_STORAGE_LIBDEPS_KEY, [])

    installed_manifests = {}
    for storage_dir in storage_dirs:
        if not silent and (libraries or storage_dir in storage_libdeps):
            print_storage_header(storage_dirs, storage_dir)
        lm = LibraryManager(storage_dir)
        if libraries:
            for library in libraries:
                pkg_dir = lm.install(library,
                                     silent=silent,
                                     interactive=interactive,
                                     force=force)
                installed_manifests[library] = lm.load_manifest(pkg_dir)
        elif storage_dir in storage_libdeps:
            builtin_lib_storages = None
            for library in storage_libdeps[storage_dir]:
                try:
                    pkg_dir = lm.install(library,
                                         silent=silent,
                                         interactive=interactive,
                                         force=force)
                    installed_manifests[library] = lm.load_manifest(pkg_dir)
                except exception.LibNotFound as e:
                    if builtin_lib_storages is None:
                        builtin_lib_storages = get_builtin_libs()
                    if not silent or not is_builtin_lib(
                            builtin_lib_storages, library):
                        click.secho("Warning! %s" % e, fg="yellow")

    if not save or not libraries:
        return

    input_dirs = ctx.meta.get(CTX_META_INPUT_DIRS_KEY, [])
    project_environments = ctx.meta[CTX_META_PROJECT_ENVIRONMENTS_KEY]
    for input_dir in input_dirs:
        config = ProjectConfig.get_instance(
            os.path.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.get("env:" + env, "lib_deps", [])
            for library in libraries:
                if library in lib_deps:
                    continue
                manifest = installed_manifests[library]
                try:
                    assert library.lower() == manifest["name"].lower()
                    assert semantic_version.Version(manifest["version"])
                    lib_deps.append("{name}@^{version}".format(**manifest))
                except (AssertionError, ValueError):
                    lib_deps.append(library)
            config.set("env:" + env, "lib_deps", lib_deps)
            config.save()
Exemplo n.º 3
0
def library_manager_libdeps(lib_deps, storage=None):
    from platformio.managers.lib import LibraryManager
    from platformio.project.helpers import get_project_global_lib_dir

    if not storage:
        manager = LibraryManager(get_project_global_lib_dir())
    else:
        manager = LibraryManager(storage)

    for lib in lib_deps:
        if manager.get_package_dir(*manager.parse_pkg_uri(lib)):
            continue
        log("installing: {}".format(lib))
        manager.install(lib)