forked from platformio/platformio-core
Improve support for 3-rd party platforms
This commit is contained in:
@ -11,7 +11,7 @@ def cli():
|
|||||||
|
|
||||||
installed_platforms = PlatformFactory.get_platforms(
|
installed_platforms = PlatformFactory.get_platforms(
|
||||||
installed=True).keys()
|
installed=True).keys()
|
||||||
sorted(installed_platforms)
|
installed_platforms = sorted(installed_platforms)
|
||||||
|
|
||||||
for platform in installed_platforms:
|
for platform in installed_platforms:
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory().newPlatform(platform)
|
||||||
|
@ -11,7 +11,7 @@ def cli():
|
|||||||
|
|
||||||
installed_platforms = PlatformFactory.get_platforms(
|
installed_platforms = PlatformFactory.get_platforms(
|
||||||
installed=True).keys()
|
installed=True).keys()
|
||||||
sorted(installed_platforms)
|
installed_platforms = sorted(installed_platforms)
|
||||||
|
|
||||||
for platform in installed_platforms:
|
for platform in installed_platforms:
|
||||||
echo("\nPlatform %s" % style(platform, fg="cyan"))
|
echo("\nPlatform %s" % style(platform, fg="cyan"))
|
||||||
|
@ -28,9 +28,6 @@ class AtmelavrPlatform(BasePlatform):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return "atmelavr"
|
|
||||||
|
|
||||||
def after_run(self, result):
|
def after_run(self, result):
|
||||||
# fix STDERR "flash written" for avrdude
|
# fix STDERR "flash written" for avrdude
|
||||||
if "flash written" in result['err']:
|
if "flash written" in result['err']:
|
||||||
|
@ -8,18 +8,35 @@ from os.path import isfile, join
|
|||||||
from platformio.exception import (BuildScriptNotFound, PlatformNotInstalledYet,
|
from platformio.exception import (BuildScriptNotFound, PlatformNotInstalledYet,
|
||||||
UnknownPackage, UnknownPlatform)
|
UnknownPackage, UnknownPlatform)
|
||||||
from platformio.pkgmanager import PackageManager
|
from platformio.pkgmanager import PackageManager
|
||||||
from platformio.util import AppState, exec_command, get_source_dir
|
from platformio.util import (AppState, exec_command, get_home_dir,
|
||||||
|
get_source_dir)
|
||||||
|
|
||||||
|
|
||||||
class PlatformFactory(object):
|
class PlatformFactory(object):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_clsname(name):
|
||||||
|
return "%sPlatform" % name.title()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_platforms(installed=False):
|
def get_platforms(installed=False):
|
||||||
platforms = {}
|
platforms = {}
|
||||||
for p in listdir(join(get_source_dir(), "platforms")):
|
for d in (get_home_dir(), get_source_dir()):
|
||||||
|
pdir = join(d, "platforms")
|
||||||
|
for p in listdir(pdir):
|
||||||
if p in ("__init__.py", "base.py") or not p.endswith(".py"):
|
if p in ("__init__.py", "base.py") or not p.endswith(".py"):
|
||||||
continue
|
continue
|
||||||
platforms[p[:-3]] = join(get_source_dir(), "platforms", p)
|
name = p[:-3]
|
||||||
|
path = join(pdir, p)
|
||||||
|
try:
|
||||||
|
isplatform = hasattr(
|
||||||
|
PlatformFactory.load_module(name, path),
|
||||||
|
PlatformFactory.get_clsname(name)
|
||||||
|
)
|
||||||
|
if isplatform:
|
||||||
|
platforms[name] = path
|
||||||
|
except UnknownPlatform:
|
||||||
|
pass
|
||||||
|
|
||||||
if not installed:
|
if not installed:
|
||||||
return platforms
|
return platforms
|
||||||
@ -31,20 +48,28 @@ class PlatformFactory(object):
|
|||||||
installed_platforms[name] = platforms[name]
|
installed_platforms[name] = platforms[name]
|
||||||
return installed_platforms
|
return installed_platforms
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load_module(name, path):
|
||||||
|
module = None
|
||||||
|
try:
|
||||||
|
module = load_source(
|
||||||
|
"platformio.platforms.%s" % name, path)
|
||||||
|
except ImportError:
|
||||||
|
raise UnknownPlatform(name)
|
||||||
|
return module
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def newPlatform(name):
|
def newPlatform(name):
|
||||||
platforms = PlatformFactory.get_platforms()
|
platforms = PlatformFactory.get_platforms()
|
||||||
clsname = "%sPlatform" % name.title()
|
if name not in platforms:
|
||||||
try:
|
|
||||||
assert name in platforms
|
|
||||||
mod = load_source(
|
|
||||||
"platformio.platforms.%s" % name, platforms[name])
|
|
||||||
except (AssertionError, ImportError):
|
|
||||||
raise UnknownPlatform(name)
|
raise UnknownPlatform(name)
|
||||||
|
|
||||||
obj = getattr(mod, clsname)()
|
_instance = getattr(
|
||||||
assert isinstance(obj, BasePlatform)
|
PlatformFactory.load_module(name, platforms[name]),
|
||||||
return obj
|
PlatformFactory.get_clsname(name)
|
||||||
|
)()
|
||||||
|
assert isinstance(_instance, BasePlatform)
|
||||||
|
return _instance
|
||||||
|
|
||||||
|
|
||||||
class BasePlatform(object):
|
class BasePlatform(object):
|
||||||
@ -52,7 +77,7 @@ class BasePlatform(object):
|
|||||||
PACKAGES = {}
|
PACKAGES = {}
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
raise NotImplementedError()
|
return self.__class__.__name__[:-8].lower()
|
||||||
|
|
||||||
def get_build_script(self):
|
def get_build_script(self):
|
||||||
builtin = join(get_source_dir(), "builder", "scripts", "%s.py" %
|
builtin = join(get_source_dir(), "builder", "scripts", "%s.py" %
|
||||||
|
@ -27,6 +27,3 @@ class Timsp430Platform(BasePlatform):
|
|||||||
"default": True
|
"default": True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return "timsp430"
|
|
||||||
|
@ -27,6 +27,3 @@ class TitivaPlatform(BasePlatform):
|
|||||||
"default": True
|
"default": True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return "titiva"
|
|
||||||
|
Reference in New Issue
Block a user