Exemplo n.º 1
0
def cli(ctx, **options):
    non_storage_cmds = ("search", "show", "register", "stats", "builtin")
    # skip commands that don't need storage folder
    if ctx.invoked_subcommand in non_storage_cmds or \
            (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
        return
    storage_dir = options['storage_dir']
    if not storage_dir:
        if options['global']:
            storage_dir = join(util.get_home_dir(), "lib")
        elif util.is_platformio_project():
            storage_dir = util.get_projectlibdeps_dir()
        elif util.is_ci():
            storage_dir = join(util.get_home_dir(), "lib")
            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_dir and not util.is_platformio_project():
        raise exception.NotGlobalLibDir(util.get_project_dir(),
                                        join(util.get_home_dir(), "lib"),
                                        ctx.invoked_subcommand)

    ctx.obj = LibraryManager(storage_dir)
    if "--json-output" not in ctx.args:
        click.echo("Library Storage: " + storage_dir)
Exemplo n.º 2
0
def cli(ctx, **options):
    non_storage_cmds = ("search", "show", "register", "stats", "builtin")
    # skip commands that don't need storage folder
    if ctx.invoked_subcommand in non_storage_cmds or \
            (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
        return
    storage_dir = options['storage_dir']
    if not storage_dir:
        if options['global']:
            storage_dir = join(util.get_home_dir(), "lib")
        elif util.is_platformio_project():
            storage_dir = util.get_projectlibdeps_dir()
        elif util.is_ci():
            storage_dir = join(util.get_home_dir(), "lib")
            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")
    elif util.is_platformio_project(storage_dir):
        with util.cd(storage_dir):
            storage_dir = util.get_projectlibdeps_dir()

    if not storage_dir and not util.is_platformio_project():
        raise exception.NotGlobalLibDir(util.get_project_dir(),
                                        join(util.get_home_dir(), "lib"),
                                        ctx.invoked_subcommand)

    ctx.obj = LibraryManager(storage_dir)
    if "--json-output" not in ctx.args:
        click.echo("Library Storage: " + storage_dir)
Exemplo n.º 3
0
def cli(ctx, environment, target, upload_port):

    config = util.get_project_config()

    if not config.sections():
        raise exception.ProjectEnvsNotAvailable()

    unknown = set(environment) - set([s[4:] for s in config.sections()])
    if unknown:
        raise exception.UnknownEnvNames(", ".join(unknown))

    # remove ".pioenvs" if project config is modified
    _pioenvs_dir = util.get_pioenvs_dir()
    if (isdir(_pioenvs_dir)
            and getmtime(join(util.get_project_dir(),
                              "platformio.ini")) > getmtime(_pioenvs_dir)):
        rmtree(_pioenvs_dir)

    found_error = False
    _first_done = False
    for section in config.sections():
        # skip main configuration section
        if section == "platformio":
            continue
        elif section[:4] != "env:":
            raise exception.InvalidEnvName(section)

        envname = section[4:]
        if environment and envname not in environment:
            # echo("Skipped %s environment" % style(envname, fg="yellow"))
            continue

        options = {}
        for k, v in config.items(section):
            options[k] = v

        if _first_done:
            click.echo()

        if not process_environment(ctx, envname, options, target, upload_port):
            found_error = True
        _first_done = True

    if found_error:
        raise exception.ReturnErrorCode()
Exemplo n.º 4
0
def cli(ctx, environment, target, upload_port):

    config = util.get_project_config()

    if not config.sections():
        raise exception.ProjectEnvsNotAvailable()

    unknown = set(environment) - set([s[4:] for s in config.sections()])
    if unknown:
        raise exception.UnknownEnvNames(", ".join(unknown))

    # remove ".pioenvs" if project config is modified
    _pioenvs_dir = util.get_pioenvs_dir()
    if (isdir(_pioenvs_dir) and
            getmtime(join(util.get_project_dir(), "platformio.ini")) >
            getmtime(_pioenvs_dir)):
        rmtree(_pioenvs_dir)

    found_error = False
    _first_done = False
    for section in config.sections():
        # skip main configuration section
        if section == "platformio":
            continue
        elif section[:4] != "env:":
            raise exception.InvalidEnvName(section)

        envname = section[4:]
        if environment and envname not in environment:
            # echo("Skipped %s environment" % style(envname, fg="yellow"))
            continue

        options = {}
        for k, v in config.items(section):
            options[k] = v

        if _first_done:
            click.echo()

        if not process_environment(ctx, envname, options, target, upload_port):
            found_error = True
        _first_done = True

    if found_error:
        raise exception.ReturnErrorCode()
Exemplo n.º 5
0
def _clean_pioenvs_dir(pioenvs_dir):
    structhash_file = join(pioenvs_dir, "structure.hash")
    proj_hash = calculate_project_hash()

    # if project's config is modified
    if isdir(pioenvs_dir) and getmtime(join(util.get_project_dir(), "platformio.ini")) > getmtime(pioenvs_dir):
        util.rmtree_(pioenvs_dir)

    # check project structure
    if isdir(pioenvs_dir) and isfile(structhash_file):
        with open(structhash_file) as f:
            if f.read() == proj_hash:
                return
        util.rmtree_(pioenvs_dir)

    if not isdir(pioenvs_dir):
        makedirs(pioenvs_dir)

    with open(structhash_file, "w") as f:
        f.write(proj_hash)
Exemplo n.º 6
0
    def patched_clean_build_dir(build_dir):
        structhash_file = join(build_dir, "structure.hash")
        platformio_ini = join(get_project_dir(), "platformio.ini")

        # if project's config is modified
        if isdir(build_dir) and getmtime(platformio_ini) > getmtime(build_dir):
            util.rmtree_(build_dir)

        if not isdir(build_dir):
            makedirs(build_dir)

        proj_hash = run.calculate_project_hash()

        # check project structure
        if isdir(build_dir) and isfile(structhash_file):
            with open(structhash_file) as f:
                if f.read() == proj_hash:
                    return

        with open(structhash_file, "w") as f:
            f.write(proj_hash)
Exemplo n.º 7
0
def _clean_pioenvs_dir(pioenvs_dir):
    structhash_file = join(pioenvs_dir, "structure.hash")
    proj_hash = calculate_project_hash()

    # if project's config is modified
    if (isdir(pioenvs_dir)
            and getmtime(join(util.get_project_dir(),
                              "platformio.ini")) > getmtime(pioenvs_dir)):
        util.rmtree_(pioenvs_dir)

    # check project structure
    if isdir(pioenvs_dir) and isfile(structhash_file):
        with open(structhash_file) as f:
            if f.read() == proj_hash:
                return
        util.rmtree_(pioenvs_dir)

    if not isdir(pioenvs_dir):
        makedirs(pioenvs_dir)

    with open(structhash_file, "w") as f:
        f.write(proj_hash)
Exemplo n.º 8
0
    # upload options
    (
        "UPLOAD_PORT", ),
    ("UPLOAD_PROTOCOL", ),
    ("UPLOAD_SPEED", ))

DefaultEnvironment(tools=[
    "gcc", "g++", "as", "ar", "gnulink", "platformio", "pioupload", "pioar",
    "piomisc"
],
                   toolpath=[join("$PIOBUILDER_DIR", "tools")],
                   variables=commonvars,
                   UNIX_TIME=int(time()),
                   PIOHOME_DIR=util.get_home_dir(),
                   PROJECT_DIR=util.get_project_dir(),
                   PROJECTLIB_DIR=util.get_projectlib_dir(),
                   PROJECTSRC_DIR=util.get_projectsrc_dir(),
                   PIOENVS_DIR=util.get_pioenvs_dir(),
                   PIOBUILDER_DIR=join(util.get_source_dir(), "builder"),
                   PIOPACKAGES_DIR=join("$PIOHOME_DIR", "packages"),
                   BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"),
                   BUILDSRC_DIR=join("$BUILD_DIR", "src"),
                   LIBSOURCE_DIRS=[
                       "$PROJECTLIB_DIR",
                       util.get_lib_dir(),
                       join("$PLATFORMFW_DIR", "libraries")
                   ])

env = DefaultEnvironment()
Exemplo n.º 9
0
DefaultEnvironment(
    tools=[
        "gcc", "g++", "as", "ar", "gnulink",
        "platformio", "pioupload", "pioar", "piomisc"
    ],
    toolpath=[join("$PIOBUILDER_DIR", "tools")],
    variables=commonvars,

    # Propagating External Environment
    ENV=environ,

    UNIX_TIME=int(time()),
    PROGNAME="program",

    PIOHOME_DIR=util.get_home_dir(),
    PROJECT_DIR=util.get_project_dir(),
    PROJECTLIB_DIR=util.get_projectlib_dir(),
    PROJECTSRC_DIR=util.get_projectsrc_dir(),
    PROJECTDATA_DIR=util.get_projectdata_dir(),
    PIOENVS_DIR=util.get_pioenvs_dir(),

    PIOBUILDER_DIR=join(util.get_source_dir(), "builder"),
    PIOPACKAGES_DIR=join("$PIOHOME_DIR", "packages"),

    BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"),
    BUILDSRC_DIR=join("$BUILD_DIR", "src"),
    LIBSOURCE_DIRS=[
        "$PROJECTLIB_DIR",
        util.get_lib_dir(),
        join("$PLATFORMFW_DIR", "libraries")
    ],
Exemplo n.º 10
0
    ("BOARD_MCU",),
    ("BOARD_F_CPU",),

    # upload options
    ("UPLOAD_PORT",),
    ("UPLOAD_PROTOCOL",),
    ("UPLOAD_SPEED",)
)

DefaultEnvironment(
    tools=["default", "platformio"],
    toolpath=[join("$PIOBUILDER_DIR", "tools")],
    variables=commonvars,

    PIOBUILDER_DIR=join(get_source_dir(), "builder"),
    PROJECT_DIR=get_project_dir(),
    PIOENVS_DIR=get_pioenvs_dir(),

    PLATFORMIOHOME_DIR=get_home_dir(),
    PLATFORM_DIR=join("$PLATFORMIOHOME_DIR", "$PLATFORM"),
    PLATFORMFW_DIR=join("$PLATFORM_DIR", "frameworks", "$FRAMEWORK"),
    PLATFORMTOOLS_DIR=join("$PLATFORM_DIR", "tools"),

    BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"),
    LIBSOURCE_DIRS=[
        join("$PROJECT_DIR", "lib"),
        get_lib_dir(),
        join("$PLATFORMFW_DIR", "libraries"),
    ]
)
Exemplo n.º 11
0
    (
        "BOARD", ),
    ("BOARD_MCU", ),
    ("BOARD_F_CPU", ),

    # upload options
    (
        "UPLOAD_PORT", ),
    ("UPLOAD_PROTOCOL", ),
    ("UPLOAD_SPEED", ))

DefaultEnvironment(tools=["default", "platformio"],
                   toolpath=[join("$PIOBUILDER_DIR", "tools")],
                   variables=commonvars,
                   PIOBUILDER_DIR=join(get_source_dir(), "builder"),
                   PROJECT_DIR=get_project_dir(),
                   PIOENVS_DIR=get_pioenvs_dir(),
                   PLATFORMIOHOME_DIR=get_home_dir(),
                   PLATFORM_DIR=join("$PLATFORMIOHOME_DIR", "$PLATFORM"),
                   PLATFORMFW_DIR=join("$PLATFORM_DIR", "frameworks",
                                       "$FRAMEWORK"),
                   PLATFORMTOOLS_DIR=join("$PLATFORM_DIR", "tools"),
                   BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"),
                   LIBSOURCE_DIRS=[
                       join("$PROJECT_DIR", "lib"),
                       get_lib_dir(),
                       join("$PLATFORMFW_DIR", "libraries"),
                   ])

env = DefaultEnvironment()