Skip to content

Commit

Permalink
Fix codegen randomness for chip-tool-darwin. (#18276)
Browse files Browse the repository at this point in the history
We had a race as to who initialized ChipClusters first: the test
generation code (which used includeAll=true) or the command-generation
code (which did not).  Since the first init decides the behavior
things were random.

The fix is to consistently use includeAll=true in all of the bits in
chip-tool and chip-tool-darwin, since that's the desired behavior
anyway.
  • Loading branch information
bzbarsky-apple authored May 10, 2022
1 parent 837b939 commit 582a3a2
Show file tree
Hide file tree
Showing 9 changed files with 53,902 additions and 25,702 deletions.
2 changes: 1 addition & 1 deletion examples/chip-tool-darwin/templates/README.zapt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Command Details

{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#chip_cluster_commands}}
{{#first}}
<details><summary>{{parent.name}}</summary><p>
Expand Down
9 changes: 5 additions & 4 deletions examples/chip-tool-darwin/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{{> clusters_header}}

{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{> cluster_header}}

{{#chip_cluster_commands}}
Expand All @@ -30,6 +30,7 @@ class {{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}: public ClusterC
public:
{{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}(): ClusterCommand("{{asDelimitedCommand name}}"){{#zcl_command_arguments}}{{#if_chip_complex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if_chip_complex}}{{/zcl_command_arguments}}
{
(void)mRequest; // Might not be used if we have no complex args
{{#chip_cluster_command_arguments}}
{{#if_chip_complex}}
AddArgument("{{asUpperCamelCase label}}", &mComplex_{{asUpperCamelCase label}});
Expand Down Expand Up @@ -106,9 +107,9 @@ public:
}

private:
chip::app::Clusters::{{asUpperCamelCase clusterName}}::Commands::{{asUpperCamelCase name}}::Type mRequest;
{{#chip_cluster_command_arguments}}
{{#if_chip_complex}}
chip::app::Clusters::{{asUpperCamelCase parent.clusterName}}::Commands::{{asUpperCamelCase parent.name}}::Type mRequest;
TypedComplexArgument<{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}> mComplex_{{asUpperCamelCase label}};
{{else if (isString type)}}
{{#if isOptional}}chip::Optional<chip::ByteSpan>{{else}}chip::ByteSpan{{/if}} m{{asUpperCamelCase label}};
Expand Down Expand Up @@ -281,7 +282,7 @@ public:
/*----------------------------------------------------------------------------*\
| Register all Clusters commands |
\*----------------------------------------------------------------------------*/
{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
void registerCluster{{asUpperCamelCase name}}(Commands & commands)
{
using namespace chip::app::Clusters::{{asUpperCamelCase name}};
Expand Down Expand Up @@ -335,7 +336,7 @@ void registerClusterAny(Commands & commands)
void registerClusters(Commands & commands)
{
registerClusterAny(commands);
{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
registerCluster{{asUpperCamelCase name}}(commands);
{{/chip_client_clusters}}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{#if (chip_has_client_clusters)}}
{{> header}}
#import <Foundation/Foundation.h>
#import <CHIP/CHIPError_Internal.h>
Expand All @@ -18,7 +17,7 @@ using chip::Callback::Callback;
using chip::Callback::Cancelable;
using namespace chip::app::Clusters;

{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}

@interface CHIPTest{{asUpperCamelCase name}} ()
@property (readonly) chip::Controller::{{asUpperCamelCase name}}ClusterTest cppCluster;
Expand Down Expand Up @@ -61,4 +60,3 @@ using namespace chip::app::Clusters;
@end

{{/chip_client_clusters}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{#if (chip_has_client_clusters)}}
{{> header}}

#import <CHIP/CHIPClustersObjc.h>
Expand All @@ -7,7 +6,7 @@

NS_ASSUME_NONNULL_BEGIN

{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}

/**
* Cluster {{name}}
Expand All @@ -26,4 +25,3 @@ NS_ASSUME_NONNULL_BEGIN
{{/chip_client_clusters}}

NS_ASSUME_NONNULL_END
{{/if}}
8 changes: 4 additions & 4 deletions examples/chip-tool/templates/logging/DataModelLogger-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{
{{/zcl_events}}
{{/zcl_clusters}}

{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#zcl_commands_source_server}}
CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & value)
{
Expand All @@ -67,7 +67,7 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP

switch (path.mClusterId)
{
{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#zcl_attributes_server}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
Expand Down Expand Up @@ -102,7 +102,7 @@ CHIP_ERROR DataModelLogger::LogCommand(const chip::app::ConcreteCommandPath & pa

switch (path.mClusterId)
{
{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#zcl_commands_source_server}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
Expand Down Expand Up @@ -158,7 +158,7 @@ CHIP_ERROR DataModelLogger::LogEvent(const chip::app::EventHeader & header, chip

switch (header.mPath.mClusterId)
{
{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#chip_server_cluster_events}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/templates/logging/DataModelLogger.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::C
{{/zcl_events}}
{{/zcl_clusters}}

{{#chip_client_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#zcl_commands_source_server}}
static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & value);
{{/zcl_commands_source_server}}
Expand Down
Loading

0 comments on commit 582a3a2

Please sign in to comment.