Skip to content

Commit

Permalink
[matter_idl] Always add global attributes to the cluster attributes l…
Browse files Browse the repository at this point in the history
…ist (#25031)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 14, 2023
1 parent 7f03354 commit 008ff46
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ jobs:
# does not enforce that the content is understood (that part is covered by parser
# unit tests)
#
# Also note ordering: global attributes are parsed first because other XML files may
# reference these.
#
# TODO: some multipass/postprocess may be more appropriate to allow any ordering of
# things.
run: |
./scripts/run_in_build_env.sh \
"./scripts/py_matter_idl/matter_idl/xml_parser.py \
Expand Down
10 changes: 8 additions & 2 deletions scripts/py_matter_idl/matter_idl/zapxml/handlers/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def GetGlobalAttribute(self, code):
raise Exception(
'Global attribute 0x%X (%d) not found. You probably need to load global-attributes.xml' % (code, code))

def GetGlobalAttributes(self):
return [attribute for code, attribute in self._global_attributes.items()]

def AddGlobalAttribute(self, attribute: Attribute):
# NOTE: this may get added several times as both 'client' and 'server'
# however matter should not differentiate between the two
Expand All @@ -131,8 +134,11 @@ def MarkTagNotHandled(self):
logging.warning(msg)
self._not_handled.add(path)

def AddIdlPostProcessor(self, processor: IdlPostProcessor):
self._idl_post_processors.append(processor)
def AddIdlPostProcessor(self, processor: IdlPostProcessor, has_priority: bool = False):
if has_priority:
self._idl_post_processors.insert(0, processor)
else:
self._idl_post_processors.append(processor)

def PostProcess(self, idl: Idl):
for p in self._idl_post_processors:
Expand Down
19 changes: 18 additions & 1 deletion scripts/py_matter_idl/matter_idl/zapxml/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,19 @@ def GetNextProcessor(self, name: str, attrs):
else:
return BaseHandler(self.context)

def EndProcessing(self):
def FinalizeProcessing(self, idl: Idl):
for attribute in self._cluster.attributes:
if attribute.definition.code == self._code:
# NOTE: For now the value is ignored, but if needed it could
# be updated here.
return

self._cluster.attributes.append(
self.context.GetGlobalAttribute(self._code))

def EndProcessing(self):
self.context.AddIdlPostProcessor(self)


class ClusterHandler(BaseHandler):
"""Handles /configurator/cluster elements."""
Expand Down Expand Up @@ -582,6 +591,14 @@ def GetNextProcessor(self, name, attrs):
else:
return BaseHandler(self.context)

def FinalizeProcessing(self, idl: Idl):
global_attributes = self.context.GetGlobalAttributes()
for cluster in idl.clusters:
cluster.attributes += global_attributes

def EndProcessing(self):
self.context.AddIdlPostProcessor(self, True)


class ConfiguratorHandler(BaseHandler):
""" Handling /configurator elements."""
Expand Down
14 changes: 0 additions & 14 deletions scripts/py_matter_yamltests/matter_yamltests/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

import enum
import functools
import glob
import io
from typing import List, Optional
Expand Down Expand Up @@ -244,26 +243,13 @@ def __enforce_casing(self, target_name: str, targets: list):


def SpecDefinitionsFromPaths(paths: str, pseudo_clusters: Optional[PseudoClusters] = PseudoClusters([])):
def sort_with_global_attribute_first(a, b):
if a.endswith('global-attributes.xml'):
return -1
elif b.endswith('global-attributes.xml'):
return 1
elif a > b:
return 1
elif a == b:
return 0
elif a < b:
return -1

filenames = []
for path in paths:
if '*' in path or '?' in path:
filenames.extend(glob.glob(path, recursive=False))
else:
filenames.append(path)

filenames.sort(key=functools.cmp_to_key(sort_with_global_attribute_first))
sources = [ParseSource(source=name) for name in filenames]

for pseudo_cluster in pseudo_clusters.clusters:
Expand Down

0 comments on commit 008ff46

Please sign in to comment.