Added support for a new "headers" field in "library.json"

This commit is contained in:
Ivan Kravets
2021-11-18 17:55:35 +02:00
parent 507df1f507
commit 68243aa95b
5 changed files with 29 additions and 5 deletions

View File

@ -11,6 +11,7 @@ PlatformIO Core 5
5.2.4 (2021-??-??) 5.2.4 (2021-??-??)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
- Added support for a new ``headers`` field in `library.json <https://docs.platformio.org/en/latest/librarymanager/config.html>`__ (declare a list of header files that can be included in a project source files using ``#include <...>`` directive)
- Improved support for projects located on a network share (`issue #3417 <https://github.com/platformio/platformio-core/issues/3417>`_, `issue #3926 <https://github.com/platformio/platformio-core/issues/3926>`_, `issue #4099 <https://github.com/platformio/platformio-core/issues/4099>`_) - Improved support for projects located on a network share (`issue #3417 <https://github.com/platformio/platformio-core/issues/3417>`_, `issue #3926 <https://github.com/platformio/platformio-core/issues/3926>`_, `issue #4099 <https://github.com/platformio/platformio-core/issues/4099>`_)
- Upgraded build engine to the SCons 4.3 (`release notes <https://github.com/SCons/scons/blob/rel_4.3.0/CHANGES.txt>`__) - Upgraded build engine to the SCons 4.3 (`release notes <https://github.com/SCons/scons/blob/rel_4.3.0/CHANGES.txt>`__)
- Fixed an issue with the CLion project generator when a macro contains a space (`issue #4102 <https://github.com/platformio/platformio-core/issues/4102>`_) - Fixed an issue with the CLion project generator when a macro contains a space (`issue #4102 <https://github.com/platformio/platformio-core/issues/4102>`_)

2
docs

Submodule docs updated: 7b3abdb696...1e2679b0ef

View File

@ -167,7 +167,7 @@ class BaseManifestParser(object):
return self._data return self._data
@staticmethod @staticmethod
def str_to_list(value, sep=",", lowercase=True): def str_to_list(value, sep=",", lowercase=False):
if isinstance(value, string_types): if isinstance(value, string_types):
value = value.split(sep) value = value.split(sep)
assert isinstance(value, list) assert isinstance(value, list)
@ -323,8 +323,10 @@ class LibraryJsonManifestParser(BaseManifestParser):
# normalize Union[str, list] fields # normalize Union[str, list] fields
for k in ("keywords", "platforms", "frameworks"): for k in ("keywords", "platforms", "frameworks"):
if k in data: if k in data:
data[k] = self.str_to_list(data[k], sep=",") data[k] = self.str_to_list(data[k], sep=",", lowercase=True)
if "headers" in data:
data["headers"] = self.str_to_list(data["headers"], sep=",")
if "authors" in data: if "authors" in data:
data["authors"] = self._parse_authors(data["authors"]) data["authors"] = self._parse_authors(data["authors"])
if "platforms" in data: if "platforms" in data:
@ -430,7 +432,9 @@ class ModuleJsonManifestParser(BaseManifestParser):
if "dependencies" in data: if "dependencies" in data:
data["dependencies"] = self._parse_dependencies(data["dependencies"]) data["dependencies"] = self._parse_dependencies(data["dependencies"])
if "keywords" in data: if "keywords" in data:
data["keywords"] = self.str_to_list(data["keywords"], sep=",") data["keywords"] = self.str_to_list(
data["keywords"], sep=",", lowercase=True
)
return data return data
def _parse_authors(self, raw): def _parse_authors(self, raw):
@ -480,6 +484,9 @@ class LibraryPropertiesManifestParser(BaseManifestParser):
export=self._parse_export(), export=self._parse_export(),
) )
) )
if "includes" in data:
data["headers"] = self.str_to_list(data["includes"], ",")
del data["includes"]
if "author" in data: if "author" in data:
data["authors"] = self._parse_authors(data) data["authors"] = self._parse_authors(data)
for key in ("author", "maintainer"): for key in ("author", "maintainer"):
@ -674,7 +681,9 @@ class PackageJsonManifestParser(BaseManifestParser):
def parse(self, contents): def parse(self, contents):
data = json.loads(contents) data = json.loads(contents)
if "keywords" in data: if "keywords" in data:
data["keywords"] = self.str_to_list(data["keywords"], sep=",") data["keywords"] = self.str_to_list(
data["keywords"], sep=",", lowercase=True
)
data = self._parse_system(data) data = self._parse_system(data)
data = self._parse_homepage(data) data = self._parse_homepage(data)
data = self._parse_repository(data) data = self._parse_repository(data)

View File

@ -209,6 +209,13 @@ class ManifestSchema(BaseSchema):
] ]
) )
) )
headers = StrictListField(
fields.Str(
validate=[
validate.Length(min=1, max=255),
]
)
)
# platform.json specific # platform.json specific
title = fields.Str(validate=validate.Length(min=1, max=100)) title = fields.Str(validate=validate.Length(min=1, max=100))

View File

@ -29,6 +29,7 @@ def test_library_json_parser():
{ {
"name": "TestPackage", "name": "TestPackage",
"keywords": "kw1, KW2, kw3", "keywords": "kw1, KW2, kw3",
"headers": "include1.h, Include2.hpp",
"platforms": ["atmelavr", "espressif"], "platforms": ["atmelavr", "espressif"],
"repository": { "repository": {
"type": "git", "type": "git",
@ -62,6 +63,7 @@ def test_library_json_parser():
}, },
"export": {"exclude": [".gitignore", "tests"], "include": ["mylib"]}, "export": {"exclude": [".gitignore", "tests"], "include": ["mylib"]},
"keywords": ["kw1", "kw2", "kw3"], "keywords": ["kw1", "kw2", "kw3"],
"headers": ["include1.h", "Include2.hpp"],
"homepage": "http://old.url.format", "homepage": "http://old.url.format",
"build": {"flags": ["-DHELLO"]}, "build": {"flags": ["-DHELLO"]},
"dependencies": [ "dependencies": [
@ -76,6 +78,7 @@ def test_library_json_parser():
contents = """ contents = """
{ {
"keywords": ["sound", "audio", "music", "SD", "card", "playback"], "keywords": ["sound", "audio", "music", "SD", "card", "playback"],
"headers": ["include 1.h", "include Space.hpp"],
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "atmelavr", "platforms": "atmelavr",
"export": { "export": {
@ -94,6 +97,7 @@ def test_library_json_parser():
raw_data, raw_data,
{ {
"keywords": ["sound", "audio", "music", "sd", "card", "playback"], "keywords": ["sound", "audio", "music", "sd", "card", "playback"],
"headers": ["include 1.h", "include Space.hpp"],
"frameworks": ["arduino"], "frameworks": ["arduino"],
"export": {"exclude": ["audio_samples"]}, "export": {"exclude": ["audio_samples"]},
"platforms": ["atmelavr"], "platforms": ["atmelavr"],
@ -205,6 +209,7 @@ sentence=This is Arduino library
customField=Custom Value customField=Custom Value
depends=First Library (=2.0.0), Second Library (>=1.2.0), Third depends=First Library (=2.0.0), Second Library (>=1.2.0), Third
ignore_empty_field= ignore_empty_field=
includes=Arduino.h, Arduino Space.hpp
""" """
raw_data = parser.LibraryPropertiesManifestParser(contents).as_dict() raw_data = parser.LibraryPropertiesManifestParser(contents).as_dict()
raw_data["dependencies"] = sorted(raw_data["dependencies"], key=lambda a: a["name"]) raw_data["dependencies"] = sorted(raw_data["dependencies"], key=lambda a: a["name"])
@ -225,6 +230,7 @@ ignore_empty_field=
{"name": "Maintainer Author", "maintainer": True}, {"name": "Maintainer Author", "maintainer": True},
], ],
"keywords": ["uncategorized"], "keywords": ["uncategorized"],
"headers": ["Arduino.h", "Arduino Space.hpp"],
"customField": "Custom Value", "customField": "Custom Value",
"depends": "First Library (=2.0.0), Second Library (>=1.2.0), Third", "depends": "First Library (=2.0.0), Second Library (>=1.2.0), Third",
"dependencies": [ "dependencies": [
@ -530,6 +536,7 @@ includes=MozziGuts.h
}, },
"platforms": ["*"], "platforms": ["*"],
"frameworks": ["arduino"], "frameworks": ["arduino"],
"headers": ["MozziGuts.h"],
"export": { "export": {
"exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"] "exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"]
}, },