Navigation Menu

Skip to content

Commit

Permalink
Add "inc" folder automatically to CPPPATH when "src" is available (wo…
Browse files Browse the repository at this point in the history
…rks for project and library) // Resolve #1003
  • Loading branch information
ivankravets committed Aug 1, 2017
1 parent b4f927a commit b929e45
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 65 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Expand Up @@ -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"
}
7 changes: 4 additions & 3 deletions HISTORY.rst
Expand Up @@ -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>`__
Expand Down Expand Up @@ -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)
~~~~~~~~~~~~~~~~~~

Expand Down
124 changes: 65 additions & 59 deletions platformio/builder/tools/piolib.py
Expand Up @@ -150,7 +150,10 @@ def build_dir(self):
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):
Expand Down Expand Up @@ -383,70 +386,33 @@ def build(self):
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


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):
Expand Down Expand Up @@ -598,6 +564,46 @@ def get_inc_dirs(self):
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():
Expand Down Expand Up @@ -664,7 +670,7 @@ def _check_lib_builder(lb):
return items


def BuildDependentLibraries(env, src_dir):
def BuildProjectLibraries(env):
lib_builders = env.GetLibBuilders()

def correct_found_libs():
Expand Down Expand Up @@ -693,7 +699,7 @@ def print_deps_tree(root, level=0):
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()

Expand All @@ -717,5 +723,5 @@ def exists(_):

def generate(env):
env.AddMethod(GetLibBuilders)
env.AddMethod(BuildDependentLibraries)
env.AddMethod(BuildProjectLibraries)
return env
3 changes: 1 addition & 2 deletions platformio/builder/tools/platformio.py
Expand Up @@ -63,7 +63,7 @@ def _append_pio_macros():
_append_pio_macros()

# build dependent libs
deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")
deplibs = env.BuildProjectLibraries()

# append specified LD_SCRIPT
if ("LDSCRIPT_PATH" in env
Expand All @@ -79,7 +79,6 @@ def _append_pio_macros():
env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))

env.Append(
CPPPATH=["$PROJECTSRC_DIR"],
LIBS=deplibs,
LIBPATH=["$BUILD_DIR"],
PIOBUILDFILES=env.CollectBuildFiles(
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -31,6 +31,7 @@ basepython = python2.7
deps =
sphinx
sphinx_rtd_theme
restructuredtext-lint
commands =
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -b latex -d {envtmpdir}/doctrees docs docs/_build/latex
Expand Down

0 comments on commit b929e45

Please sign in to comment.