How to use the platformio.proc.exec_command function in platformio

To help you get started, we’ve selected a few platformio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github platformio / platformio-core / platformio / builder / tools / pioide.py View on Github external
def _get_gcc_defines(env):
    items = []
    try:
        sysenv = os.environ.copy()
        sysenv["PATH"] = str(env["ENV"]["PATH"])
        result = exec_command(
            "echo | %s -dM -E -" % env.subst("$CC"), env=sysenv, shell=True
        )
    except OSError:
        return items
    if result["returncode"] != 0:
        return items
    for line in result["out"].split("\n"):
        tokens = line.strip().split(" ", 2)
        if not tokens or tokens[0] != "#define":
            continue
        if len(tokens) > 2:
            items.append("%s=%s" % (tokens[1], tokens[2]))
        else:
            items.append(tokens[1])
    return items
github platformio / platformio-core / platformio / commands / check / tools / base.py View on Github external
def _get_toolchain_defines(cc_path):
        defines = []
        result = proc.exec_command("echo | %s -dM -E -x c++ -" % cc_path, shell=True)

        for line in result["out"].split("\n"):
            tokens = line.strip().split(" ", 2)
            if not tokens or tokens[0] != "#define":
                continue
            if len(tokens) > 2:
                defines.append("%s=%s" % (tokens[1], tokens[2]))
            else:
                defines.append(tokens[1])

        return defines
github WallaceWilliam / framework-esp8266-rtos-sdk-idf-platformio / builder / frameworks / esp8266-rtos-sdk.py View on Github external
def partition_table_get_partition_info(get_part_info_args, part_info):
    idf_env = environ.copy()
    populate_idf_env_vars(idf_env)

    cmd = [
            env.subst("$PYTHONEXE"), env.subst("$PARTTOOL"),
            "-q",
            "--partition-table-offset", env['SDKCONFIG']['CONFIG_PARTITION_TABLE_OFFSET'],
            "--partition-table-file", env.subst("$PARTITIONS_TABLE_CSV"),
            "get_partition_info", get_part_info_args, "--info", part_info,
        ]
    result = exec_command(cmd, env=idf_env)
    rc = result["returncode"]
  
    if rc != 0 and rc != 1:
        sys.stderr.write("parttool.py execution failed (${rc}), problem with partition CSV file (see above)")
        env.Exit(1)
    return result["out"]
github platformio / platformio-core / platformio / commands / check / tools / pvsstudio.py View on Github external
else os.path.join("bin", "plog-converter"),
        )

        cmd = (
            converter_tool,
            "-t",
            "xml",
            output_file,
            "-m",
            "cwe",
            "-m",
            "misra",
            "--cerr",
        )

        result = proc.exec_command(cmd)
        if result["returncode"] != 0:
            click.echo(result["err"])
            self._bad_input = True

        return result["err"]
github platformio / platformio-core / platformio / builder / tools / piomisc.py View on Github external
def _get_compiler_type(env):
    if env.subst("$CC").endswith("-gcc"):
        return "gcc"
    try:
        sysenv = environ.copy()
        sysenv['PATH'] = str(env['ENV']['PATH'])
        result = exec_command([env.subst("$CC"), "-v"], env=sysenv)
    except OSError:
        return None
    if result['returncode'] != 0:
        return None
    output = "".join([result['out'], result['err']]).lower()
    if "clang" in output and "LLVM" in output:
        return "clang"
    if "gcc" in output:
        return "gcc"
    return None
github platformio / platformio-core / platformio / managers / platform.py View on Github external
(1 if click._compat.isatty(sys.stdout) else 0))
        cmd += targets

        # encode and append variables
        for key, value in variables.items():
            cmd.append("%s=%s" % (key.upper(), self.encode_scons_arg(value)))

        def _write_and_flush(stream, data):
            try:
                stream.write(data)
                stream.flush()
            except IOError:
                pass

        copy_pythonpath_to_osenv()
        result = exec_command(
            cmd,
            stdout=BuildAsyncPipe(
                line_callback=self._on_stdout_line,
                data_callback=lambda data: _write_and_flush(sys.stdout, data)),
            stderr=BuildAsyncPipe(
                line_callback=self._on_stderr_line,
                data_callback=lambda data: _write_and_flush(sys.stderr, data)))
        return result
github platformio / platformio-core / platformio / commands / check / tools / base.py View on Github external
def check(self, on_defect_callback=None):
        self._on_defect_callback = on_defect_callback
        cmd = self.configure_command()
        if self.options.get("verbose"):
            click.echo(" ".join(cmd))

        proc.exec_command(
            cmd,
            stdout=proc.LineBufferedAsyncPipe(self.on_tool_output),
            stderr=proc.LineBufferedAsyncPipe(self.on_tool_output),
        )

        self.clean_up()

        return self._bad_input
github platformio / platformio-core / platformio / builder / tools / piosize.py View on Github external
def _run_tool(cmd, env, tool_args):
    sysenv = environ.copy()
    sysenv["PATH"] = str(env["ENV"]["PATH"])

    build_dir = env.subst("$BUILD_DIR")
    if not isdir(build_dir):
        makedirs(build_dir)
    tmp_file = join(build_dir, "size-data-longcmd.txt")

    with open(tmp_file, "w") as fp:
        fp.write("\n".join(tool_args))

    cmd.append("@" + tmp_file)
    result = exec_command(cmd, env=sysenv)
    remove(tmp_file)

    return result
github platformio / platformio-core / platformio / commands / check / tools / base.py View on Github external
def check(self, on_defect_callback=None):
        self._on_defect_callback = on_defect_callback
        cmd = self.configure_command()
        if self.options.get("verbose"):
            click.echo(" ".join(cmd))

        proc.exec_command(
            cmd,
            stdout=proc.LineBufferedAsyncPipe(self.on_tool_output),
            stderr=proc.LineBufferedAsyncPipe(self.on_tool_output),
        )

        self.clean_up()

        return self._bad_input