Check library compatibility with project environment before building // Resolve #415

This commit is contained in:
Ivan Kravets
2016-07-15 23:06:10 +03:00
parent 2bfa3517f0
commit 9838aef6b8
3 changed files with 42 additions and 2 deletions

View File

@ -20,6 +20,8 @@ PlatformIO 3.0
* Handle extra build flags and build script from
`library.json <http://docs.platformio.org/en/latest/librarymanager/config.html>`__
(`issue #289 <https://github.com/platformio/platformio/issues/289>`_)
* Check library compatibility with project environment before building
(`issue #415 <https://github.com/platformio/platformio/issues/415>`_)
* Added ``license`` field to `library.json <http://docs.platformio.org/en/latest/librarymanager/config.html>`__
(`issue #522 <https://github.com/platformio/platformio/issues/522>`_)
* Show detailed build information about dependent libraries

View File

@ -14,7 +14,7 @@
import sys
VERSION = (3, 0, "0.dev5")
VERSION = (3, 0, "0.dev6")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -124,6 +124,12 @@ class LibBuilderBase(object):
def is_built(self):
return self._is_built
def is_platform_compatible(self, platform):
return True
def is_framework_compatible(self, framework):
return True
def load_manifest(self): # pylint: disable=no-self-use
return {}
@ -191,6 +197,9 @@ class ArduinoLibBuilder(LibBuilderBase):
return ["+<*.%s>" % ext
for ext in piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT]
def is_framework_compatible(self, framework):
return framework.lower() in ("arduino", "energia")
class MbedLibBuilder(LibBuilderBase):
@ -214,6 +223,9 @@ class MbedLibBuilder(LibBuilderBase):
join(self.build_dir if use_build_dir else self.src_dir, p))
return path_dirs
def is_framework_compatible(self, framework):
return framework.lower() == "mbed"
class PlatformIOLibBuilder(LibBuilderBase):
@ -247,6 +259,25 @@ class PlatformIOLibBuilder(LibBuilderBase):
return self._manifest.get("build").get("extra_script")
return LibBuilderBase.extra_script.fget(self)
def is_platform_compatible(self, platform):
items = self._manifest.get("platforms")
if not items:
return LibBuilderBase.is_platform_compatible(self, platform)
return self._item_in_list(platform, items)
def is_framework_compatible(self, framework):
items = self._manifest.get("frameworks")
if not items:
return LibBuilderBase.is_framework_compatible(self, framework)
return self._item_in_list(framework, items)
def _item_in_list(self, item, ilist):
if ilist == "*":
return True
if not isinstance(ilist, list):
ilist = [i.strip() for i in ilist.split(",")]
return item.lower() in [i.lower() for i in ilist]
def find_deps(env, scanner, path_dirs, src_dir, src_filter):
result = []
@ -295,6 +326,8 @@ def find_and_build_deps(env, lib_builders, scanner,
def GetLibBuilders(env):
items = []
env_frameworks = [
f.lower().strip() for f in env.get("FRAMEWORK", "").split(",")]
libs_dirs = [env.subst(d) for d in env.get("LIBSOURCE_DIRS", [])
if isdir(env.subst(d))]
for libs_dir in libs_dirs:
@ -304,6 +337,11 @@ def GetLibBuilders(env):
lb = LibBuilderFactory.new(env, join(libs_dir, item))
if lb.name in env.get("LIB_IGNORE", []):
continue
if not lb.is_platform_compatible(env['PLATFORM']):
continue
if not any([lb.is_framework_compatible(f)
for f in env_frameworks]):
continue
items.append(lb)
return items
@ -314,7 +352,7 @@ def BuildDependentLibraries(env, src_dir):
lib_builders = env.GetLibBuilders()
print "Looking for dependencies..."
print "Collecting %d libraries" % len(lib_builders)
print "Collecting %d compatible libraries" % len(lib_builders)
built_lib_names = []
for lib_name in env.get("LIB_FORCE", []):