Example #1
0
def clean_build_dir(build_dir):
    # remove legacy ".pioenvs" folder
    legacy_build_dir = join(get_project_dir(), ".pioenvs")
    if isdir(legacy_build_dir) and legacy_build_dir != build_dir:
        util.rmtree_(legacy_build_dir)

    structhash_file = join(build_dir, "structure.hash")
    proj_hash = calculate_project_hash()

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

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

    if not isdir(build_dir):
        makedirs(build_dir)

    with open(structhash_file, "w") as f:
        f.write(proj_hash)
Example #2
0
 def __init__(
     self,
     severity,
     category,
     message,
     file="unknown",
     line=0,
     column=0,
     id=None,
     callstack=None,
     cwe=None,
 ):
     assert severity in (self.SEVERITY_HIGH, self.SEVERITY_MEDIUM,
                         self.SEVERITY_LOW)
     self.severity = severity
     self.category = category
     self.message = message
     self.line = int(line)
     self.column = int(column)
     self.callstack = callstack
     self.cwe = cwe
     self.id = id
     self.file = file
     if file.startswith(get_project_dir()):
         self.file = os.path.relpath(file, get_project_dir())
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 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):
            config = ProjectConfig.get_instance(
                os.path.join(storage_dir, "platformio.ini")
            )
            config.validate(options["environment"], silent=in_silence)
            libdeps_dir = config.get_optional_dir("libdeps")
            for env in config.envs():
                if options["environment"] and env not in options["environment"]:
                    continue
                storage_dir = os.path.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 config_call(init_kwargs, method, *args):
     assert isinstance(init_kwargs, dict)
     assert "path" in init_kwargs
     project_dir = get_project_dir()
     if isfile(init_kwargs["path"]):
         project_dir = os.path.dirname(init_kwargs["path"])
     with fs.cd(project_dir):
         return getattr(ProjectConfig(**init_kwargs), method)(*args)
Example #5
0
    def patched_clean_build_dir(build_dir, *args):
        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)
Example #6
0
 def get_source_language(self):
     with fs.cd(get_project_dir()):
         for _, __, files in os.walk(self.config.get_optional_dir("src")):
             for name in files:
                 if "." not in name:
                     continue
                 if os.path.splitext(name)[1].lower() in (".cpp", ".cxx",
                                                          ".ino"):
                     return "c++"
         return "c"
Example #7
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))
Example #8
0
    def patched_clean_build_dir(build_dir, *args):
        from platformio import fs
        from platformio.project.helpers import get_project_dir
        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):
            fs.rmtree(build_dir)

        if not isdir(build_dir):
            makedirs(build_dir)
Example #9
0
def clean_build_dir(build_dir, config):
    # remove legacy ".pioenvs" folder
    legacy_build_dir = join(get_project_dir(), ".pioenvs")
    if isdir(legacy_build_dir) and legacy_build_dir != build_dir:
        fs.rmtree(legacy_build_dir)

    checksum_file = join(build_dir, "project.checksum")
    checksum = compute_project_checksum(config)

    if isdir(build_dir):
        # check project structure
        if isfile(checksum_file) and fs.get_file_contents(checksum_file) == checksum:
            return
        fs.rmtree(build_dir)

    makedirs(build_dir)
    fs.write_file_contents(checksum_file, checksum)
Example #10
0
def collect_component_stats(result):
    components = dict()

    def _append_defect(component, defect):
        if not components.get(component):
            components[component] = Counter()
        components[component].update({DefectItem.SEVERITY_LABELS[defect.severity]: 1})

    for defect in result.get("defects", []):
        component = dirname(defect.file) or defect.file
        _append_defect(component, defect)

        if component.lower().startswith(get_project_dir().lower()):
            while os.sep in component:
                component = dirname(component)
                _append_defect(component, defect)

    return components
Example #11
0
def clean_build_dir(build_dir, config):
    # remove legacy ".pioenvs" folder
    legacy_build_dir = join(get_project_dir(), ".pioenvs")
    if isdir(legacy_build_dir) and legacy_build_dir != build_dir:
        fs.rmtree(legacy_build_dir)

    checksum_file = join(build_dir, "project.checksum")
    checksum = compute_project_checksum(config)

    if isdir(build_dir):
        # check project structure
        if isfile(checksum_file):
            with open(checksum_file) as f:
                if f.read() == checksum:
                    return
        fs.rmtree(build_dir)

    makedirs(build_dir)
    with open(checksum_file, "w") as f:
        f.write(checksum)
Example #12
0
    for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"):
        DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET"

env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)

# Load variables from CLI
env.Replace(
    **{
        key: PlatformBase.decode_scons_arg(env[key])
        for key in list(clivars.keys()) if key in env
    })

# Setup project optional directories
config = env.GetProjectConfig()
env.Replace(
    PROJECT_DIR=get_project_dir(),
    PROJECT_CORE_DIR=config.get_optional_dir("core"),
    PROJECT_PACKAGES_DIR=config.get_optional_dir("packages"),
    PROJECT_WORKSPACE_DIR=config.get_optional_dir("workspace"),
    PROJECT_LIBDEPS_DIR=config.get_optional_dir("libdeps"),
    PROJECT_INCLUDE_DIR=config.get_optional_dir("include"),
    PROJECT_SRC_DIR=config.get_optional_dir("src"),
    PROJECTSRC_DIR=config.get_optional_dir("src"),  # legacy for dev/platform
    PROJECT_TEST_DIR=config.get_optional_dir("test"),
    PROJECT_DATA_DIR=config.get_optional_dir("data"),
    PROJECTDATA_DIR=config.get_optional_dir("data"),  # legacy for dev/platform
    PROJECT_BUILD_DIR=config.get_optional_dir("build"),
    BUILD_CACHE_DIR=config.get_optional_dir("build_cache"),
    LIBSOURCE_DIRS=[
        config.get_optional_dir("lib"),
        join("$PROJECT_LIBDEPS_DIR", "$PIOENV"),
Example #13
0
Import("env")
from platformio import util
from platformio.project.helpers import get_project_build_dir, get_project_dir
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)
Example #14
0
    ("PIOTEST_RUNNING_NAME",),
    ("UPLOAD_PORT",)
)  # yapf: disable

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=[