Skip to content

Commit

Permalink
Switch legacy platform manager to the new
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Aug 15, 2020
1 parent bb6fb3f commit 04694b4
Show file tree
Hide file tree
Showing 25 changed files with 471 additions and 1,272 deletions.
6 changes: 3 additions & 3 deletions platformio/builder/tools/pioide.py
Expand Up @@ -45,10 +45,10 @@ def _dump_includes(env):
# includes from toolchains
p = env.PioPlatform()
includes["toolchain"] = []
for name in p.get_installed_packages():
if p.get_package_type(name) != "toolchain":
for pkg in p.get_installed_packages():
if p.get_package_type(pkg.metadata.name) != "toolchain":
continue
toolchain_dir = glob_escape(p.get_package_dir(name))
toolchain_dir = glob_escape(pkg.path)
toolchain_incglobs = [
os.path.join(toolchain_dir, "*", "include", "c++", "*"),
os.path.join(toolchain_dir, "*", "include", "c++", "*", "*-*-*"),
Expand Down
29 changes: 15 additions & 14 deletions platformio/builder/tools/pioplatform.py
Expand Up @@ -22,6 +22,7 @@

from platformio import fs, util
from platformio.compat import WINDOWS
from platformio.package.meta import PackageItem
from platformio.platform.exception import UnknownBoard
from platformio.platform.factory import PlatformFactory
from platformio.project.config import ProjectOptions
Expand Down Expand Up @@ -63,32 +64,30 @@ def GetFrameworkScript(env, framework):

def LoadPioPlatform(env):
p = env.PioPlatform()
installed_packages = p.get_installed_packages()

# Ensure real platform name
env["PIOPLATFORM"] = p.name

# Add toolchains and uploaders to $PATH and $*_LIBRARY_PATH
systype = util.get_systype()
for name in installed_packages:
type_ = p.get_package_type(name)
for pkg in p.get_installed_packages():
type_ = p.get_package_type(pkg.metadata.name)
if type_ not in ("toolchain", "uploader", "debugger"):
continue
pkg_dir = p.get_package_dir(name)
env.PrependENVPath(
"PATH",
os.path.join(pkg_dir, "bin")
if os.path.isdir(os.path.join(pkg_dir, "bin"))
else pkg_dir,
os.path.join(pkg.path, "bin")
if os.path.isdir(os.path.join(pkg.path, "bin"))
else pkg.path,
)
if (
not WINDOWS
and os.path.isdir(os.path.join(pkg_dir, "lib"))
and os.path.isdir(os.path.join(pkg.path, "lib"))
and type_ != "toolchain"
):
env.PrependENVPath(
"DYLD_LIBRARY_PATH" if "darwin" in systype else "LD_LIBRARY_PATH",
os.path.join(pkg_dir, "lib"),
os.path.join(pkg.path, "lib"),
)

# Platform specific LD Scripts
Expand Down Expand Up @@ -133,6 +132,7 @@ def LoadPioPlatform(env):

def PrintConfiguration(env): # pylint: disable=too-many-statements
platform = env.PioPlatform()
pkg_metadata = PackageItem(platform.get_dir()).metadata
board_config = env.BoardConfig() if "BOARD" in env else None

def _get_configuration_data():
Expand All @@ -147,11 +147,12 @@ def _get_configuration_data():
)

def _get_plaform_data():
data = ["PLATFORM: %s (%s)" % (platform.title, platform.version)]
if platform.src_version:
data.append("#" + platform.src_version)
if int(ARGUMENTS.get("PIOVERBOSE", 0)) and platform.src_url:
data.append("(%s)" % platform.src_url)
data = [
"PLATFORM: %s (%s)"
% (platform.title, pkg_metadata.version or platform.version)
]
if int(ARGUMENTS.get("PIOVERBOSE", 0)) and pkg_metadata.spec.external:
data.append("(%s)" % pkg_metadata.spec.url)
if board_config:
data.extend([">", board_config.get("name")])
return data
Expand Down
4 changes: 2 additions & 2 deletions platformio/commands/boards.py
Expand Up @@ -19,7 +19,7 @@

from platformio import fs
from platformio.compat import dump_json_to_unicode
from platformio.managers.platform import PlatformManager
from platformio.package.manager.platform import PlatformPackageManager


@click.command("boards", short_help="Embedded Board Explorer")
Expand Down Expand Up @@ -71,7 +71,7 @@ def print_boards(boards):


def _get_boards(installed=False):
pm = PlatformManager()
pm = PlatformPackageManager()
return pm.get_installed_boards() if installed else pm.get_all_boards()


Expand Down
10 changes: 6 additions & 4 deletions platformio/commands/home/rpc/handlers/project.py
Expand Up @@ -25,7 +25,7 @@
from platformio.commands.home.rpc.handlers.piocore import PIOCoreRPC
from platformio.compat import PY2, get_filesystem_encoding
from platformio.ide.projectgenerator import ProjectGenerator
from platformio.managers.platform import PlatformManager
from platformio.package.manager.platform import PlatformPackageManager
from platformio.project.config import ProjectConfig
from platformio.project.exception import ProjectError
from platformio.project.helpers import get_project_dir, is_platformio_project
Expand Down Expand Up @@ -105,7 +105,7 @@ def _path_to_name(path):
return (os.path.sep).join(path.split(os.path.sep)[-2:])

result = []
pm = PlatformManager()
pm = PlatformPackageManager()
for project_dir in AppRPC.load_state()["storage"]["recentProjects"]:
if not os.path.isdir(project_dir):
continue
Expand Down Expand Up @@ -148,8 +148,9 @@ def _path_to_name(path):
@staticmethod
def get_project_examples():
result = []
for manifest in PlatformManager().get_installed():
examples_dir = os.path.join(manifest["__pkg_dir"], "examples")
pm = PlatformPackageManager()
for pkg in pm.get_installed():
examples_dir = os.path.join(pkg.path, "examples")
if not os.path.isdir(examples_dir):
continue
items = []
Expand All @@ -172,6 +173,7 @@ def get_project_examples():
"description": project_description,
}
)
manifest = pm.load_manifest(pkg)
result.append(
{
"platform": {
Expand Down
8 changes: 4 additions & 4 deletions platformio/commands/lib/helpers.py
Expand Up @@ -15,7 +15,7 @@
import os

from platformio.compat import ci_strings_are_equal
from platformio.managers.platform import PlatformManager
from platformio.package.manager.platform import PlatformPackageManager
from platformio.package.meta import PackageSpec
from platformio.platform.factory import PlatformFactory
from platformio.project.config import ProjectConfig
Expand All @@ -28,9 +28,9 @@ def get_builtin_libs(storage_names=None):

items = []
storage_names = storage_names or []
pm = PlatformManager()
for manifest in pm.get_installed():
p = PlatformFactory.new(manifest["__pkg_dir"])
pm = PlatformPackageManager()
for pkg in pm.get_installed():
p = PlatformFactory.new(pkg)
for storage in p.get_lib_storages():
if storage_names and storage["name"] not in storage_names:
continue
Expand Down

0 comments on commit 04694b4

Please sign in to comment.