def get_src_files(self):
     result = []
     with fs.cd(self.project_dir):
         for root, _, files in os.walk(get_project_src_dir()):
             for f in files:
                 result.append(relpath(join(root, f)))
     return result
Beispiel #2
0
 def _finalize_arduino_import(_, project_dir, arduino_project_dir):
     with util.cd(project_dir):
         src_dir = get_project_src_dir()
         if isdir(src_dir):
             util.rmtree_(src_dir)
         shutil.copytree(arduino_project_dir, src_dir)
     return project_dir
Beispiel #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
Beispiel #4
0
def init_base_project(project_dir):
    ProjectConfig(join(project_dir, "platformio.ini")).save()
    with fs.cd(project_dir):
        dir_to_readme = [
            (get_project_src_dir(), None),
            (get_project_include_dir(), init_include_readme),
            (get_project_lib_dir(), init_lib_readme),
            (get_project_test_dir(), init_test_readme),
        ]
        for (path, cb) in dir_to_readme:
            if isdir(path):
                continue
            makedirs(path)
            if cb:
                cb(path)
Beispiel #5
0
 def _generate_project_main(_, project_dir, framework):
     main_content = None
     if framework == "arduino":
         main_content = "\n".join([
             "#include <Arduino.h>",
             "",
             "void setup() {",
             "  // put your setup code here, to run once:",
             "}",
             "",
             "void loop() {",
             "  // put your main code here, to run repeatedly:",
             "}"
             ""
         ])   # yapf: disable
     elif framework == "mbed":
         main_content = "\n".join([
             "#include <mbed.h>",
             "",
             "int main() {",
             "",
             "  // put your setup code here, to run once:",
             "",
             "  while(1) {",
             "    // put your main code here, to run repeatedly:",
             "  }",
             "}",
             ""
         ])   # yapf: disable
     if not main_content:
         return project_dir
     with util.cd(project_dir):
         src_dir = get_project_src_dir()
         main_path = join(src_dir, "main.cpp")
         if isfile(main_path):
             return project_dir
         if not isdir(src_dir):
             os.makedirs(src_dir)
         with open(main_path, "w") as f:
             f.write(main_content.strip())
     return project_dir
    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": abspath(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
        }   # yapf: disable

        # 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": get_project_src_dir(),
                "project_lib_dir": get_project_lib_dir(),
                "project_libdeps_dir": join(
                    get_project_libdeps_dir(), self.env_name)

            })  # yapf: disable

        for key, value in tpl_vars.items():
            if key.endswith(("_path", "_dir")):
                tpl_vars[key] = fs.to_unix_path(value)
        for key in ("includes", "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
        return tpl_vars
Beispiel #7
0
        "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=[
        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"),