From 68243aa95b4ebd6ec37c3e4f3bd8bebcd0edb749 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 18 Nov 2021 17:55:35 +0200 Subject: [PATCH] Added support for a new "headers" field in "library.json" --- HISTORY.rst | 1 + docs | 2 +- platformio/package/manifest/parser.py | 17 +++++++++++++---- platformio/package/manifest/schema.py | 7 +++++++ tests/package/test_manifest.py | 7 +++++++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index a5ea55aa..68e1f024 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,7 @@ PlatformIO Core 5 5.2.4 (2021-??-??) ~~~~~~~~~~~~~~~~~~ +- Added support for a new ``headers`` field in `library.json `__ (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 `_, `issue #3926 `_, `issue #4099 `_) - Upgraded build engine to the SCons 4.3 (`release notes `__) - Fixed an issue with the CLion project generator when a macro contains a space (`issue #4102 `_) diff --git a/docs b/docs index 7b3abdb6..1e2679b0 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 7b3abdb69625fcac959bbaa6a7aae0174afc16af +Subproject commit 1e2679b0ef3b373d2d324cd89e7ac6a2a14dbfe7 diff --git a/platformio/package/manifest/parser.py b/platformio/package/manifest/parser.py index 3598d516..78c4da1e 100644 --- a/platformio/package/manifest/parser.py +++ b/platformio/package/manifest/parser.py @@ -167,7 +167,7 @@ class BaseManifestParser(object): return self._data @staticmethod - def str_to_list(value, sep=",", lowercase=True): + def str_to_list(value, sep=",", lowercase=False): if isinstance(value, string_types): value = value.split(sep) assert isinstance(value, list) @@ -323,8 +323,10 @@ class LibraryJsonManifestParser(BaseManifestParser): # normalize Union[str, list] fields for k in ("keywords", "platforms", "frameworks"): 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: data["authors"] = self._parse_authors(data["authors"]) if "platforms" in data: @@ -430,7 +432,9 @@ class ModuleJsonManifestParser(BaseManifestParser): if "dependencies" in data: data["dependencies"] = self._parse_dependencies(data["dependencies"]) 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 def _parse_authors(self, raw): @@ -480,6 +484,9 @@ class LibraryPropertiesManifestParser(BaseManifestParser): export=self._parse_export(), ) ) + if "includes" in data: + data["headers"] = self.str_to_list(data["includes"], ",") + del data["includes"] if "author" in data: data["authors"] = self._parse_authors(data) for key in ("author", "maintainer"): @@ -674,7 +681,9 @@ class PackageJsonManifestParser(BaseManifestParser): def parse(self, contents): data = json.loads(contents) 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_homepage(data) data = self._parse_repository(data) diff --git a/platformio/package/manifest/schema.py b/platformio/package/manifest/schema.py index fcd84296..cedb84ad 100644 --- a/platformio/package/manifest/schema.py +++ b/platformio/package/manifest/schema.py @@ -209,6 +209,13 @@ class ManifestSchema(BaseSchema): ] ) ) + headers = StrictListField( + fields.Str( + validate=[ + validate.Length(min=1, max=255), + ] + ) + ) # platform.json specific title = fields.Str(validate=validate.Length(min=1, max=100)) diff --git a/tests/package/test_manifest.py b/tests/package/test_manifest.py index ff6803eb..18c6a355 100644 --- a/tests/package/test_manifest.py +++ b/tests/package/test_manifest.py @@ -29,6 +29,7 @@ def test_library_json_parser(): { "name": "TestPackage", "keywords": "kw1, KW2, kw3", + "headers": "include1.h, Include2.hpp", "platforms": ["atmelavr", "espressif"], "repository": { "type": "git", @@ -62,6 +63,7 @@ def test_library_json_parser(): }, "export": {"exclude": [".gitignore", "tests"], "include": ["mylib"]}, "keywords": ["kw1", "kw2", "kw3"], + "headers": ["include1.h", "Include2.hpp"], "homepage": "http://old.url.format", "build": {"flags": ["-DHELLO"]}, "dependencies": [ @@ -76,6 +78,7 @@ def test_library_json_parser(): contents = """ { "keywords": ["sound", "audio", "music", "SD", "card", "playback"], + "headers": ["include 1.h", "include Space.hpp"], "frameworks": "arduino", "platforms": "atmelavr", "export": { @@ -94,6 +97,7 @@ def test_library_json_parser(): raw_data, { "keywords": ["sound", "audio", "music", "sd", "card", "playback"], + "headers": ["include 1.h", "include Space.hpp"], "frameworks": ["arduino"], "export": {"exclude": ["audio_samples"]}, "platforms": ["atmelavr"], @@ -205,6 +209,7 @@ sentence=This is Arduino library customField=Custom Value depends=First Library (=2.0.0), Second Library (>=1.2.0), Third ignore_empty_field= +includes=Arduino.h, Arduino Space.hpp """ raw_data = parser.LibraryPropertiesManifestParser(contents).as_dict() raw_data["dependencies"] = sorted(raw_data["dependencies"], key=lambda a: a["name"]) @@ -225,6 +230,7 @@ ignore_empty_field= {"name": "Maintainer Author", "maintainer": True}, ], "keywords": ["uncategorized"], + "headers": ["Arduino.h", "Arduino Space.hpp"], "customField": "Custom Value", "depends": "First Library (=2.0.0), Second Library (>=1.2.0), Third", "dependencies": [ @@ -530,6 +536,7 @@ includes=MozziGuts.h }, "platforms": ["*"], "frameworks": ["arduino"], + "headers": ["MozziGuts.h"], "export": { "exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"] },