Example #1
0
        def _get_project_data(project_dir):
            data = {"boards": [], "envLibdepsDirs": [], "libExtraDirs": []}
            config = ProjectConfig(join(project_dir, "platformio.ini"))
            libdeps_dir = get_project_libdeps_dir()

            data['libExtraDirs'].extend(
                config.get("platformio", "lib_extra_dirs", []))

            for section in config.sections():
                if not section.startswith("env:"):
                    continue
                data['envLibdepsDirs'].append(join(libdeps_dir, section[4:]))
                if config.has_option(section, "board"):
                    data['boards'].append(config.get(section, "board"))
                data['libExtraDirs'].extend(
                    config.get(section, "lib_extra_dirs", []))

            # skip non existing folders and resolve full path
            for key in ("envLibdepsDirs", "libExtraDirs"):
                data[key] = [
                    expanduser(d) if d.startswith("~") else realpath(d)
                    for d in data[key] if isdir(d)
                ]

            return data
Example #2
0
    def _load_tplvars(self):
        tpl_vars = {"env_name": self.env_name}
        # default env configuration
        tpl_vars.update(
            ProjectConfig.get_instance(join(
                self.project_dir, "platformio.ini")).items(env=self.env_name,
                                                           as_dict=True))
        # build data
        tpl_vars.update(
            load_project_ide_data(self.project_dir, self.env_name) or {})

        with util.cd(self.project_dir):
            tpl_vars.update({
                "project_name": basename(self.project_dir),
                "src_files": self.get_src_files(),
                "user_home_dir": abspath(expanduser("~")),
                "project_dir": self.project_dir,
                "project_src_dir": get_project_src_dir(),
                "project_lib_dir": get_project_lib_dir(),
                "project_libdeps_dir": join(
                    get_project_libdeps_dir(), self.env_name),
                "systype": util.get_systype(),
                "platformio_path": self._fix_os_path(
                    sys.argv[0] if isfile(sys.argv[0])
                    else where_is_program("platformio")),
                "env_pathsep": os.pathsep,
                "env_path": self._fix_os_path(os.getenv("PATH"))
            })  # yapf: disable
        return tpl_vars
Example #3
0
def cli(ctx, **options):
    storage_cmds = ("install", "uninstall", "update", "list")
    # skip commands that don't need storage folder
    if ctx.invoked_subcommand not in storage_cmds or \
            (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
        return
    storage_dirs = list(options['storage_dir'])
    if options['global']:
        storage_dirs.append(get_project_global_lib_dir())
    if not storage_dirs:
        if is_platformio_project():
            storage_dirs = [get_project_dir()]
        elif is_ci():
            storage_dirs = [get_project_global_lib_dir()]
            click.secho(
                "Warning! Global library storage is used automatically. "
                "Please use `platformio lib --global %s` command to remove "
                "this warning." % ctx.invoked_subcommand,
                fg="yellow")

    if not storage_dirs:
        raise exception.NotGlobalLibDir(get_project_dir(),
                                        get_project_global_lib_dir(),
                                        ctx.invoked_subcommand)

    in_silence = PlatformioCLI.in_silence()
    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:
        if not is_platformio_project(storage_dir):
            ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir)
            continue
        with fs.cd(storage_dir):
            libdeps_dir = get_project_libdeps_dir()
        config = ProjectConfig.get_instance(join(storage_dir,
                                                 "platformio.ini"))
        config.validate(options['environment'], silent=in_silence)
        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)
            ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY][storage_dir] = config.get(
                "env:" + env, "lib_deps", [])
Example #4
0
def handle_legacy_libdeps(project_dir, config):
    legacy_libdeps_dir = join(project_dir, ".piolibdeps")
    if (not isdir(legacy_libdeps_dir)
            or legacy_libdeps_dir == get_project_libdeps_dir()):
        return
    if not config.has_section("env"):
        config.add_section("env")
    lib_extra_dirs = config.get("env", "lib_extra_dirs", [])
    lib_extra_dirs.append(legacy_libdeps_dir)
    config.set("env", "lib_extra_dirs", lib_extra_dirs)
    click.secho(
        "DEPRECATED! A legacy library storage `{0}` has been found in a "
        "project. \nPlease declare project dependencies in `platformio.ini`"
        " file using `lib_deps` option and remove `{0}` folder."
        "\nMore details -> http://docs.platformio.org/page/projectconf/"
        "section_env_library.html#lib-deps".format(legacy_libdeps_dir),
        fg="yellow")
    def _load_tplvars(self):
        tpl_vars = {
            "config": self.config,
            "systype": util.get_systype(),
            "project_name": basename(self.project_dir),
            "project_dir": self.project_dir,
            "env_name": self.env_name,
            "user_home_dir": abspath(expanduser("~")),
            "platformio_path":
                sys.argv[0] if isfile(sys.argv[0])
                else where_is_program("platformio"),
            "env_path": os.getenv("PATH"),
            "env_pathsep": os.pathsep
        }   # yapf: disable

        # default env configuration
        tpl_vars.update(self.config.items(env=self.env_name, as_dict=True))
        # build data
        tpl_vars.update(
            load_project_ide_data(self.project_dir, self.env_name) or {})

        with fs.cd(self.project_dir):
            tpl_vars.update({
                "src_files": self.get_src_files(),
                "project_src_dir": get_project_src_dir(),
                "project_lib_dir": get_project_lib_dir(),
                "project_libdeps_dir": join(
                    get_project_libdeps_dir(), self.env_name)

            })  # yapf: disable

        for key, value in tpl_vars.items():
            if key.endswith(("_path", "_dir")):
                tpl_vars[key] = fs.to_unix_path(value)
        for key in ("includes", "src_files", "libsource_dirs"):
            if key not in tpl_vars:
                continue
            tpl_vars[key] = [fs.to_unix_path(inc) for inc in tpl_vars[key]]

        tpl_vars['to_unix_path'] = fs.to_unix_path
        return tpl_vars
Example #6
0
DEFAULT_ENV_OPTIONS = dict(
    tools=[
        "ar", "gas", "gcc", "g++", "gnulink", "platformio", "pioplatform",
        "pioproject", "piowinhooks", "piolib", "pioupload", "piomisc", "pioide"
    ],
    toolpath=[join(util.get_source_dir(), "builder", "tools")],
    variables=clivars,

    # Propagating External Environment
    ENV=environ,
    UNIX_TIME=int(time()),
    PROJECT_DIR=project_helpers.get_project_dir(),
    PROJECTCORE_DIR=project_helpers.get_project_core_dir(),
    PROJECTPACKAGES_DIR=project_helpers.get_project_packages_dir(),
    PROJECTWORKSPACE_DIR=project_helpers.get_project_workspace_dir(),
    PROJECTLIBDEPS_DIR=project_helpers.get_project_libdeps_dir(),
    PROJECTINCLUDE_DIR=project_helpers.get_project_include_dir(),
    PROJECTSRC_DIR=project_helpers.get_project_src_dir(),
    PROJECTTEST_DIR=project_helpers.get_project_test_dir(),
    PROJECTDATA_DIR=project_helpers.get_project_data_dir(),
    PROJECTBUILD_DIR=project_helpers.get_project_build_dir(),
    BUILDCACHE_DIR=project_helpers.get_project_optional_dir("build_cache_dir"),
    BUILD_DIR=join("$PROJECTBUILD_DIR", "$PIOENV"),
    BUILDSRC_DIR=join("$BUILD_DIR", "src"),
    BUILDTEST_DIR=join("$BUILD_DIR", "test"),
    LIBPATH=["$BUILD_DIR"],
    LIBSOURCE_DIRS=[
        project_helpers.get_project_lib_dir(),
        join("$PROJECTLIBDEPS_DIR", "$PIOENV"),
        project_helpers.get_project_global_lib_dir()
    ],