Skip to content

Commit b929e45

Browse files
committed
Add "inc" folder automatically to CPPPATH when "src" is available (works for project and library) // Resolve #1003
1 parent b4f927a commit b929e45

File tree

5 files changed

+75
-65
lines changed

5 files changed

+75
-65
lines changed

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"build": true,
99
"dist": true
1010
},
11-
"editor.rulers": [79]
11+
"editor.rulers": [79],
12+
"restructuredtext.builtDocumentationPath": "${workspaceRoot}/docs/_build/html",
13+
"restructuredtext.confPath": "${workspaceRoot}/docs",
14+
"restructuredtext.linter.executablePath": "${workspaceRoot}/.tox/docs/bin/restructuredtext-lint"
1215
}

HISTORY.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ PlatformIO 3.0
99

1010
* Pre/Post extra scripting for advanced control of PIO Build System
1111
(`issue #891 <https://github.com/platformio/platformio-core/issues/891>`_)
12-
* Added ``monitor_*`` options to white-list for `Project Configuration File "platformio.ini" <http://docs.platformio.org/page/projectconf.html>`__
13-
(`issue #982 <https://github.com/platformio/platformio-core/issues/982>`_)
12+
* Add "inc" folder automatically to CPPPATH when "src" is available (works for project and library)
13+
(`issue #1003 <https://github.com/platformio/platformio-core/issues/1003>`_)
1414
* Use a root of library when filtering source code using
1515
`library.json <http://docs.platformio.org/page/librarymanager/config.html>`__
1616
and ``srcFilter`` field
17+
* Added ``monitor_*`` options to white-list for `Project Configuration File "platformio.ini" <http://docs.platformio.org/page/projectconf.html>`__
18+
(`issue #982 <https://github.com/platformio/platformio-core/issues/982>`_)
1719
* Do not ask for board ID when initialize project for desktop platform
1820
* Handle broken PIO Core state and create new one
1921
* 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
14341436
* Added support for *Microduino* and *Raspduino* boards in
14351437
`atmelavr <http://docs.platformio.org/page/platforms/atmelavr.html>`_ platform
14361438

1437-
14381439
0.3.1 (2014-06-21)
14391440
~~~~~~~~~~~~~~~~~~
14401441

platformio/builder/tools/piolib.py

+65-59
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ def build_dir(self):
150150
return join("$BUILD_DIR", "lib", basename(self.path))
151151

152152
def get_inc_dirs(self):
153-
return [self.src_dir]
153+
items = [self.src_dir]
154+
if all([isdir(join(self.path, d)) for d in ("inc", "src")]):
155+
items.append(join(self.path, "inc"))
156+
return items
154157

155158
@property
156159
def build_flags(self):
@@ -383,70 +386,33 @@ def build(self):
383386
for lb in self._circular_deps:
384387
self.env.AppendUnique(CPPPATH=lb.get_inc_dirs())
385388

386-
if not self._is_built:
387-
self.env.AppendUnique(CPPPATH=self.get_inc_dirs())
389+
if self._is_built:
390+
return libs
391+
self._is_built = True
388392

389-
if self.lib_ldf_mode == "off":
390-
for lb in self.envorigin.GetLibBuilders():
391-
if self == lb or not lb.is_built:
392-
continue
393-
for key in ("CPPPATH", "LIBPATH", "LIBS", "LINKFLAGS"):
394-
self.env.AppendUnique(**{key: lb.env.get(key)})
393+
self.env.AppendUnique(CPPPATH=self.get_inc_dirs())
395394

396-
if self.lib_archive:
397-
libs.append(
398-
self.env.BuildLibrary(self.build_dir, self.src_dir,
399-
self.src_filter))
400-
else:
401-
self.env.BuildSources(self.build_dir, self.src_dir,
402-
self.src_filter)
403-
self._is_built = True
395+
if self.lib_ldf_mode == "off":
396+
for lb in self.envorigin.GetLibBuilders():
397+
if self == lb or not lb.is_built:
398+
continue
399+
for key in ("CPPPATH", "LIBPATH", "LIBS", "LINKFLAGS"):
400+
self.env.AppendUnique(**{key: lb.env.get(key)})
401+
402+
if self.lib_archive:
403+
libs.append(
404+
self.env.BuildLibrary(self.build_dir, self.src_dir,
405+
self.src_filter))
406+
else:
407+
self.env.BuildSources(self.build_dir, self.src_dir,
408+
self.src_filter)
404409
return libs
405410

406411

407412
class UnknownLibBuilder(LibBuilderBase):
408413
pass
409414

410415

411-
class ProjectAsLibBuilder(LibBuilderBase):
412-
413-
def __init__(self, *args, **kwargs):
414-
LibBuilderBase.__init__(self, *args, **kwargs)
415-
self._is_built = True
416-
417-
@property
418-
def src_dir(self):
419-
return self.env.subst("$PROJECTSRC_DIR")
420-
421-
@property
422-
def lib_ldf_mode(self):
423-
mode = LibBuilderBase.lib_ldf_mode.fget(self)
424-
if not mode.startswith("chain"):
425-
return mode
426-
# parse all project files
427-
return "deep+" if "+" in mode else "deep"
428-
429-
@property
430-
def src_filter(self):
431-
return self.env.get("SRC_FILTER", LibBuilderBase.src_filter.fget(self))
432-
433-
def process_extra_options(self):
434-
# skip for project, options are already processed
435-
pass
436-
437-
def search_deps_recursive(self, search_paths=None):
438-
for dep in self.env.get("LIB_DEPS", []):
439-
for token in ("@", "="):
440-
if token in dep:
441-
dep, _ = dep.split(token, 1)
442-
for lb in self.envorigin.GetLibBuilders():
443-
if lb.name == dep:
444-
if lb not in self.depbuilders:
445-
self.depend_recursive(lb)
446-
break
447-
return LibBuilderBase.search_deps_recursive(self, search_paths)
448-
449-
450416
class ArduinoLibBuilder(LibBuilderBase):
451417

452418
def load_manifest(self):
@@ -598,6 +564,46 @@ def get_inc_dirs(self):
598564
return inc_dirs
599565

600566

567+
class ProjectAsLibBuilder(LibBuilderBase):
568+
569+
@property
570+
def src_dir(self):
571+
return self.env.subst("$PROJECTSRC_DIR")
572+
573+
@property
574+
def lib_ldf_mode(self):
575+
mode = LibBuilderBase.lib_ldf_mode.fget(self)
576+
if not mode.startswith("chain"):
577+
return mode
578+
# parse all project files
579+
return "deep+" if "+" in mode else "deep"
580+
581+
@property
582+
def src_filter(self):
583+
return self.env.get("SRC_FILTER", LibBuilderBase.src_filter.fget(self))
584+
585+
def process_extra_options(self):
586+
# skip for project, options are already processed
587+
pass
588+
589+
def search_deps_recursive(self, search_paths=None):
590+
for dep in self.env.get("LIB_DEPS", []):
591+
for token in ("@", "="):
592+
if token in dep:
593+
dep, _ = dep.split(token, 1)
594+
for lb in self.envorigin.GetLibBuilders():
595+
if lb.name == dep:
596+
if lb not in self.depbuilders:
597+
self.depend_recursive(lb)
598+
break
599+
return LibBuilderBase.search_deps_recursive(self, search_paths)
600+
601+
def build(self):
602+
self._is_built = True # do not build Project now
603+
self.env.AppendUnique(CPPPATH=self.get_inc_dirs())
604+
return LibBuilderBase.build(self)
605+
606+
601607
def GetLibBuilders(env): # pylint: disable=too-many-branches
602608

603609
if "__PIO_LIB_BUILDERS" in DefaultEnvironment():
@@ -664,7 +670,7 @@ def _check_lib_builder(lb):
664670
return items
665671

666672

667-
def BuildDependentLibraries(env, src_dir):
673+
def BuildProjectLibraries(env):
668674
lib_builders = env.GetLibBuilders()
669675

670676
def correct_found_libs():
@@ -693,7 +699,7 @@ def print_deps_tree(root, level=0):
693699
print "Collected %d compatible libraries" % len(lib_builders)
694700
print "Looking for dependencies..."
695701

696-
project = ProjectAsLibBuilder(env, src_dir)
702+
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
697703
project.env = env
698704
project.search_deps_recursive()
699705

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

718724
def generate(env):
719725
env.AddMethod(GetLibBuilders)
720-
env.AddMethod(BuildDependentLibraries)
726+
env.AddMethod(BuildProjectLibraries)
721727
return env

platformio/builder/tools/platformio.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _append_pio_macros():
6363
_append_pio_macros()
6464

6565
# build dependent libs
66-
deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")
66+
deplibs = env.BuildProjectLibraries()
6767

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

8181
env.Append(
82-
CPPPATH=["$PROJECTSRC_DIR"],
8382
LIBS=deplibs,
8483
LIBPATH=["$BUILD_DIR"],
8584
PIOBUILDFILES=env.CollectBuildFiles(

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ basepython = python2.7
3131
deps =
3232
sphinx
3333
sphinx_rtd_theme
34+
restructuredtext-lint
3435
commands =
3536
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
3637
sphinx-build -W -b latex -d {envtmpdir}/doctrees docs docs/_build/latex

0 commit comments

Comments
 (0)