Exemplo n.º 1
0
def cli(ctx, environment, target, upload_port, project_dir, project_conf, jobs,
        silent, verbose, disable_auto_clean):
    # find project directory on upper level
    if isfile(project_dir):
        project_dir = find_project_dir_above(project_dir)

    with util.cd(project_dir):
        # clean obsolete build dir
        if not disable_auto_clean:
            try:
                clean_build_dir(get_project_build_dir())
            except:  # pylint: disable=bare-except
                click.secho(
                    "Can not remove temporary directory `%s`. Please remove "
                    "it manually to avoid build issues" %
                    get_project_build_dir(force=True),
                    fg="yellow")

        config = ProjectConfig.get_instance(
            project_conf or join(project_dir, "platformio.ini"))
        config.validate(environment)

        handle_legacy_libdeps(project_dir, config)

        results = []
        start_time = time()
        default_envs = config.default_envs()
        for envname in config.envs():
            skipenv = any([
                environment and envname not in environment, not environment
                and default_envs and envname not in default_envs
            ])
            if skipenv:
                results.append((envname, None))
                continue

            if not silent and any(status is not None
                                  for (_, status) in results):
                click.echo()

            ep = EnvironmentProcessor(ctx, envname, config, target,
                                      upload_port, silent, verbose, jobs)
            result = (envname, ep.process())
            results.append(result)

            if result[1] and "monitor" in ep.get_build_targets() and \
                    "nobuild" not in ep.get_build_targets():
                ctx.invoke(cmd_device_monitor,
                           environment=environment[0] if environment else None)

        found_error = any(status is False for (_, status) in results)

        if (found_error or not silent) and len(results) > 1:
            click.echo()
            print_summary(results, start_time)

        if found_error:
            raise exception.ReturnErrorCode(1)
        return True
Exemplo n.º 2
0
def cli(ctx, environment, target, upload_port, project_dir, project_conf, jobs,
        silent, verbose, disable_auto_clean):
    # find project directory on upper level
    if isfile(project_dir):
        project_dir = find_project_dir_above(project_dir)

    is_test_running = CTX_META_TEST_IS_RUNNING in ctx.meta

    with fs.cd(project_dir):
        config = ProjectConfig.get_instance(
            project_conf or join(project_dir, "platformio.ini"))
        config.validate(environment)

        # clean obsolete build dir
        if not disable_auto_clean:
            try:
                clean_build_dir(get_project_build_dir(), config)
            except:  # pylint: disable=bare-except
                click.secho(
                    "Can not remove temporary directory `%s`. Please remove "
                    "it manually to avoid build issues" %
                    get_project_build_dir(force=True),
                    fg="yellow")

        handle_legacy_libdeps(project_dir, config)

        default_envs = config.default_envs()
        results = []
        for env in config.envs():
            skipenv = any([
                environment and env not in environment, not environment
                and default_envs and env not in default_envs
            ])
            if skipenv:
                results.append({"env": env})
                continue

            # print empty line between multi environment project
            if not silent and any(
                    r.get("succeeded") is not None for r in results):
                click.echo()

            results.append(
                process_env(ctx, env, config, environment, target, upload_port,
                            silent, verbose, jobs, is_test_running))

        command_failed = any(r.get("succeeded") is False for r in results)

        if (not is_test_running and (command_failed or not silent)
                and len(results) > 1):
            print_processing_summary(results)

        if command_failed:
            raise exception.ReturnErrorCode(1)
        return True
Exemplo n.º 3
0
def test_run(pioproject_dir):
    with util.cd(pioproject_dir):
        build_dir = get_project_build_dir()
        if isdir(build_dir):
            util.rmtree_(build_dir)

        env_names = ProjectConfig(join(pioproject_dir,
                                       "platformio.ini")).envs()
        result = util.exec_command(
            ["platformio", "run", "-e",
             random.choice(env_names)])
        if result['returncode'] != 0:
            pytest.fail(str(result))

        assert isdir(build_dir)

        # check .elf file
        for item in listdir(build_dir):
            if not isdir(item):
                continue
            assert isfile(join(build_dir, item, "firmware.elf"))
            # check .hex or .bin files
            firmwares = []
            for ext in ("bin", "hex"):
                firmwares += glob(join(build_dir, item, "firmware*.%s" % ext))
            if not firmwares:
                pytest.fail("Missed firmware file")
            for firmware in firmwares:
                assert getsize(firmware) > 0
Exemplo n.º 4
0
 def run(self):
     with util.cd(self.options['project_dir']):
         build_dir = get_project_build_dir()
     result = util.exec_command(
         [join(build_dir, self.env_name, "program")],
         stdout=LineBufferedAsyncPipe(self.on_run_out),
         stderr=LineBufferedAsyncPipe(self.on_run_out))
     assert "returncode" in result
     return result['returncode'] == 0 and not self._run_failed
Exemplo n.º 5
0
def add_compile_crystal_target():
    input_file = get_crystal_target()
    output_obj_file = join(get_project_build_dir(), envname,
                           "__crystal_{}".format(relpath(input_file)))
    print("output file : %s" % output_obj_file)

    shard_yml = isfile("shard.yml")
    linker_cmdline_file = join(get_project_build_dir(), envname,
                               "__linker_cmd_{}".format(relpath(input_file)))

    sed_cmd = "sed -E -e 's/^.*-rdynamic//' -e 's/-L[^ ]+//g' -e 's/\/[^ ]+libcrystal.a//g'"

    compile = "{bin} build {crystal_target} --verbose -o{output} --cross-compile --target={target} {flags} | {sed} > {file}".format(
        bin=get_shards_binary() if shard_yml else get_crystal_binary(),
        crystal_target=input_file
        if shard_yml or isfile(input_file) else "src/%s.cr" % input_file,
        output=output_obj_file,
        target=get_crystal_triple(),
        flags=get_crystal_build_flags(),
        file=linker_cmdline_file,
        sed=sed_cmd)

    output_obj_file = output_obj_file + ".o"

    install_shards = "{bin} update".format(bin=get_shards_binary())
    install_dep = None

    if shard_yml:
        env.AlwaysBuild(env.Alias("install_shards", None, [install_shards]))
        install_dep = "install_shards"

    env.Command(output_obj_file, install_dep, [compile])

    env.Depends("%s/%s/program" % (get_project_build_dir(), envname),
                output_obj_file)
    env.Append(PIOBUILDFILES=abspath(output_obj_file))

    libpath = join(get_crystal_lib_path(), "rpi", "libraries")
    local_libraries_exist = exists(join(get_project_dir(), "libraries"))
    local_libpath = " -L" + join(get_project_dir(),
                                 "libraries") if local_libraries_exist else ""
    env.Append(LINKFLAGS="@%s -L%s%s" %
               (linker_cmdline_file, libpath, local_libpath))
Exemplo n.º 6
0
def add_compile_crystal_extension():
    env.Append(SRC_FILTER="-<*/ext/sigfault.c>")
    libname = join(get_project_build_dir(), get_envname(), "crystal.o")
    env.Object(libname, ["src/ext/sigfault.c"])
    env.Append(LINKFLAGS=libname)
    env.Depends("%s/%s/program" % (get_project_build_dir(), envname), libname)
Exemplo n.º 7
0
from platformio.project.config import ProjectConfig
from os.path import basename, join, relpath, abspath, isfile, exists
from os import environ
import base64
import subprocess
import re

config = ProjectConfig.get_instance(join(get_project_dir(), "platformio.ini"))


def get_envname():
    return base64.b64decode(ARGUMENTS["PIOENV"])


envname = get_envname()
print("PBD: %s, env : %s" % (relpath(get_project_build_dir()), envname))


def get_option(section, option, dft):
    if config.has_option(section, option):
        return config.get(section, option)
    else:
        return dft


def get_env_option(name, default):
    return get_option("env:%s" % envname, name, default)


def get_crystal_target():
    return get_env_option("crystal_target", "main")
Exemplo n.º 8
0
    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()
    ],
    PROGNAME="program",
    PROG_PATH=join("$BUILD_DIR", "$PROGNAME$PROGSUFFIX"),
    PYTHONEXE=get_pythonexe_path())

if not int(ARGUMENTS.get("PIOVERBOSE", 0)):