Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): add Matter plugin support #4491

Merged
merged 27 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
311052a
Add Matter plugin
MonicaisHer Dec 11, 2023
76fa675
Add comments for Matter SDK building related commands
MonicaisHer Dec 12, 2023
815b68e
Use plugin name as a prefix for plugin-specific keywords
MonicaisHer Dec 14, 2023
a0fcab5
Replace storage paths in Matter SDK
MonicaisHer Dec 14, 2023
872a234
Format and uncomment
MonicaisHer Dec 14, 2023
90740f3
Update plugin keywords names, move bootstrap script after path replac…
MonicaisHer Dec 15, 2023
18b3a68
Enhance formatting and remove redundant copy command
MonicaisHer Jan 2, 2024
da14ed1
Add unit and spread tests for Matter plugin
MonicaisHer Jan 25, 2024
61adb5e
Merge branch 'main' into IENG-860
MonicaisHer Jan 26, 2024
7c484e2
Remove ZAP build, export `PATH` only
MonicaisHer Feb 12, 2024
d34cc01
Remove ZAP plugin-specific keyword
MonicaisHer Feb 12, 2024
9f5c229
Prepend PATH difference to existing PATH
MonicaisHer Feb 15, 2024
76d8ce7
Fix format, source matter-sdk-env.sh file in matter lighting snap
MonicaisHer Feb 15, 2024
f529f0f
Merge branch 'main' into IENG-860
MonicaisHer Feb 15, 2024
1cb674d
Use shell parameter expansion
MonicaisHer Feb 15, 2024
eca52bd
Remove extra separator
MonicaisHer Feb 16, 2024
12e1e6a
Combine multiple statements into one for better readability
MonicaisHer Feb 23, 2024
0e415a2
Remove obsolete if statement
MonicaisHer Feb 23, 2024
ffcd7c6
Stage plugin env script, and flag plugin as experimental
MonicaisHer Mar 7, 2024
a9c3920
Revert "Stage plugin env script, and flag plugin as experimental"
MonicaisHer Mar 7, 2024
f1c69bb
Flag plugin as experimental
MonicaisHer Mar 7, 2024
b7b4663
Stage plugin env script
MonicaisHer Mar 7, 2024
cefacd7
Check experimental matter plugin in lifecycle test
MonicaisHer Mar 11, 2024
94da1bc
Merge branch 'main' into IENG-860
MonicaisHer Mar 11, 2024
7916db5
Merge branch 'main' into IENG-860
syu-w Mar 20, 2024
76df76b
Remove extra line
MonicaisHer Mar 21, 2024
849dbfe
chore(merge): 'main' into 'IENG-860'
mr-cal Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions snapcraft/parts/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
from .flutter_plugin import FlutterPlugin
from .kernel_plugin import KernelPlugin
from .python_plugin import PythonPlugin
from .matter_plugin import MatterPlugin
from .register import register

__all__ = [
"ColconPlugin",
"CondaPlugin",
"FlutterPlugin",
"MatterPlugin",
"KernelPlugin",
"PythonPlugin",
"register",
Expand Down
138 changes: 138 additions & 0 deletions snapcraft/parts/plugins/matter_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2023 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""The matter plugin."""
import os

from typing import Any, Dict, List, Set

from craft_parts import infos, plugins
from overrides import overrides

MATTER_REPO = "https://github.com/project-chip/connectedhomeip.git"
"""The repository where the matter SDK resides."""

MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved

class MatterPluginProperties(plugins.PluginProperties, plugins.PluginModel):
"""The part properties used by the matter plugin."""

# matter_branch: str
# zap_version: str
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
@overrides
def unmarshal(cls, data: Dict[str, Any]) -> "MatterPluginProperties":
"""Populate class attributes from the part specification.

:param data: A dictionary containing part properties.

:return: The populated plugin properties data object.

:raise pydantic.ValidationError: If validation fails.
"""
plugin_data = plugins.extract_plugin_properties(
data,
plugin_name="matter",
# required=["matter_branch", "zap_version"]
)
return cls(**plugin_data)


class MatterPlugin(plugins.Plugin):
"""A plugin for matter project.

This plugin uses the common plugin keywords.
For more information check the 'plugins' topic.

Additionally, this plugin uses the following plugin-specific keywords:
- matter-branch
(str, no default)
The matter branch to use for the build.
- zap-version
(str, no default)
The zap version to use for the build.
"""

properties_class = MatterPluginProperties

def __init__(
self,
*,
properties: plugins.PluginProperties,
part_info: infos.PartInfo,
) -> None:
super().__init__(properties=properties, part_info=part_info)

self.matter_dir = part_info.part_build_dir
self.snap_arch = os.getenv("SNAP_ARCH")

@overrides
def get_build_packages(self) -> Set[str]:
return {
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
"wget",
"unzip",
"clang",
"pkg-config",
"git",
"cmake",
"ninja-build",
"unzip",
"libssl-dev",
"libdbus-1-dev",
"libglib2.0-dev",
"libavahi-client-dev",
"python3-venv",
"python3-dev",
"python3-pip",
"libgirepository1.0-dev",
"libcairo2-dev",
"libreadline-dev",
"generate-ninja",
}

@overrides
def get_build_environment(self) -> Dict[str, str]:
return {}

@overrides
def get_build_snaps(self) -> Set[str]:
return set()

@overrides
def get_build_commands(self) -> List[str]:
commands = []

if self.snap_arch == "arm64":
commands.extend(
[
f"wget --no-verbose https://github.com/project-chip/zap/releases/download/v2023.11.13/zap-linux-{self.snap_arch}.zip",
f"unzip -o zap-linux-{self.snap_arch}.zip",
"echo 'export ZAP_INSTALL_PATH=$PWD'",
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
]
)

commands.extend(
[
f"if [ ! -d matter ]; then git clone --depth 1 -b v1.2.0.1 {MATTER_REPO} matter; fi",
"cd matter || echo 'skip clone'",
f"scripts/checkout_submodules.py --shallow --platform linux",
f"set +u && source scripts/activate.sh && set -u",
"cp -vr ./* $CRAFT_PART_INSTALL/",
"echo 'Cloned Matter repository and activated submodules'",
]
)

return commands
MonicaisHer marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion snapcraft/parts/plugins/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
from .flutter_plugin import FlutterPlugin
from .kernel_plugin import KernelPlugin
from .python_plugin import PythonPlugin
from .matter_plugin import MatterPlugin


def register() -> None:
"""Register Snapcraft plugins."""
craft_parts.plugins.register({"colcon": ColconPlugin})
craft_parts.plugins.register({"conda": CondaPlugin})
craft_parts.plugins.register({"flutter": FlutterPlugin})
craft_parts.plugins.register({"matter": MatterPlugin})
craft_parts.plugins.register({"python": PythonPlugin})
craft_parts.plugins.register({"kernel": KernelPlugin})