Пример #1
0
    def newPlatform(cls, name, requirements=None):
        pm = PlatformManager()
        platform_dir = None
        if isdir(name):
            platform_dir = name
            name = pm.load_manifest(platform_dir)["name"]
        elif name.endswith("platform.json") and isfile(name):
            platform_dir = dirname(name)
            name = fs.load_json(name)["name"]
        else:
            name, requirements, url = pm.parse_pkg_uri(name, requirements)
            platform_dir = pm.get_package_dir(name, requirements, url)
            if platform_dir:
                name = pm.load_manifest(platform_dir)["name"]

        if not platform_dir:
            raise exception.UnknownPlatform(
                name if not requirements else "%s@%s" % (name, requirements))

        platform_cls = None
        if isfile(join(platform_dir, "platform.py")):
            platform_cls = getattr(
                cls.load_module(name, join(platform_dir, "platform.py")),
                cls.get_clsname(name),
            )
        else:
            platform_cls = type(str(cls.get_clsname(name)), (PlatformBase, ),
                                {})

        _instance = platform_cls(join(platform_dir, "platform.json"))
        assert isinstance(_instance, PlatformBase)
        return _instance
Пример #2
0
    def __init__(self, manifest_path):
        self.manifest_path = manifest_path
        self.silent = False
        self.verbose = False

        self._manifest = fs.load_json(manifest_path)
        self._BOARDS_CACHE = {}
        self._custom_packages = None

        self.config = ProjectConfig.get_instance()
        self.pm = PackageManager(self.config.get_optional_dir("packages"),
                                 self.package_repositories)

        self._src_manifest = None
        src_manifest_path = self.pm.get_src_manifest_path(self.get_dir())
        if src_manifest_path:
            self._src_manifest = fs.load_json(src_manifest_path)
Пример #3
0
 def _update_src_manifest(self, data, src_dir):
     if not isdir(src_dir):
         os.makedirs(src_dir)
     src_manifest_path = join(src_dir, self.SRC_MANIFEST_NAME)
     _data = {}
     if isfile(src_manifest_path):
         _data = fs.load_json(src_manifest_path)
     _data.update(data)
     with open(src_manifest_path, "w") as fp:
         json.dump(_data, fp)
Пример #4
0
    def load_manifest(self, pkg_dir):
        cache_key = "load_manifest-%s" % pkg_dir
        result = self.cache_get(cache_key)
        if result:
            return result

        manifest = {}
        src_manifest = None
        manifest_path = self.get_manifest_path(pkg_dir)
        src_manifest_path = self.get_src_manifest_path(pkg_dir)
        if src_manifest_path:
            src_manifest = fs.load_json(src_manifest_path)

        if not manifest_path and not src_manifest_path:
            return None

        if manifest_path and manifest_path.endswith(".json"):
            manifest = fs.load_json(manifest_path)
        elif manifest_path and manifest_path.endswith(".properties"):
            with codecs.open(manifest_path, encoding="utf-8") as fp:
                for line in fp.readlines():
                    if "=" not in line:
                        continue
                    key, value = line.split("=", 1)
                    manifest[key.strip()] = value.strip()

        if src_manifest:
            if "version" in src_manifest:
                manifest['version'] = src_manifest['version']
            manifest['__src_url'] = src_manifest['url']
            # handle a custom package name
            autogen_name = self.parse_pkg_uri(manifest['__src_url'])[0]
            if "name" not in manifest or autogen_name != src_manifest['name']:
                manifest['name'] = src_manifest['name']

        if "name" not in manifest:
            manifest['name'] = basename(pkg_dir)
        if "version" not in manifest:
            manifest['version'] = "0.0.0"

        manifest['__pkg_dir'] = pkg_dir
        self.cache_set(cache_key, manifest)
        return manifest
Пример #5
0
 def __enter__(self):
     try:
         self._lock_state_file()
         if isfile(self.path):
             self._storage = fs.load_json(self.path)
         assert isinstance(self._storage, dict)
     except (AssertionError, ValueError, UnicodeDecodeError,
             exception.InvalidJSONFile):
         self._storage = {}
     return self
Пример #6
0
    def __init__(self, manifest_path):
        self.manifest_path = manifest_path
        self.silent = False
        self.verbose = False

        self._BOARDS_CACHE = {}
        self._manifest = fs.load_json(manifest_path)
        self._custom_packages = None

        self.pm = PackageManager(get_project_packages_dir(),
                                 self.package_repositories)
Пример #7
0
    def __init__(self, manifest_path):
        self.manifest_path = manifest_path
        self.silent = False
        self.verbose = False

        self._manifest = fs.load_json(manifest_path)
        self._BOARDS_CACHE = {}
        self._custom_packages = None

        self.config = ProjectConfig.get_instance()
        self.pm = ToolPackageManager(self.config.get_optional_dir("packages"))
Пример #8
0
 def __init__(self, manifest_path):
     self._id = basename(manifest_path)[:-5]
     assert isfile(manifest_path)
     self.manifest_path = manifest_path
     try:
         self._manifest = fs.load_json(manifest_path)
     except ValueError:
         raise exception.InvalidBoardManifest(manifest_path)
     if not set(["name", "url", "vendor"]) <= set(self._manifest):
         raise exception.PlatformioException(
             "Please specify name, url and vendor fields for " +
             manifest_path)
Пример #9
0
 def _get_plaform_data():
     data = ["PLATFORM: %s %s" % (platform.title, platform.version)]
     src_manifest_path = platform.pm.get_src_manifest_path(platform.get_dir())
     if src_manifest_path:
         src_manifest = fs.load_json(src_manifest_path)
         if "version" in src_manifest:
             data.append("#" + src_manifest["version"])
         if int(ARGUMENTS.get("PIOVERBOSE", 0)):
             data.append("(%s)" % src_manifest["url"])
     if board_config:
         data.extend([">", board_config.get("name")])
     return data
Пример #10
0
    def load_manifest(self):
        assert isfile(join(self.path, "library.json"))
        manifest = fs.load_json(join(self.path, "library.json"))
        assert "name" in manifest

        # replace "espressif" old name dev/platform with ESP8266
        if "platforms" in manifest:
            manifest['platforms'] = [
                "espressif8266" if p == "espressif" else p
                for p in util.items_to_list(manifest['platforms'])
            ]

        return manifest
Пример #11
0
    def _mbed_lib_conf_parse_macros(self, mbed_lib_path):
        macros = {}
        cppdefines = str(self.env.Flatten(self.env.subst("$CPPDEFINES")))
        manifest = fs.load_json(mbed_lib_path)

        # default macros
        for macro in manifest.get("macros", []):
            macro = self._mbed_normalize_macro(macro)
            macros[macro['name']] = macro

        # configuration items
        for key, options in manifest.get("config", {}).items():
            if "value" not in options:
                continue
            macros[key] = dict(name=options.get("macro_name"),
                               value=options.get("value"))

        # overrode items per target
        for target, options in manifest.get("target_overrides", {}).items():
            if target != "*" and "TARGET_" + target not in cppdefines:
                continue
            for macro in options.get("target.macros_add", []):
                macro = self._mbed_normalize_macro(macro)
                macros[macro['name']] = macro
            for key, value in options.items():
                if not key.startswith("target.") and key in macros:
                    macros[key]['value'] = value

        # normalize macro names
        for key, macro in macros.items():
            if not macro['name']:
                macro['name'] = key
                if "." not in macro['name']:
                    macro['name'] = "%s.%s" % (manifest.get("name"),
                                               macro['name'])
                macro['name'] = re.sub(r"[^a-z\d]+",
                                       "_",
                                       macro['name'],
                                       flags=re.I).upper()
                macro['name'] = "MBED_CONF_" + macro['name']
            if isinstance(macro['value'], bool):
                macro['value'] = 1 if macro['value'] else 0

        return {macro["name"]: macro["value"] for macro in macros.values()}
Пример #12
0
    def build_legacy_spec(self, pkg_dir):
        # find src manifest
        src_manifest_name = ".piopkgmanager.json"
        src_manifest_path = None
        for name in os.listdir(pkg_dir):
            if not os.path.isfile(os.path.join(pkg_dir, name, src_manifest_name)):
                continue
            src_manifest_path = os.path.join(pkg_dir, name, src_manifest_name)
            break

        if src_manifest_path:
            src_manifest = fs.load_json(src_manifest_path)
            return PackageSpec(
                name=src_manifest.get("name"),
                url=src_manifest.get("url"),
                requirements=src_manifest.get("requirements"),
            )

        # fall back to a package manifest
        manifest = self.load_manifest(pkg_dir)
        return PackageSpec(name=manifest.get("name"))
Пример #13
0
    def new(cls, pkg_or_spec):
        platform_dir = None
        platform_name = None
        if isinstance(pkg_or_spec, PackageItem):
            platform_dir = pkg_or_spec.path
            platform_name = pkg_or_spec.metadata.name
        elif os.path.isdir(pkg_or_spec):
            platform_dir = pkg_or_spec
        else:
            from platformio.package.manager.platform import (  # pylint: disable=import-outside-toplevel
                PlatformPackageManager, )

            pkg = PlatformPackageManager().get_package(pkg_or_spec)
            if not pkg:
                raise UnknownPlatform(pkg_or_spec)
            platform_dir = pkg.path
            platform_name = pkg.metadata.name

        if not platform_dir or not os.path.isfile(
                os.path.join(platform_dir, "platform.json")):
            raise UnknownPlatform(pkg_or_spec)

        if not platform_name:
            platform_name = fs.load_json(
                os.path.join(platform_dir, "platform.json"))["name"]

        platform_cls = None
        if os.path.isfile(os.path.join(platform_dir, "platform.py")):
            platform_cls = getattr(
                cls.load_module(platform_name,
                                os.path.join(platform_dir, "platform.py")),
                cls.get_clsname(platform_name),
            )
        else:
            platform_cls = type(str(cls.get_clsname(platform_name)),
                                (PlatformBase, ), {})

        _instance = platform_cls(os.path.join(platform_dir, "platform.json"))
        assert isinstance(_instance, PlatformBase)
        return _instance
Пример #14
0
    def load_manifest(self, pkg_dir):  # pylint: disable=too-many-branches
        cache_key = "load_manifest-%s" % pkg_dir
        result = self.cache_get(cache_key)
        if result:
            return result

        manifest = {}
        src_manifest = None
        manifest_path = self.get_manifest_path(pkg_dir)
        src_manifest_path = self.get_src_manifest_path(pkg_dir)
        if src_manifest_path:
            src_manifest = fs.load_json(src_manifest_path)

        if not manifest_path and not src_manifest_path:
            return None

        try:
            manifest = ManifestParserFactory.new_from_file(
                manifest_path).as_dict()
        except ManifestException:
            pass

        if src_manifest:
            if "version" in src_manifest:
                manifest["version"] = src_manifest["version"]
            manifest["__src_url"] = src_manifest["url"]
            # handle a custom package name
            autogen_name = self.parse_pkg_uri(manifest["__src_url"])[0]
            if "name" not in manifest or autogen_name != src_manifest["name"]:
                manifest["name"] = src_manifest["name"]

        if "name" not in manifest:
            manifest["name"] = basename(pkg_dir)
        if "version" not in manifest:
            manifest["version"] = "0.0.0"

        manifest["__pkg_dir"] = realpath(pkg_dir)
        self.cache_set(cache_key, manifest)
        return manifest
Пример #15
0
 def _get_vcs_info(lb):
     path = LibraryManager.get_src_manifest_path(lb.path)
     return fs.load_json(path) if path else None
Пример #16
0
         MCU_FAMILY.upper() + "xx", "Include"),
    join(FRAMEWORK_DIR, FRAMEWORK_CORE, "Drivers",
         MCU_FAMILY.upper() + "xx_HAL_Driver", "Inc"),
    join(FRAMEWORK_DIR, FRAMEWORK_CORE, "Drivers", "BSP", "Components",
         "Common")
],
           LIBPATH=[
               join(FRAMEWORK_DIR, FRAMEWORK_CORE, "Drivers", "CMSIS", "Lib",
                    "GCC"),
               join(FRAMEWORK_DIR, "platformio", "ldscripts")
           ])

if not board.get("build.ldscript", ""):
    env.Replace(LDSCRIPT_PATH=get_linker_script(board.get("build.mcu")))

variants_remap = fs.load_json(
    join(FRAMEWORK_DIR, "platformio", "variants_remap.json"))
board_type = env.subst("$BOARD")
variant = variants_remap[
    board_type] if board_type in variants_remap else board_type.upper()

#
# Generate framework specific files
#

generate_hal_config_file(board.get("build.mcu"))

#
# Process BSP components
#

components_dir = join(FRAMEWORK_DIR, FRAMEWORK_CORE, "Drivers", "BSP",
Пример #17
0
 def load_manifest(self):
     if not isfile(join(self.path, "module.json")):
         return {}
     return fs.load_json(join(self.path, "module.json"))