Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Darwin name determination for global structs and enums. #1374

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this lead to backwards compatibility issues if someone has new zap and old gsdk?
Should these changes be tied to some classification of a new vs old gsdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't, because in old SDK there are no global structs and clusterName is never 'Globals'.

Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ async function asObjectiveCClass(type, cluster, options) {
}

if (isStruct) {
const structObj = await zclQuery.selectStructByName(
this.global.db,
type,
pkgIds
);
if (structObj.structClusterCount == 0) {
// This is a global struct.
return `${
options.hash.structTypePrefix || 'MTR'
}DataType${appHelper.asUpperCamelCase(type)}`;
}

if (options.hash.compatRemapClusterName) {
cluster = compatClusterNameRemapping.call(this, cluster, { hash: {} });
// If we are generating the "use the old name" API, here, and using the
Expand All @@ -265,7 +277,9 @@ async function asObjectiveCClass(type, cluster, options) {
});
}
// Use a custom prefix if specified, otherwise default to "MTR" for backwards compat.
return `${options.hash.structTypePrefix || "MTR"}${cluster}Cluster${appHelper.asUpperCamelCase(type)}`;
return `${
options.hash.structTypePrefix || 'MTR'
}${cluster}Cluster${appHelper.asUpperCamelCase(type)}`;
}

return 'NSNumber';
Expand Down Expand Up @@ -339,6 +353,12 @@ function commandHasRequiredField(command) {
* "Enum" bits on the enum names while we're here.
*/
function objCEnumName(clusterName, enumLabel, options) {
if (clusterName == 'Globals') {
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
// For global enums, just use "MTRDataType" followed by the label, without
// stripping "Enum" off the end or doing any other processing.
return 'MTRDataType' + enumLabel;
}

clusterName = appHelper.asUpperCamelCase(clusterName, {
hash: { preserveAcronyms: options.hash.preserveAcronyms },
});
Expand Down
Loading