Skip to content

Commit b578401

Browse files
authored
Render provisionality for commands and other elements (#72332)
* Update jinja and add test * Apply suggestion * Support parsing comments for elements with prefixes like "provisional"
1 parent 6abe092 commit b578401

3 files changed

Lines changed: 66 additions & 16 deletions

File tree

scripts/py_matter_idl/matter/idl/generators/idl/MatterIdl.jinja

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
optional ExtensionFieldSet extensionFieldSets[] = 5;
88
#}
99

10+
{{- field.api_maturity | idltxt -}}
1011
{%- if field.qualities %}{{field.qualities | idltxt}} {% endif -%}
1112
{{field.data_type.name}}
1213
{%- if field.data_type.max_length -%} <{{field.data_type.max_length}}> {%- endif -%}
@@ -18,6 +19,7 @@
1819
{% macro render_struct(s) -%}{#
1920
Macro for the output of a complete struct
2021
#}
22+
{{- s.api_maturity | idltxt -}}
2123
{%- if s.is_shared%}shared {% endif -%}
2224
{%- if s.tag %}{{s.tag | idltxt}} {% endif -%}
2325
{% if s.qualities %}{{s.qualities | idltxt}} {% endif -%}
@@ -42,18 +44,18 @@ struct {{s.name}} {##}
4244
// This IDL was auto-generated from a parsed data structure
4345

4446
{% for enum in idl.global_enums %}
45-
enum {{enum.name}} : {{ enum.base_type}} {
47+
{{enum.api_maturity | idltxt}}enum {{enum.name}} : {{ enum.base_type}} {
4648
{% for entry in enum.entries %}
47-
{{entry.name}} = {{entry.code}} {{-specification_name_clarification(entry)}};
49+
{{entry.api_maturity | idltxt}}{{entry.name}} = {{entry.code}} {{-specification_name_clarification(entry)}};
4850
{% endfor %}
4951
}
5052

5153
{% endfor %}
5254

5355
{%- for bitmap in idl.global_bitmaps %}
54-
bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
56+
{{bitmap.api_maturity | idltxt}}bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
5557
{% for entry in bitmap.entries %}
56-
{{entry.name}} = 0x{{"%X" | format(entry.code)}} {{-specification_name_clarification(entry)}};
58+
{{entry.api_maturity | idltxt}}{{entry.name}} = 0x{{"%X" | format(entry.code)}} {{-specification_name_clarification(entry)}};
5759
{% endfor %}
5860
}
5961

@@ -72,9 +74,9 @@ bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
7274

7375
{% for enum in cluster.enums | selectattr("is_global")%}
7476
/* GLOBAL:
75-
enum {{enum.name}} : {{ enum.base_type}} {
77+
{{enum.api_maturity | idltxt}}enum {{enum.name}} : {{ enum.base_type}} {
7678
{% for entry in enum.entries %}
77-
{{entry.name}} = {{entry.code}} {{-specification_name_clarification(entry)}};
79+
{{entry.api_maturity | idltxt}}{{entry.name}} = {{entry.code}} {{-specification_name_clarification(entry)}};
7880
{% endfor %}
7981
}
8082
*/
@@ -83,9 +85,9 @@ bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
8385

8486
{%- for bitmap in cluster.bitmaps | selectattr("is_global")%}
8587
/* GLOBAL:
86-
bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
88+
{{bitmap.api_maturity | idltxt}}bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
8789
{% for entry in bitmap.entries %}
88-
{{entry.name}} = 0x{{"%X" | format(entry.code)}} {{-specification_name_clarification(entry)}};
90+
{{entry.api_maturity | idltxt}}{{entry.name}} = 0x{{"%X" | format(entry.code)}} {{-specification_name_clarification(entry)}};
8991
{% endfor %}
9092
}
9193
*/
@@ -100,20 +102,22 @@ bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
100102
{% endfor %}
101103

102104
{%- for enum in cluster.enums | rejectattr("is_global")%}
103-
{%+ if enum.is_shared%}shared {% endif -%}
105+
{%+ if enum.api_maturity %}{{enum.api_maturity | idltxt}}{% endif -%}
106+
{%- if enum.is_shared%}shared {% endif -%}
104107
enum {{enum.name}} : {{ enum.base_type}} {
105108
{% for entry in enum.entries %}
106-
{{entry.name}} = {{entry.code}} {{-specification_name_clarification(entry)}};
109+
{{entry.api_maturity | idltxt}}{{entry.name}} = {{entry.code}} {{-specification_name_clarification(entry)}};
107110
{% endfor %}
108111
}
109112

110113
{% endfor %}
111114

112115
{%- for bitmap in cluster.bitmaps | rejectattr("is_global")%}
113-
{%+ if bitmap.is_shared%}shared {% endif -%}
116+
{%+ if bitmap.api_maturity %}{{bitmap.api_maturity | idltxt}}{% endif -%}
117+
{%- if bitmap.is_shared%}shared {% endif -%}
114118
bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
115119
{% for entry in bitmap.entries %}
116-
{{entry.name}} = 0x{{"%X" | format(entry.code)}} {{-specification_name_clarification(entry)}};
120+
{{entry.api_maturity | idltxt}}{{entry.name}} = 0x{{"%X" | format(entry.code)}} {{-specification_name_clarification(entry)}};
117121
{% endfor %}
118122
}
119123

@@ -152,7 +156,7 @@ bitmap {{bitmap.name}} : {{ bitmap.base_type}} {
152156
{% if c.description %}
153157
/** {{c.description}} */
154158
{% endif %}
155-
{{c.qualities | idltxt}}command {{c | command_access}}{{c.name}}(
159+
{{c.api_maturity | idltxt}}{{c.qualities | idltxt}}command {{c | command_access}}{{c.name}}(
156160
{%- if c.input_param %}{{c.input_param}}{% endif -%}
157161
): {{c.output_param}} = {{c.code}};
158162
{% endfor %}

scripts/py_matter_idl/matter/idl/matter_idl_parser.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def apply_to_idl(self, idl: Idl, content: str):
5050
return
5151

5252
actual_pos = self.start_pos + self.value_len
53-
while content[actual_pos] in ' \t\n\r':
53+
while actual_pos < len(content) and content[actual_pos] in ' \t\n\r':
5454
actual_pos += 1
5555

5656
# A doc comment will apply to any supported element assuming it immediately
@@ -505,10 +505,16 @@ def endpoint_server_cluster(self, meta, cluster_id, *content):
505505
return AddServerClusterToEndpointTransform(
506506
ServerClusterInstantiation(parse_meta=meta, name=cluster_id, attributes=attributes, events_emitted=events, commands=commands))
507507

508-
@v_args(inline=True)
509-
def cluster_content(self, api_maturity, element):
508+
@v_args(meta=True)
509+
def cluster_content(self, meta, args):
510+
api_maturity, element = args[0], args[1]
510511
if api_maturity is not None:
511512
element.api_maturity = api_maturity
513+
if not self.skip_meta:
514+
if isinstance(element, Attribute):
515+
element.definition.parse_meta = ParseMetaData(meta)
516+
elif hasattr(element, 'parse_meta'):
517+
element.parse_meta = ParseMetaData(meta)
512518
return element
513519

514520
@v_args(inline=True, meta=True)

scripts/py_matter_idl/matter/idl/test_idl_generator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,46 @@ def test_app_rendering(self):
134134
# checks that data types and content is the same
135135
self.assertEqual(idl, idl2)
136136

137+
def test_maturity_rendering(self):
138+
idl_content = """
139+
client cluster ProvisionalCluster = 1 {
140+
provisional struct ProvisionalStruct {
141+
provisional int16u provisionalField = 1;
142+
}
143+
144+
provisional enum ProvisionalEnum : ENUM16 {
145+
provisional kProvisionalValue = 0;
146+
}
147+
148+
provisional bitmap ProvisionalBitmap : BITMAP32 {
149+
provisional kProvisionalBit = 0x1;
150+
}
151+
152+
/** Test command description */
153+
provisional command ProvisionalCommand(): DefaultSuccess = 0;
154+
}
155+
"""
156+
# Parse and render (skip_meta must be False for comment parsing to work)
157+
parser = CreateParser(skip_meta=False, merge_globals=False)
158+
idl = parser.parse(idl_content)
159+
rendered = RenderAsIdlTxt(idl)
160+
161+
# Verify that maturity words are preserved in the rendered IDL
162+
self.assertIn("provisional struct ProvisionalStruct", rendered)
163+
self.assertIn("provisional int16u provisionalField = 1;", rendered)
164+
self.assertIn("provisional enum ProvisionalEnum", rendered)
165+
self.assertIn("provisional kProvisionalValue = 0;", rendered)
166+
self.assertIn("provisional bitmap ProvisionalBitmap", rendered)
167+
self.assertIn("provisional kProvisionalBit = 0x1;", rendered)
168+
self.assertIn("provisional command ProvisionalCommand(): DefaultSuccess = 0;", rendered)
169+
170+
# Verify that doc comment is matched and rendered correctly on the provisional command
171+
self.assertIn("/** Test command description */", rendered)
172+
173+
# Also ensure roundtrip parses back to the exact same IDL
174+
idl2 = parser.parse(rendered)
175+
self.assertEqual(idl, idl2)
176+
137177

138178
if __name__ == '__main__':
139179
unittest.main()

0 commit comments

Comments
 (0)