Skip to content

Commit

Permalink
Add support for not complaining about abi changes in provisional cl…
Browse files Browse the repository at this point in the history
…usters (#31372)

* Ignore changes in provisional clusters for backwards compatibility

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Feb 8, 2024
1 parent af6c057 commit 9049875
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/py_matter_idl/matter_idl/backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
from typing import Callable, Dict, List, Optional, Protocol, TypeVar

from matter_idl.matter_idl_types import Attribute, Bitmap, Cluster, Command, Enum, Event, Field, Idl, Struct
from matter_idl.matter_idl_types import ApiMaturity, Attribute, Bitmap, Cluster, Command, Enum, Event, Field, Idl, Struct


class Compatibility(enum.Enum):
Expand Down Expand Up @@ -52,6 +52,13 @@ def attribute_name(attribute: Attribute) -> str:
return attribute.definition.name


def not_stable(maturity: ApiMaturity):
"""Determine if the given api maturity allows binary/api changes or not."""
# TODO: internal and deprecated not currently widely used,
# so we enforce stability on them for now.
return maturity == ApiMaturity.PROVISIONAL


class CompatibilityChecker:
def __init__(self, original: Idl, updated: Idl):
self._original_idl = original
Expand Down Expand Up @@ -271,6 +278,11 @@ def _check_cluster_list_compatible(self, original: List[Cluster], updated: List[

for original_cluster in original:
updated_cluster = updated_clusters.get(original_cluster.name)

if not_stable(updated_cluster.api_maturity) or not_stable(original_cluster.api_maturity):
# no point in checking
continue

self._check_cluster_compatible(original_cluster, updated_cluster)

def _check_cluster_compatible(self, original_cluster: Cluster, updated_cluster: Optional[Cluster]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ def test_clusters_enum_add_remove(self):
"server cluster A = 16 { enum X : ENUM8 { A = 1; }}",
Compatibility.FORWARD_FAIL)

def test_provisional_cluster(self):
self.ValidateUpdate(
"Provisional cluster changes are ok.",
"provisional server cluster A = 16 { enum X : ENUM8 { A = 1; B = 2; } info event A = 1 { int8u x = 1;} }",
"provisional server cluster A = 16 { enum X : ENUM8 { A = 1; B = 3; } info event A = 2 { int16u x = 1;} }",
Compatibility.ALL_OK)

def test_clusters_enum_code(self):
self.ValidateUpdate(
"Adding an enum is ok. Also validates code formatting",
Expand Down

0 comments on commit 9049875

Please sign in to comment.