mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Add "inc" folder automatically to CPPPATH when "src" is available (works for project and library) // Resolve #1003
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -8,5 +8,8 @@
|
||||
"build": true,
|
||||
"dist": true
|
||||
},
|
||||
"editor.rulers": [79]
|
||||
"editor.rulers": [79],
|
||||
"restructuredtext.builtDocumentationPath": "${workspaceRoot}/docs/_build/html",
|
||||
"restructuredtext.confPath": "${workspaceRoot}/docs",
|
||||
"restructuredtext.linter.executablePath": "${workspaceRoot}/.tox/docs/bin/restructuredtext-lint"
|
||||
}
|
||||
|
@ -9,11 +9,13 @@ PlatformIO 3.0
|
||||
|
||||
* Pre/Post extra scripting for advanced control of PIO Build System
|
||||
(`issue #891 <https://github.com/platformio/platformio-core/issues/891>`_)
|
||||
* Added ``monitor_*`` options to white-list for `Project Configuration File "platformio.ini" <http://docs.platformio.org/page/projectconf.html>`__
|
||||
(`issue #982 <https://github.com/platformio/platformio-core/issues/982>`_)
|
||||
* Add "inc" folder automatically to CPPPATH when "src" is available (works for project and library)
|
||||
(`issue #1003 <https://github.com/platformio/platformio-core/issues/1003>`_)
|
||||
* Use a root of library when filtering source code using
|
||||
`library.json <http://docs.platformio.org/page/librarymanager/config.html>`__
|
||||
and ``srcFilter`` field
|
||||
* Added ``monitor_*`` options to white-list for `Project Configuration File "platformio.ini" <http://docs.platformio.org/page/projectconf.html>`__
|
||||
(`issue #982 <https://github.com/platformio/platformio-core/issues/982>`_)
|
||||
* Do not ask for board ID when initialize project for desktop platform
|
||||
* Handle broken PIO Core state and create new one
|
||||
* Fixed an issue with a custom transport for `PIO Unit Testing <http://docs.platformio.org/page/plus/unit-testing.html>`__
|
||||
@ -1434,7 +1436,6 @@ PlatformIO 0.0
|
||||
* Added support for *Microduino* and *Raspduino* boards in
|
||||
`atmelavr <http://docs.platformio.org/page/platforms/atmelavr.html>`_ platform
|
||||
|
||||
|
||||
0.3.1 (2014-06-21)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -150,7 +150,10 @@ class LibBuilderBase(object):
|
||||
return join("$BUILD_DIR", "lib", basename(self.path))
|
||||
|
||||
def get_inc_dirs(self):
|
||||
return [self.src_dir]
|
||||
items = [self.src_dir]
|
||||
if all([isdir(join(self.path, d)) for d in ("inc", "src")]):
|
||||
items.append(join(self.path, "inc"))
|
||||
return items
|
||||
|
||||
@property
|
||||
def build_flags(self):
|
||||
@ -383,24 +386,26 @@ class LibBuilderBase(object):
|
||||
for lb in self._circular_deps:
|
||||
self.env.AppendUnique(CPPPATH=lb.get_inc_dirs())
|
||||
|
||||
if not self._is_built:
|
||||
self.env.AppendUnique(CPPPATH=self.get_inc_dirs())
|
||||
if self._is_built:
|
||||
return libs
|
||||
self._is_built = True
|
||||
|
||||
if self.lib_ldf_mode == "off":
|
||||
for lb in self.envorigin.GetLibBuilders():
|
||||
if self == lb or not lb.is_built:
|
||||
continue
|
||||
for key in ("CPPPATH", "LIBPATH", "LIBS", "LINKFLAGS"):
|
||||
self.env.AppendUnique(**{key: lb.env.get(key)})
|
||||
self.env.AppendUnique(CPPPATH=self.get_inc_dirs())
|
||||
|
||||
if self.lib_archive:
|
||||
libs.append(
|
||||
self.env.BuildLibrary(self.build_dir, self.src_dir,
|
||||
self.src_filter))
|
||||
else:
|
||||
self.env.BuildSources(self.build_dir, self.src_dir,
|
||||
self.src_filter)
|
||||
self._is_built = True
|
||||
if self.lib_ldf_mode == "off":
|
||||
for lb in self.envorigin.GetLibBuilders():
|
||||
if self == lb or not lb.is_built:
|
||||
continue
|
||||
for key in ("CPPPATH", "LIBPATH", "LIBS", "LINKFLAGS"):
|
||||
self.env.AppendUnique(**{key: lb.env.get(key)})
|
||||
|
||||
if self.lib_archive:
|
||||
libs.append(
|
||||
self.env.BuildLibrary(self.build_dir, self.src_dir,
|
||||
self.src_filter))
|
||||
else:
|
||||
self.env.BuildSources(self.build_dir, self.src_dir,
|
||||
self.src_filter)
|
||||
return libs
|
||||
|
||||
|
||||
@ -408,45 +413,6 @@ class UnknownLibBuilder(LibBuilderBase):
|
||||
pass
|
||||
|
||||
|
||||
class ProjectAsLibBuilder(LibBuilderBase):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
LibBuilderBase.__init__(self, *args, **kwargs)
|
||||
self._is_built = True
|
||||
|
||||
@property
|
||||
def src_dir(self):
|
||||
return self.env.subst("$PROJECTSRC_DIR")
|
||||
|
||||
@property
|
||||
def lib_ldf_mode(self):
|
||||
mode = LibBuilderBase.lib_ldf_mode.fget(self)
|
||||
if not mode.startswith("chain"):
|
||||
return mode
|
||||
# parse all project files
|
||||
return "deep+" if "+" in mode else "deep"
|
||||
|
||||
@property
|
||||
def src_filter(self):
|
||||
return self.env.get("SRC_FILTER", LibBuilderBase.src_filter.fget(self))
|
||||
|
||||
def process_extra_options(self):
|
||||
# skip for project, options are already processed
|
||||
pass
|
||||
|
||||
def search_deps_recursive(self, search_paths=None):
|
||||
for dep in self.env.get("LIB_DEPS", []):
|
||||
for token in ("@", "="):
|
||||
if token in dep:
|
||||
dep, _ = dep.split(token, 1)
|
||||
for lb in self.envorigin.GetLibBuilders():
|
||||
if lb.name == dep:
|
||||
if lb not in self.depbuilders:
|
||||
self.depend_recursive(lb)
|
||||
break
|
||||
return LibBuilderBase.search_deps_recursive(self, search_paths)
|
||||
|
||||
|
||||
class ArduinoLibBuilder(LibBuilderBase):
|
||||
|
||||
def load_manifest(self):
|
||||
@ -598,6 +564,46 @@ class PlatformIOLibBuilder(LibBuilderBase):
|
||||
return inc_dirs
|
||||
|
||||
|
||||
class ProjectAsLibBuilder(LibBuilderBase):
|
||||
|
||||
@property
|
||||
def src_dir(self):
|
||||
return self.env.subst("$PROJECTSRC_DIR")
|
||||
|
||||
@property
|
||||
def lib_ldf_mode(self):
|
||||
mode = LibBuilderBase.lib_ldf_mode.fget(self)
|
||||
if not mode.startswith("chain"):
|
||||
return mode
|
||||
# parse all project files
|
||||
return "deep+" if "+" in mode else "deep"
|
||||
|
||||
@property
|
||||
def src_filter(self):
|
||||
return self.env.get("SRC_FILTER", LibBuilderBase.src_filter.fget(self))
|
||||
|
||||
def process_extra_options(self):
|
||||
# skip for project, options are already processed
|
||||
pass
|
||||
|
||||
def search_deps_recursive(self, search_paths=None):
|
||||
for dep in self.env.get("LIB_DEPS", []):
|
||||
for token in ("@", "="):
|
||||
if token in dep:
|
||||
dep, _ = dep.split(token, 1)
|
||||
for lb in self.envorigin.GetLibBuilders():
|
||||
if lb.name == dep:
|
||||
if lb not in self.depbuilders:
|
||||
self.depend_recursive(lb)
|
||||
break
|
||||
return LibBuilderBase.search_deps_recursive(self, search_paths)
|
||||
|
||||
def build(self):
|
||||
self._is_built = True # do not build Project now
|
||||
self.env.AppendUnique(CPPPATH=self.get_inc_dirs())
|
||||
return LibBuilderBase.build(self)
|
||||
|
||||
|
||||
def GetLibBuilders(env): # pylint: disable=too-many-branches
|
||||
|
||||
if "__PIO_LIB_BUILDERS" in DefaultEnvironment():
|
||||
@ -664,7 +670,7 @@ def GetLibBuilders(env): # pylint: disable=too-many-branches
|
||||
return items
|
||||
|
||||
|
||||
def BuildDependentLibraries(env, src_dir):
|
||||
def BuildProjectLibraries(env):
|
||||
lib_builders = env.GetLibBuilders()
|
||||
|
||||
def correct_found_libs():
|
||||
@ -693,7 +699,7 @@ def BuildDependentLibraries(env, src_dir):
|
||||
print "Collected %d compatible libraries" % len(lib_builders)
|
||||
print "Looking for dependencies..."
|
||||
|
||||
project = ProjectAsLibBuilder(env, src_dir)
|
||||
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
|
||||
project.env = env
|
||||
project.search_deps_recursive()
|
||||
|
||||
@ -717,5 +723,5 @@ def exists(_):
|
||||
|
||||
def generate(env):
|
||||
env.AddMethod(GetLibBuilders)
|
||||
env.AddMethod(BuildDependentLibraries)
|
||||
env.AddMethod(BuildProjectLibraries)
|
||||
return env
|
||||
|
@ -63,7 +63,7 @@ def BuildProgram(env):
|
||||
_append_pio_macros()
|
||||
|
||||
# build dependent libs
|
||||
deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")
|
||||
deplibs = env.BuildProjectLibraries()
|
||||
|
||||
# append specified LD_SCRIPT
|
||||
if ("LDSCRIPT_PATH" in env
|
||||
@ -79,7 +79,6 @@ def BuildProgram(env):
|
||||
env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))
|
||||
|
||||
env.Append(
|
||||
CPPPATH=["$PROJECTSRC_DIR"],
|
||||
LIBS=deplibs,
|
||||
LIBPATH=["$BUILD_DIR"],
|
||||
PIOBUILDFILES=env.CollectBuildFiles(
|
||||
|
Reference in New Issue
Block a user