Improved handling of a library root based on "Conan" or "CMake" build systems // Resolve #3887

This commit is contained in:
Ivan Kravets
2021-09-29 19:21:31 +03:00
parent ed33652534
commit e8769fff7d
3 changed files with 21 additions and 6 deletions

View File

@ -12,7 +12,8 @@ PlatformIO Core 5
~~~~~~~~~~~~~~~~~~
- Allowed to override a default library builder via a new ``builder`` field in a ``build`` group of `library.json <https://docs.platformio.org/page/librarymanager/config.html#build>`__ manifest (`issue #3957 <https://github.com/platformio/platformio-core/issues/3957>`_)
- Handle "test" folder as a part of CLion project (`issue #4005 <https://github.com/platformio/platformio-core/issues/4005>`_)
- Handle the "test" folder as a part of CLion project (`issue #4005 <https://github.com/platformio/platformio-core/issues/4005>`_)
- Improved handling of a library root based on "Conan" or "CMake" build systems (`issue #3887 <https://github.com/platformio/platformio-core/issues/3887>`_)
- Fixed a "KeyError: Invalid board option 'build.cpu'" when using a precompiled library with a board that does not have a CPU field in the manifest (`issue #4056 <https://github.com/platformio/platformio-core/issues/4056>`_)
- Fixed a "FileExist" error when the `platformio ci <https://docs.platformio.org/en/latest/userguide/cmd_ci.html>`__ command is used in pair with the ``--keep-build-dir`` option (`issue #4011 <https://github.com/platformio/platformio-core/issues/4011>`_)
- Fixed an issue with draft values of C++ language standards that broke static analysis via Cppcheck (`issue #3944 <https://github.com/platformio/platformio-core/issues/3944>`_)

View File

@ -184,11 +184,11 @@ class LibBuilderBase(object):
@property
def include_dir(self):
if not all(
os.path.isdir(os.path.join(self.path, d)) for d in ("include", "src")
):
return None
return os.path.join(self.path, "include")
return (
os.path.join(self.path, "include")
if os.path.isdir(os.path.join(self.path, "include"))
else None
)
@property
def src_dir(self):
@ -501,6 +501,14 @@ class ArduinoLibBuilder(LibBuilderBase):
return {}
return ManifestParserFactory.new_from_file(manifest_path).as_dict()
@property
def include_dir(self):
if not all(
os.path.isdir(os.path.join(self.path, d)) for d in ("include", "src")
):
return None
return os.path.join(self.path, "include")
def get_include_dirs(self):
include_dirs = LibBuilderBase.get_include_dirs(self)
if os.path.isdir(os.path.join(self.path, "src")):

View File

@ -61,6 +61,12 @@ class LibraryPackageManager(BasePackageManager): # pylint: disable=too-many-anc
@staticmethod
def find_library_root(path):
for root, dirs, files in os.walk(path):
# check if Conan-based library
if os.path.isfile(os.path.join(root, "conanfile.py")):
return root
# check if CMake-based library
if os.path.isfile(os.path.join(root, "CMakeLists.txt")):
return root
if not files and len(dirs) == 1:
continue
for fname in files: