forked from platformio/platformio-core
Improve library builder for Arduino lib structure
This commit is contained in:
@ -23,6 +23,7 @@ from sys import modules
|
|||||||
import SCons.Scanner
|
import SCons.Scanner
|
||||||
|
|
||||||
from platformio import util
|
from platformio import util
|
||||||
|
from platformio.builder.tools import platformio as piotool
|
||||||
|
|
||||||
|
|
||||||
class LibBuilderFactory(object):
|
class LibBuilderFactory(object):
|
||||||
@ -72,7 +73,7 @@ class LibBuilderFactory(object):
|
|||||||
class LibBuilderBase(object):
|
class LibBuilderBase(object):
|
||||||
|
|
||||||
def __init__(self, env, path):
|
def __init__(self, env, path):
|
||||||
self.env = env
|
self.env = env.Clone()
|
||||||
self.path = path
|
self.path = path
|
||||||
self._is_built = False
|
self._is_built = False
|
||||||
self._manifest = self.load_manifest()
|
self._manifest = self.load_manifest()
|
||||||
@ -93,11 +94,10 @@ class LibBuilderBase(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def src_filter(self):
|
def src_filter(self):
|
||||||
return " ".join([
|
return piotool.SRC_FILTER_DEFAULT + [
|
||||||
"+<*>", "-<.git%s>" % os.sep, "-<svn%s>" % os.sep,
|
|
||||||
"-<example%s>" % os.sep, "-<examples%s>" % os.sep,
|
"-<example%s>" % os.sep, "-<examples%s>" % os.sep,
|
||||||
"-<test%s>" % os.sep, "-<tests%s>" % os.sep
|
"-<test%s>" % os.sep, "-<tests%s>" % os.sep
|
||||||
])
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def src_dir(self):
|
def src_dir(self):
|
||||||
@ -118,8 +118,8 @@ class LibBuilderBase(object):
|
|||||||
def get_path_dirs(self, use_build_dir=False):
|
def get_path_dirs(self, use_build_dir=False):
|
||||||
return [self.build_dir if use_build_dir else self.src_dir]
|
return [self.build_dir if use_build_dir else self.src_dir]
|
||||||
|
|
||||||
def append_to_cpppath(self):
|
def append_to_cpppath(self, env):
|
||||||
self.env.AppendUnique(
|
env.AppendUnique(
|
||||||
CPPPATH=self.get_path_dirs(use_build_dir=True)
|
CPPPATH=self.get_path_dirs(use_build_dir=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -130,8 +130,8 @@ class LibBuilderBase(object):
|
|||||||
print "Depends on <%s>" % self.name
|
print "Depends on <%s>" % self.name
|
||||||
assert self._is_built is False
|
assert self._is_built is False
|
||||||
self._is_built = True
|
self._is_built = True
|
||||||
self.append_to_cpppath()
|
return self.env.BuildLibrary(
|
||||||
return self.env.BuildLibrary(self.build_dir, self.src_dir)
|
self.build_dir, self.src_dir, self.src_filter)
|
||||||
|
|
||||||
|
|
||||||
class UnknownLibBuilder(LibBuilderBase):
|
class UnknownLibBuilder(LibBuilderBase):
|
||||||
@ -160,6 +160,13 @@ class ArduinoLibBuilder(LibBuilderBase):
|
|||||||
join(self.build_dir if use_build_dir else self.src_dir, "utility"))
|
join(self.build_dir if use_build_dir else self.src_dir, "utility"))
|
||||||
return path_dirs
|
return path_dirs
|
||||||
|
|
||||||
|
@property
|
||||||
|
def src_filter(self):
|
||||||
|
if isdir(join(self.path, "src")):
|
||||||
|
return LibBuilderBase.src_filter.fget(self)
|
||||||
|
return ["+<*.%s>" % ext
|
||||||
|
for ext in piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT]
|
||||||
|
|
||||||
|
|
||||||
class MbedLibBuilder(LibBuilderBase):
|
class MbedLibBuilder(LibBuilderBase):
|
||||||
|
|
||||||
@ -225,7 +232,7 @@ def find_and_build_deps(env, lib_builders, scanner,
|
|||||||
libs = []
|
libs = []
|
||||||
# append PATH directories to global CPPPATH before build starts
|
# append PATH directories to global CPPPATH before build starts
|
||||||
for lb in target_lbs:
|
for lb in target_lbs:
|
||||||
lb.append_to_cpppath()
|
lb.append_to_cpppath(env)
|
||||||
# start builder
|
# start builder
|
||||||
for lb in target_lbs:
|
for lb in target_lbs:
|
||||||
libs.append(lb.build())
|
libs.append(lb.build())
|
||||||
@ -270,6 +277,7 @@ def BuildDependentLibraries(env, src_dir):
|
|||||||
libs.extend(find_and_build_deps(
|
libs.extend(find_and_build_deps(
|
||||||
env, lib_builders, scanner, lb.src_dir, lb.src_filter))
|
env, lib_builders, scanner, lb.src_dir, lb.src_filter))
|
||||||
if not lb.is_built:
|
if not lb.is_built:
|
||||||
|
lb.append_to_cpppath(env)
|
||||||
libs.append(lb.build())
|
libs.append(lb.build())
|
||||||
|
|
||||||
# process project source code
|
# process project source code
|
||||||
|
@ -26,7 +26,7 @@ from platformio.util import pioversion_to_intstr
|
|||||||
|
|
||||||
SRC_BUILD_EXT = ["c", "cpp", "S", "spp", "SPP", "sx", "s", "asm", "ASM"]
|
SRC_BUILD_EXT = ["c", "cpp", "S", "spp", "SPP", "sx", "s", "asm", "ASM"]
|
||||||
SRC_HEADER_EXT = ["h", "hpp"]
|
SRC_HEADER_EXT = ["h", "hpp"]
|
||||||
SRC_FILTER_DEFAULT = " ".join(["+<*>", "-<.git%s>" % sep, "-<svn%s>" % sep])
|
SRC_FILTER_DEFAULT = ["+<*>", "-<.git%s>" % sep, "-<svn%s>" % sep]
|
||||||
|
|
||||||
|
|
||||||
def BuildProgram(env):
|
def BuildProgram(env):
|
||||||
@ -179,6 +179,8 @@ def MatchSourceFiles(env, src_dir, src_filter=None):
|
|||||||
|
|
||||||
src_dir = env.subst(src_dir)
|
src_dir = env.subst(src_dir)
|
||||||
src_filter = src_filter or SRC_FILTER_DEFAULT
|
src_filter = src_filter or SRC_FILTER_DEFAULT
|
||||||
|
if isinstance(src_filter, list) or isinstance(src_filter, tuple):
|
||||||
|
src_filter = " ".join(src_filter)
|
||||||
|
|
||||||
matches = set()
|
matches = set()
|
||||||
# correct fs directory separator
|
# correct fs directory separator
|
||||||
|
Reference in New Issue
Block a user