Skip to content

Commit 2325138

Browse files
tehampsonbzbarsky-apple
authored andcommitted
Enums that are not used as a type in XML suppresses codegen intended for DataModel::Decode (#29739)
Co-authored-by: Boris Zbarsky <[email protected]>
1 parent fcc98e6 commit 2325138

File tree

8 files changed

+104
-168
lines changed

8 files changed

+104
-168
lines changed

src/app/common/templates/config-data.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ WeakEnums:
1010
- PHYRateEnum
1111
- StepMode
1212

13+
EnumsNotUsedAsTypeInXML:
14+
# List of enums that are not used as a type in XML. By adding an enum
15+
# to this list you prevent incorrectly assuming from code that you are
16+
# able to use kUnknownEnumValue safely. This happens for derived clusters
17+
# such as ModeBase where there are CommonTag, DerivedClusterTags, MfgTags.
18+
- "DishwasherMode::ModeTag"
19+
- "LaundryWasherMode::ModeTag"
20+
- "RefrigeratorAndTemperatureControlledCabinetMode::ModeTag"
21+
- "RvcRunMode::ModeTag"
22+
- "RvcRunMode::StatusCode"
23+
- "RvcCleanMode::ModeTag"
24+
- "RvcCleanMode::StatusCode"
25+
1326
CommandHandlerInterfaceOnlyClusters:
1427
# List of clusters that are implemented entirely with
1528
# CommandHandlerInterface and hence do not need generated command dispatch.

src/app/zap-templates/templates/app/cluster-enums-check.zapt

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace app {
99
namespace Clusters {
1010
{{#zcl_clusters}}
1111
{{#zcl_enums}}
12+
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
1213
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
1314
{
1415
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
@@ -33,6 +34,7 @@ static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../n
3334
return static_cast<EnumType>({{first_unused_enum_value mode="first_unused"}});
3435
}
3536
}
37+
{{/unless}}
3638
{{/zcl_enums}}
3739

3840
{{/zcl_clusters}}

src/app/zap-templates/templates/app/cluster-enums.zapt

+8
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ enum class {{asType label}} : {{asUnderlyingZclType name}} {
2424
{{#zcl_enum_items}}
2525
k{{asUpperCamelCase label}} = {{asHex value 2}},
2626
{{/zcl_enum_items}}
27+
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
2728
// All received enum values that are not listed above will be mapped
2829
// to kUnknownEnumValue. This is a helper enum value that should only
2930
// be used by code to process how it handles receiving and unknown
3031
// enum value. This specific should never be transmitted.
3132
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
33+
{{else}}
34+
// kUnknownEnumValue intentionally not defined. This enum never goes
35+
// through DataModel::Decode, likely because it is a part of a derived
36+
// cluster. As a result having kUnknownEnumValue in this enum is error
37+
// prone, and was removed. See
38+
// src/app/common/templates/config-data.yaml.
39+
{{/unless}}
3240
};
3341
{{#if (isInConfigList label "WeakEnums")}}
3442
#else // CHIP_USE_ENUM_CLASS_FOR_IM_ENUM

src/controller/python/chip/clusters/Objects.py

+35-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controller/python/templates/python-cluster-Objects-py.zapt

+8
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ class {{asUpperCamelCase name}}(Cluster):
5454
{{#zcl_enum_items}}
5555
k{{asUpperCamelCase label}} = {{asHex value 2}}
5656
{{/zcl_enum_items}}
57+
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
5758
# All received enum values that are not listed above will be mapped
5859
# to kUnknownEnumValue. This is a helper enum value that should only
5960
# be used by code to process how it handles receiving and unknown
6061
# enum value. This specific should never be transmitted.
6162
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
63+
{{else}}
64+
# kUnknownEnumValue intentionally not defined. This enum never goes
65+
# through DataModel::Decode, likely because it is a part of a derived
66+
# cluster. As a result having kUnknownEnumValue in this enum is error
67+
# prone, and was removed. See
68+
# src/app/common/templates/config-data.yaml.
69+
{{/unless}}
6270

6371
{{#last}}
6472
{{/last}}

src/controller/python/templates/templates.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"templates/chip/helper.js",
99
"controller/python/templates/helper.js"
1010
],
11+
"resources": {
12+
"config-data": "../../../../src/app/common/templates/config-data.yaml"
13+
},
1114
"override": "../../../../src/app/zap-templates/common/override.js",
1215
"partials": [
1316
{

zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h

-98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)