From 3624470b6d775f1a824fae74a2402e254a794282 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 15 Jan 2024 15:25:07 -0500 Subject: [PATCH] Add support for not complaining about abi changes in `provisional` clusters (#31372) * Ignore changes in provisional clusters for backwards compatibility * Restyle --- .../matter_idl/backwards_compatibility.py | 14 +++++++++++++- .../matter_idl/test_backwards_compatibility.py | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/py_matter_idl/matter_idl/backwards_compatibility.py b/scripts/py_matter_idl/matter_idl/backwards_compatibility.py index 9a6684c8031b9a..99adaf7a64bc0b 100644 --- a/scripts/py_matter_idl/matter_idl/backwards_compatibility.py +++ b/scripts/py_matter_idl/matter_idl/backwards_compatibility.py @@ -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): @@ -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 @@ -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]): diff --git a/scripts/py_matter_idl/matter_idl/test_backwards_compatibility.py b/scripts/py_matter_idl/matter_idl/test_backwards_compatibility.py index dece1632ac4719..e94e79abd5fce5 100755 --- a/scripts/py_matter_idl/matter_idl/test_backwards_compatibility.py +++ b/scripts/py_matter_idl/matter_idl/test_backwards_compatibility.py @@ -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",