示例#1
0
def DumpIDEData(env, globalenv):
    """ env here is `projenv`"""

    env["__escape_build_flag"] = _escape_build_flag

    LINTCCOM = (
        "${__escape_build_flag(CFLAGS)} ${__escape_build_flag(CCFLAGS)} $CPPFLAGS"
    )
    LINTCXXCOM = (
        "${__escape_build_flag(CXXFLAGS)} ${__escape_build_flag(CCFLAGS)} $CPPFLAGS"
    )

    data = {
        "env_name":
        env["PIOENV"],
        "libsource_dirs": [env.subst(l) for l in env.GetLibSourceDirs()],
        "defines":
        _dump_defines(env),
        "includes":
        _dump_includes(env),
        "cc_path":
        where_is_program(env.subst("$CC"), env.subst("${ENV['PATH']}")),
        "cxx_path":
        where_is_program(env.subst("$CXX"), env.subst("${ENV['PATH']}")),
        "gdb_path":
        where_is_program(env.subst("$GDB"), env.subst("${ENV['PATH']}")),
        "prog_path":
        env.subst("$PROG_PATH"),
        "svd_path":
        _get_svd_path(env),
        "compiler_type":
        env.GetCompilerType(),
        "targets":
        globalenv.DumpTargets(),
        "extra":
        dict(flash_images=[{
            "offset": item[0],
            "path": env.subst(item[1])
        } for item in env.get("FLASH_EXTRA_IMAGES", [])]),
    }
    data["extra"].update(env.get("IDE_EXTRA_DATA", {}))

    env_ = env.Clone()
    # https://github.com/platformio/platformio-atom-ide/issues/34
    _new_defines = []
    for item in processDefines(env_.get("CPPDEFINES", [])):
        item = item.replace('\\"', '"')
        if " " in item:
            _new_defines.append(item.replace(" ", "\\\\ "))
        else:
            _new_defines.append(item)
    env_.Replace(CPPDEFINES=_new_defines)

    data.update({
        "cc_flags": env_.subst(LINTCCOM),
        "cxx_flags": env_.subst(LINTCXXCOM)
    })

    return data
示例#2
0
def DumpIDEData(env):
    LINTCCOM = "$CFLAGS $CCFLAGS $CPPFLAGS"
    LINTCXXCOM = "$CXXFLAGS $CCFLAGS $CPPFLAGS"

    data = {
        "env_name":
        env["PIOENV"],
        "libsource_dirs": [env.subst(l) for l in env.GetLibSourceDirs()],
        "defines":
        _dump_defines(env),
        "includes":
        _dump_includes(env),
        "cc_flags":
        env.subst(LINTCCOM),
        "cxx_flags":
        env.subst(LINTCXXCOM),
        "cc_path":
        where_is_program(env.subst("$CC"), env.subst("${ENV['PATH']}")),
        "cxx_path":
        where_is_program(env.subst("$CXX"), env.subst("${ENV['PATH']}")),
        "gdb_path":
        where_is_program(env.subst("$GDB"), env.subst("${ENV['PATH']}")),
        "prog_path":
        env.subst("$PROG_PATH"),
        "flash_extra_images": [{
            "offset": item[0],
            "path": env.subst(item[1])
        } for item in env.get("FLASH_EXTRA_IMAGES", [])],
        "svd_path":
        _get_svd_path(env),
        "compiler_type":
        env.GetCompilerType(),
    }

    env_ = env.Clone()
    # https://github.com/platformio/platformio-atom-ide/issues/34
    _new_defines = []
    for item in processDefines(env_.get("CPPDEFINES", [])):
        item = item.replace('\\"', '"')
        if " " in item:
            _new_defines.append(item.replace(" ", "\\\\ "))
        else:
            _new_defines.append(item)
    env_.Replace(CPPDEFINES=_new_defines)

    data.update({
        "cc_flags": env_.subst(LINTCCOM),
        "cxx_flags": env_.subst(LINTCXXCOM)
    })

    return data
示例#3
0
    def _load_tplvars(self):
        tpl_vars = {"env_name": self.env_name}
        # default env configuration
        tpl_vars.update(
            ProjectConfig.get_instance(join(
                self.project_dir, "platformio.ini")).items(env=self.env_name,
                                                           as_dict=True))
        # build data
        tpl_vars.update(
            load_project_ide_data(self.project_dir, self.env_name) or {})

        with util.cd(self.project_dir):
            tpl_vars.update({
                "project_name": basename(self.project_dir),
                "src_files": self.get_src_files(),
                "user_home_dir": abspath(expanduser("~")),
                "project_dir": self.project_dir,
                "project_src_dir": get_project_src_dir(),
                "project_lib_dir": get_project_lib_dir(),
                "project_libdeps_dir": join(
                    get_project_libdeps_dir(), self.env_name),
                "systype": util.get_systype(),
                "platformio_path": self._fix_os_path(
                    sys.argv[0] if isfile(sys.argv[0])
                    else where_is_program("platformio")),
                "env_pathsep": os.pathsep,
                "env_path": self._fix_os_path(os.getenv("PATH"))
            })  # yapf: disable
        return tpl_vars
示例#4
0
def prepare_ulp_env_vars(env):
    ulp_env.PrependENVPath("IDF_PATH", FRAMEWORK_DIR)

    additional_packages = [
        os.path.join(
            platform.get_package_dir(
                "toolchain-xtensa-esp%s"
                % ("32s2" if idf_variant == "esp32s2" else "32")
            ),
            "bin",
        ),
        os.path.join(
            platform.get_package_dir("toolchain-%sulp" % idf_variant),
            "bin",
        ),
        platform.get_package_dir("tool-ninja"),
        os.path.join(platform.get_package_dir("tool-cmake"), "bin"),
        os.path.dirname(where_is_program("python")),
    ]

    if "windows" in get_systype():
        additional_packages.append(platform.get_package_dir("tool-mconf"))

    for package in additional_packages:
        ulp_env.PrependENVPath("PATH", package)
示例#5
0
 def _process_cmd_update(self, options):
     cmd_args = ["platformio", "--force", "update"]
     if options.get("only_check"):
         cmd_args.append("--only-check")
     return self._defer_async_cmd(
         ProcessAsyncCmd({
             "executable": proc.where_is_program("platformio"),
             "args": cmd_args
         }))
示例#6
0
def system_info(json_output):
    project_config = ProjectConfig()
    data = {}
    data["core_version"] = {"title": "PlatformIO Core", "value": __version__}
    data["python_version"] = {
        "title": "Python",
        "value": "{0}.{1}.{2}-{3}.{4}".format(*list(sys.version_info)),
    }
    data["system"] = {"title": "System Type", "value": util.get_systype()}
    data["platform"] = {
        "title": "Platform",
        "value": platform.platform(terse=True)
    }
    data["filesystem_encoding"] = {
        "title": "File System Encoding",
        "value": compat.get_filesystem_encoding(),
    }
    data["locale_encoding"] = {
        "title": "Locale Encoding",
        "value": compat.get_locale_encoding(),
    }
    data["core_dir"] = {
        "title": "PlatformIO Core Directory",
        "value": project_config.get_optional_dir("core"),
    }
    data["platformio_exe"] = {
        "title":
        "PlatformIO Core Executable",
        "value":
        proc.where_is_program(
            "platformio.exe" if proc.WINDOWS else "platformio"),
    }
    data["python_exe"] = {
        "title": "Python Executable",
        "value": proc.get_pythonexe_path(),
    }
    data["global_lib_nums"] = {
        "title": "Global Libraries",
        "value": len(LibraryPackageManager().get_installed()),
    }
    data["dev_platform_nums"] = {
        "title": "Development Platforms",
        "value": len(PlatformPackageManager().get_installed()),
    }
    data["package_tool_nums"] = {
        "title":
        "Tools & Toolchains",
        "value":
        len(
            ToolPackageManager(
                project_config.get_optional_dir("packages")).get_installed()),
    }

    click.echo(
        json.dumps(data) if json_output else tabulate([(
            item["title"], item["value"]) for item in data.values()]))
    def _load_tplvars(self):
        tpl_vars = {
            "config":
            self.config,
            "systype":
            util.get_systype(),
            "project_name":
            basename(self.project_dir),
            "project_dir":
            self.project_dir,
            "env_name":
            self.env_name,
            "user_home_dir":
            realpath(fs.expanduser("~")),
            "platformio_path":
            sys.argv[0]
            if isfile(sys.argv[0]) else where_is_program("platformio"),
            "env_path":
            os.getenv("PATH"),
            "env_pathsep":
            os.pathsep,
        }

        # default env configuration
        tpl_vars.update(self.config.items(env=self.env_name, as_dict=True))
        # build data
        tpl_vars.update(
            load_project_ide_data(self.project_dir, self.env_name) or {})

        with fs.cd(self.project_dir):
            tpl_vars.update({
                "src_files":
                self.get_src_files(),
                "project_src_dir":
                self.config.get_optional_dir("src"),
                "project_lib_dir":
                self.config.get_optional_dir("lib"),
                "project_libdeps_dir":
                join(self.config.get_optional_dir("libdeps"), self.env_name),
            })

        for key, value in tpl_vars.items():
            if key.endswith(("_path", "_dir")):
                tpl_vars[key] = fs.to_unix_path(value)
        for key in ("src_files", "libsource_dirs"):
            if key not in tpl_vars:
                continue
            tpl_vars[key] = [fs.to_unix_path(inc) for inc in tpl_vars[key]]

        tpl_vars["to_unix_path"] = fs.to_unix_path
        tpl_vars["filter_includes"] = self.filter_includes
        return tpl_vars
示例#8
0
    def CompilationDatabase(env, target):
        # Resolve absolute path of toolchain
        for cmd in ("CC", "CXX", "AS"):
            if cmd not in env:
                continue
            env[cmd] = where_is_program(env.subst("$%s" % cmd),
                                        env.subst("${ENV['PATH']}"))

        result = env.__COMPILATIONDB_Database(target=target, source=[])

        env.AlwaysBuild(result)
        env.NoCache(result)

        return result
def populate_idf_env_vars(idf_env):
    idf_env["IDF_PATH"] = platform.get_package_dir("framework-espidf")

    additional_packages = [
        join(platform.get_package_dir("toolchain-xtensa32"), "bin"),
        join(platform.get_package_dir("toolchain-esp32ulp"), "bin"),
        platform.get_package_dir("tool-ninja"),
        join(platform.get_package_dir("tool-cmake"), "bin"),
        dirname(where_is_program("python")),
    ]

    if "windows" in get_systype():
        additional_packages.append(platform.get_package_dir("tool-mconf"))

    idf_env["PATH"] = pathsep.join(additional_packages + [idf_env["PATH"]])
示例#10
0
def prepare_ulp_env_vars(env):
    ulp_env.PrependENVPath("IDF_PATH",
                           platform.get_package_dir("framework-espidf"))

    additional_packages = [
        os.path.join(platform.get_package_dir("toolchain-xtensa32"), "bin"),
        os.path.join(platform.get_package_dir("toolchain-esp32ulp"), "bin"),
        platform.get_package_dir("tool-ninja"),
        os.path.join(platform.get_package_dir("tool-cmake"), "bin"),
        os.path.dirname(where_is_program("python")),
    ]

    if "windows" in get_systype():
        additional_packages.append(platform.get_package_dir("tool-mconf"))

    for package in additional_packages:
        ulp_env.PrependENVPath("PATH", package)
示例#11
0
    def EmitCompilationDbEntry(target, source, env):
        """
        This emitter will be added to each c/c++ object build to capture the info needed
        for clang tools
        :param target: target node(s)
        :param source: source node(s)
        :param env: Environment for use building this node
        :return: target(s), source(s)
        """

        # Resolve absolute path of toolchain
        for cmd in ("CC", "CXX", "AS"):
            if cmd not in env:
                continue
            if os.path.isabs(env[cmd]):
                continue
            env[cmd] = where_is_program(
                env.subst("$%s" % cmd), env.subst("${ENV['PATH']}")
            )

        dbtarget = __CompilationDbNode(source)

        entry = env.__COMPILATIONDB_Entry(
            target=dbtarget,
            source=[],
            __COMPILATIONDB_UTARGET=target,
            __COMPILATIONDB_USOURCE=source,
            __COMPILATIONDB_UACTION=user_action,
            __COMPILATIONDB_ENV=env,
        )

        # Technically, these next two lines should not be required: it should be fine to
        # cache the entries. However, they don't seem to update properly. Since they are quick
        # to re-generate disable caching and sidestep this problem.
        env.AlwaysBuild(entry)
        env.NoCache(entry)

        __COMPILATION_DB_ENTRIES.append(dbtarget)

        return target, source
示例#12
0
    def _process_cmd_run_or_test(  # pylint: disable=too-many-locals,too-many-branches
            self, command, options):
        assert options and "project_id" in options
        project_dir = join(self.working_dir, "projects", options["project_id"])
        origin_pio_ini = join(project_dir, "platformio.ini")
        back_pio_ini = join(project_dir, "platformio.ini.bak")

        # remove insecure project options
        try:
            conf = ProjectConfig(origin_pio_ini)
            if isfile(back_pio_ini):
                os.remove(back_pio_ini)
            os.rename(origin_pio_ini, back_pio_ini)
            # cleanup
            if conf.has_section("platformio"):
                for opt in conf.options("platformio"):
                    if opt.endswith("_dir"):
                        conf.remove_option("platformio", opt)
            else:
                conf.add_section("platformio")
            conf.set("platformio", "build_dir", ".pio/build")
            conf.save(origin_pio_ini)

            # restore A/M times
            os.utime(origin_pio_ini,
                     (getatime(back_pio_ini), getmtime(back_pio_ini)))
        except NotPlatformIOProjectError as e:
            raise pb.Error(str(e))

        cmd_args = ["platformio", "--force", command, "-d", project_dir]
        for env in options.get("environment", []):
            cmd_args.extend(["-e", env])
        for target in options.get("target", []):
            cmd_args.extend(["-t", target])
        for ignore in options.get("ignore", []):
            cmd_args.extend(["-i", ignore])
        if options.get("upload_port", False):
            cmd_args.extend(["--upload-port", options.get("upload_port")])
        if options.get("test_port", False):
            cmd_args.extend(["--test-port", options.get("test_port")])
        if options.get("disable_auto_clean", False):
            cmd_args.append("--disable-auto-clean")
        if options.get("without_building", False):
            cmd_args.append("--without-building")
        if options.get("without_uploading", False):
            cmd_args.append("--without-uploading")
        if options.get("silent", False):
            cmd_args.append("-s")
        if options.get("verbose", False):
            cmd_args.append("-v")

        paused_acs = []
        for ac in self._acs.values():
            if not isinstance(ac, SerialPortAsyncCmd):
                continue
            self.log.info("Pause active monitor at {port}",
                          port=ac.options["port"])
            ac.pause()
            paused_acs.append(ac)

        def _cb_on_end():
            if isfile(back_pio_ini):
                if isfile(origin_pio_ini):
                    os.remove(origin_pio_ini)
                os.rename(back_pio_ini, origin_pio_ini)
            for ac in paused_acs:
                ac.unpause()
                self.log.info("Unpause active monitor at {port}",
                              port=ac.options["port"])

        return self._defer_async_cmd(
            ProcessAsyncCmd(
                {
                    "executable": proc.where_is_program("platformio"),
                    "args": cmd_args
                },
                on_end_callback=_cb_on_end,
            ))
示例#13
0
    def spawn(self, patterns):  # pylint: disable=too-many-branches
        systype = util.get_systype()
        server = self.debug_options.get("server")
        if not server:
            return None
        server = self.apply_patterns(server, patterns)
        server_executable = server['executable']
        if not server_executable:
            return None
        if server['cwd']:
            server_executable = join(server['cwd'], server_executable)
        if ("windows" in systype and not server_executable.endswith(".exe")
                and isfile(server_executable + ".exe")):
            server_executable = server_executable + ".exe"

        if not isfile(server_executable):
            server_executable = where_is_program(server_executable)
        if not isfile(server_executable):
            raise exception.DebugInvalidOptions(
                "\nCould not launch Debug Server '%s'. Please check that it "
                "is installed and is included in a system PATH\n\n"
                "See documentation or contact [email protected]:\n"
                "http://docs.platformio.org/page/plus/debugging.html\n" %
                server_executable)

        self._debug_port = ":3333"
        openocd_pipe_allowed = all([
            not self.debug_options['port'],
            "openocd" in server_executable
        ])  # yapf: disable
        if openocd_pipe_allowed:
            args = []
            if server['cwd']:
                args.extend(["-s", server['cwd']])
            args.extend([
                "-c", "gdb_port pipe; tcl_port disabled; telnet_port disabled"
            ])
            args.extend(server['arguments'])
            str_args = " ".join(
                [arg if arg.startswith("-") else '"%s"' % arg for arg in args])
            self._debug_port = '| "%s" %s' % (server_executable, str_args)
            self._debug_port = self._debug_port.replace("\\", "\\\\")
        else:
            env = os.environ.copy()
            # prepend server "lib" folder to LD path
            if ("windows" not in systype and server['cwd']
                    and isdir(join(server['cwd'], "lib"))):
                ld_key = ("DYLD_LIBRARY_PATH"
                          if "darwin" in systype else "LD_LIBRARY_PATH")
                env[ld_key] = join(server['cwd'], "lib")
                if os.environ.get(ld_key):
                    env[ld_key] = "%s:%s" % (env[ld_key],
                                             os.environ.get(ld_key))
            # prepend BIN to PATH
            if server['cwd'] and isdir(join(server['cwd'], "bin")):
                env['PATH'] = "%s%s%s" % (
                    join(server['cwd'], "bin"), os.pathsep,
                    os.environ.get("PATH", os.environ.get("Path", "")))

            self._transport = reactor.spawnProcess(
                self,
                server_executable, [server_executable] + server['arguments'],
                path=server['cwd'],
                env=env)
            if "mspdebug" in server_executable.lower():
                self._debug_port = ":2000"
            elif "jlink" in server_executable.lower():
                self._debug_port = ":2331"
            elif "qemu" in server_executable.lower():
                self._debug_port = ":1234"

        return self._transport
示例#14
0
 def _tx_target(sock_dir):
     subcmd_argv = ["remote", "device", "monitor"]
     subcmd_argv.extend(device_helpers.options_to_argv(kwargs, project_options))
     subcmd_argv.extend(["--sock", sock_dir])
     subprocess.call([proc.where_is_program("platformio")] + subcmd_argv)
示例#15
0
def get_core_fullpath():
    return where_is_program(
        "platformio" + (".exe" if "windows" in util.get_systype() else "")
    )