Example #1
0
def cli(
        ctx,
        environment,
        target,
        upload_port,  # pylint: disable=R0913,R0914
        project_dir,
        verbose,
        disable_auto_clean):
    with util.cd(project_dir):
        config = util.get_project_config()

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

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

        # clean obsolete .pioenvs dir
        if not disable_auto_clean:
            try:
                _clean_pioenvs_dir(util.get_pioenvs_dir())
            except:  # pylint: disable=bare-except
                click.secho(
                    "Can not remove temporary directory `%s`. Please remove "
                    "`.pioenvs` directory from the project manually to avoid "
                    "build issues" % util.get_pioenvs_dir(),
                    fg="yellow")

        results = []
        for section in config.sections():
            # skip main configuration section
            if section == "platformio":
                continue

            if not section.startswith("env:"):
                raise exception.InvalidEnvName(section)

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

            if results:
                click.echo()

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

            ep = EnvironmentProcessor(ctx, envname, options, target,
                                      upload_port, verbose)
            results.append(ep.process())

        if not all(results):
            raise exception.ReturnErrorCode()
Example #2
0
def cli(ctx, environment, target, upload_port,  # pylint: disable=R0913,R0914
        project_dir, verbose, disable_auto_clean):
    with util.cd(project_dir):
        config = util.get_project_config()

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

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

        # clean obsolete .pioenvs dir
        if not disable_auto_clean:
            try:
                _clean_pioenvs_dir(util.get_pioenvs_dir())
            except:  # pylint: disable=bare-except
                click.secho(
                    "Can not remove temporary directory `%s`. Please remove "
                    "`.pioenvs` directory from the project manually to avoid "
                    "build issues" % util.get_pioenvs_dir(),
                    fg="yellow"
                )

        results = []
        for section in config.sections():
            # skip main configuration section
            if section == "platformio":
                continue

            if not section.startswith("env:"):
                raise exception.InvalidEnvName(section)

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

            if results:
                click.echo()

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

            ep = EnvironmentProcessor(
                ctx, envname, options, target, upload_port, verbose)
            results.append(ep.process())

        if not all(results):
            raise exception.ReturnErrorCode()
Example #3
0
def run(
        ctx=None,
        environment=(),
        target=(),
        upload_port=None,  # pylint: disable=R0913,R0914
        project_dir=os.getcwd(),
        verbose=3,
        disable_auto_clean=False):
    with util.cd(project_dir):
        config = util.get_project_config()

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

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

        # clean obsolete .pioenvs dir
        if not disable_auto_clean:
            try:
                _clean_pioenvs_dir(util.get_pioenvs_dir())
            except Exception:
                raise exception.CleanPioenvsDirError(util.get_pioenvs_dir())

        results = []
        for section in config.sections():
            # skip main configuration section
            if section == "platformio":
                continue

            if not section.startswith("env:"):
                raise exception.InvalidEnvName(section)

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

            if results:
                click.echo()

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

            ep = EnvironmentProcessor(ctx, envname, options, target,
                                      upload_port, verbose)
            results.append(ep.process(
            ))  # [JORGE_GARCIA] modified to get process description

        return results
Example #4
0
def run(
    ctx=None,
    environment=(),
    target=(),
    upload_port=None,  # pylint: disable=R0913,R0914
    project_dir=os.getcwd(),
    verbose=3,
    disable_auto_clean=False,
):
    with util.cd(project_dir):
        config = util.get_project_config()

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

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

        # clean obsolete .pioenvs dir
        if not disable_auto_clean:
            try:
                _clean_pioenvs_dir(util.get_pioenvs_dir())
            except Exception:
                raise exception.CleanPioenvsDirError(util.get_pioenvs_dir())

        results = []
        for section in config.sections():
            # skip main configuration section
            if section == "platformio":
                continue

            if not section.startswith("env:"):
                raise exception.InvalidEnvName(section)

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

            if results:
                click.echo()

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

            ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, verbose)
            results.append(ep.process())  # [JORGE_GARCIA] modified to get process description

        return results
Example #5
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()
Example #6
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()
Example #7
0
def _clean_pioenvs_dir():
    pioenvs_dir = util.get_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):
        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
        rmtree(pioenvs_dir)

    if not isdir(pioenvs_dir):
        makedirs(pioenvs_dir)

    with open(structhash_file, "w") as f:
        f.write(proj_hash)
Example #8
0
def _clean_pioenvs_dir():
    pioenvs_dir = util.get_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)):
        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
        rmtree(pioenvs_dir)

    if not isdir(pioenvs_dir):
        makedirs(pioenvs_dir)

    with open(structhash_file, "w") as f:
        f.write(proj_hash)
Example #9
0
        "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()

if "BOARD" in env:
    try:
        env.Replace(BOARD_OPTIONS=util.get_boards(env.subst("$BOARD")))
Example #10
0
    ],
    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")
    ],

    PYTHONEXE=normpath(sys.executable)
)
Example #11
0
    ("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()
Example #12
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()

if not isdir(env['PLATFORMIOHOME_DIR']):