Skip to content
代码片段 群组 项目
未验证 提交 d3e77310 编辑于 作者: Philip Gregor's avatar Philip Gregor 提交者: GitHub
浏览文件

ZAP generation js helper (#1270)


* tv-casting-app: ZAP generation js helper

* Update src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js

Commit suggestion by bzbarsky-apple

Co-authored-by: default avatarBoris Zbarsky <bzbarsky@apple.com>
上级 002a6bc4
No related branches found
No related tags found
无相关合并请求
...@@ -222,7 +222,9 @@ async function asObjectiveCClass(type, cluster, options) { ...@@ -222,7 +222,9 @@ async function asObjectiveCClass(type, cluster, options) {
!options.hash.forceNotList !options.hash.forceNotList
) { ) {
if (options.hash.stronglyTypedArrays) { if (options.hash.stronglyTypedArrays) {
let innerType = await asObjectiveCClass.call(this, type, cluster, { hash: { ...options.hash, forceNotList: true }}); let innerType = await asObjectiveCClass.call(this, type, cluster, {
hash: { ...options.hash, forceNotList: true },
});
return `NSArray<${innerType} *>`; return `NSArray<${innerType} *>`;
} }
...@@ -262,7 +264,8 @@ async function asObjectiveCClass(type, cluster, options) { ...@@ -262,7 +264,8 @@ async function asObjectiveCClass(type, cluster, options) {
hash: { preserveAcronyms: preserveAcronyms }, hash: { preserveAcronyms: preserveAcronyms },
}); });
} }
return `MTR${cluster}Cluster${appHelper.asUpperCamelCase(type)}`; // Use a custom prefix if specified, otherwise default to "MTR" for backwards compat.
return `${options.hash.structTypePrefix || "MTR"}${cluster}Cluster${appHelper.asUpperCamelCase(type)}`;
} }
return 'NSNumber'; return 'NSNumber';
...@@ -707,7 +710,12 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -707,7 +710,12 @@ async function availabilityHelper(clusterName, language, options) {
} }
if (introducedVersions === undefined) { if (introducedVersions === undefined) {
const provisionalRelease = findProvisionalRelease(this.global, clusterName, options, 'provisional'); const provisionalRelease = findProvisionalRelease(
this.global,
clusterName,
options,
'provisional'
);
if (!provisionalRelease) { if (!provisionalRelease) {
console.log( console.log(
`WARNING: Missing "introduced" or "provisional" entry for: '${clusterName}' '${JSON.stringify( `WARNING: Missing "introduced" or "provisional" entry for: '${clusterName}' '${JSON.stringify(
...@@ -718,14 +726,14 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -718,14 +726,14 @@ async function availabilityHelper(clusterName, language, options) {
} }
const provisionalAvailability = (() => { const provisionalAvailability = (() => {
if (language == "ObjC") { if (language == 'ObjC') {
return 'MTR_PROVISIONALLY_AVAILABLE'; return 'MTR_PROVISIONALLY_AVAILABLE';
} }
if (language == "Swift") { if (language == 'Swift') {
// For now, we are stuck with Swift versions in Matter CI that do not // For now, we are stuck with Swift versions in Matter CI that do not
// support wrapping attributes in conditional compilation. // support wrapping attributes in conditional compilation.
return '@available(iOS, unavailable) @available(macOS, unavailable) @available(tvOS, unavailable) @available(watchOS, unavailable)' return '@available(iOS, unavailable) @available(macOS, unavailable) @available(tvOS, unavailable) @available(watchOS, unavailable)';
/* /*
return `#if MTR_ENABLE_PROVISIONAL return `#if MTR_ENABLE_PROVISIONAL
#else #else
...@@ -735,7 +743,9 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -735,7 +743,9 @@ async function availabilityHelper(clusterName, language, options) {
*/ */
} }
throw new Error(`Unknown language ${language}; cannot determine availability syntax.`); throw new Error(
`Unknown language ${language}; cannot determine availability syntax.`
);
})(); })();
if (isProvisional.call(this, clusterName, options)) { if (isProvisional.call(this, clusterName, options)) {
...@@ -743,15 +753,15 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -743,15 +753,15 @@ async function availabilityHelper(clusterName, language, options) {
} }
const futureAvailability = (() => { const futureAvailability = (() => {
if (language == "ObjC") { if (language == 'ObjC') {
return 'MTR_NEWLY_AVAILABLE'; return 'MTR_NEWLY_AVAILABLE';
} }
return '' return '';
})(); })();
if (introducedVersions === 'future') { if (introducedVersions === 'future') {
if (language == "ObjC") { if (language == 'ObjC') {
return futureAvailability; return futureAvailability;
} }
...@@ -763,21 +773,21 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -763,21 +773,21 @@ async function availabilityHelper(clusterName, language, options) {
} }
if (deprecatedVersions === undefined) { if (deprecatedVersions === undefined) {
if (language == "ObjC") { if (language == 'ObjC') {
let availabilityStrings = Object.entries(introducedVersions).map( let availabilityStrings = Object.entries(introducedVersions).map(
([os, version]) => `${os.toLowerCase()}(${version})` ([os, version]) => `${os.toLowerCase()}(${version})`
); );
return `MTR_AVAILABLE(${availabilityStrings.join(', ')})`; return `MTR_AVAILABLE(${availabilityStrings.join(', ')})`;
} }
if (language == "Swift") { if (language == 'Swift') {
let availabilityStrings = Object.entries(introducedVersions).map( let availabilityStrings = Object.entries(introducedVersions).map(
([os, version]) => `${os} ${version}` ([os, version]) => `${os} ${version}`
); );
// For now, we are stuck with Swift versions in Matter CI that do not // For now, we are stuck with Swift versions in Matter CI that do not
// support wrapping attributes in conditional compilation. // support wrapping attributes in conditional compilation.
return `@available(${availabilityStrings.join(', ')}, *)` return `@available(${availabilityStrings.join(', ')}, *)`;
/* /*
return `#if MTR_NO_AVAILABILITY return `#if MTR_NO_AVAILABILITY
#else #else
@available(${availabilityStrings.join(', ')}, *) @available(${availabilityStrings.join(', ')}, *)
...@@ -787,7 +797,7 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -787,7 +797,7 @@ async function availabilityHelper(clusterName, language, options) {
} }
} }
if (language != "ObjC") { if (language != 'ObjC') {
throw new Error(`Deprecation not supported for native Swift APIs yet.`); throw new Error(`Deprecation not supported for native Swift APIs yet.`);
} }
...@@ -847,7 +857,8 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -847,7 +857,8 @@ async function availabilityHelper(clusterName, language, options) {
} }
let availabilityStrings = Object.entries(introducedVersions).map( let availabilityStrings = Object.entries(introducedVersions).map(
([os, version]) => `${os.toLowerCase()}(${version}, ${deprecatedVersions[os]})` ([os, version]) =>
`${os.toLowerCase()}(${version}, ${deprecatedVersions[os]})`
); );
return `MTR_DEPRECATED("${ return `MTR_DEPRECATED("${
options.hash.deprecationMessage options.hash.deprecationMessage
...@@ -855,11 +866,11 @@ async function availabilityHelper(clusterName, language, options) { ...@@ -855,11 +866,11 @@ async function availabilityHelper(clusterName, language, options) {
} }
async function availability(clusterName, options) { async function availability(clusterName, options) {
return availabilityHelper.call(this, clusterName, "ObjC", options); return availabilityHelper.call(this, clusterName, 'ObjC', options);
} }
async function swiftAvailability(clusterName, options) { async function swiftAvailability(clusterName, options) {
return availabilityHelper.call(this, clusterName, "Swift", options); return availabilityHelper.call(this, clusterName, 'Swift', options);
} }
/** /**
...@@ -871,7 +882,12 @@ async function swiftAvailability(clusterName, options) { ...@@ -871,7 +882,12 @@ async function swiftAvailability(clusterName, options) {
* *
* Throws if referenceRelease is not defined. * Throws if referenceRelease is not defined.
*/ */
function compareIntroductionToReferenceRelease(global, path, options, referenceRelease) { function compareIntroductionToReferenceRelease(
global,
path,
options,
referenceRelease
) {
if (referenceRelease === undefined) { if (referenceRelease === undefined) {
throw new Error("Can't compare to non-existent release"); throw new Error("Can't compare to non-existent release");
} }
...@@ -912,7 +928,8 @@ function wasIntroducedBeforeRelease(releaseName, clusterName, options) { ...@@ -912,7 +928,8 @@ function wasIntroducedBeforeRelease(releaseName, clusterName, options) {
let comparisonStatus = compareIntroductionToReferenceRelease( let comparisonStatus = compareIntroductionToReferenceRelease(
this.global, this.global,
makeAvailabilityPath(clusterName, options), makeAvailabilityPath(clusterName, options),
options, referenceRelease options,
referenceRelease
); );
if (comparisonStatus === undefined) { if (comparisonStatus === undefined) {
// Not introduced yet, so not introduced before anything in particular. // Not introduced yet, so not introduced before anything in particular.
...@@ -928,16 +945,17 @@ function wasIntroducedBeforeRelease(releaseName, clusterName, options) { ...@@ -928,16 +945,17 @@ function wasIntroducedBeforeRelease(releaseName, clusterName, options) {
* the release and the path that ended up being found, or undefined if nothing * the release and the path that ended up being found, or undefined if nothing
* was found. * was found.
*/ */
function findReleaseForPathOrAncestorAndSection(global, cluster, options, section) { function findReleaseForPathOrAncestorAndSection(
global,
cluster,
options,
section
) {
const data = fetchAvailabilityData(global); const data = fetchAvailabilityData(global);
let path = makeAvailabilityPath(cluster, options); let path = makeAvailabilityPath(cluster, options);
while (path !== undefined) { while (path !== undefined) {
let foundRelease = findReleaseForPath( let foundRelease = findReleaseForPath(data, [section, ...path], options);
data,
[section, ...path],
options
);
if (foundRelease !== undefined) { if (foundRelease !== undefined) {
return { release: foundRelease, path: path }; return { release: foundRelease, path: path };
} }
...@@ -947,7 +965,14 @@ function findReleaseForPathOrAncestorAndSection(global, cluster, options, sectio ...@@ -947,7 +965,14 @@ function findReleaseForPathOrAncestorAndSection(global, cluster, options, sectio
} }
function wasRemoved(cluster, options) { function wasRemoved(cluster, options) {
return findReleaseForPathOrAncestorAndSection(this.global, cluster, options, 'removed') !== undefined; return (
findReleaseForPathOrAncestorAndSection(
this.global,
cluster,
options,
'removed'
) !== undefined
);
} }
function pathsEqual(path1, path2) { function pathsEqual(path1, path2) {
...@@ -973,9 +998,18 @@ function isSupported(cluster, options) { ...@@ -973,9 +998,18 @@ function isSupported(cluster, options) {
// Things that have a deprecated container and were not introduced before the // Things that have a deprecated container and were not introduced before the
// deprecation are not supported. // deprecation are not supported.
let path = makeAvailabilityPath(cluster, options); let path = makeAvailabilityPath(cluster, options);
let deprecationRelease = findDeprecationRelease(this.global, findPathToContainer(path), options); let deprecationRelease = findDeprecationRelease(
this.global,
findPathToContainer(path),
options
);
if (deprecationRelease !== undefined) { if (deprecationRelease !== undefined) {
let comparisonStatus = compareIntroductionToReferenceRelease(this.global, path, options, deprecationRelease); let comparisonStatus = compareIntroductionToReferenceRelease(
this.global,
path,
options,
deprecationRelease
);
// The only case where we might be supported is if we have an explicit // The only case where we might be supported is if we have an explicit
// introduction and the introduction comes before the ancestor deprecation. // introduction and the introduction comes before the ancestor deprecation.
if (comparisonStatus != -1) { if (comparisonStatus != -1) {
...@@ -987,7 +1021,12 @@ function isSupported(cluster, options) { ...@@ -987,7 +1021,12 @@ function isSupported(cluster, options) {
} }
function findProvisionalRelease(global, cluster, options) { function findProvisionalRelease(global, cluster, options) {
let provisionalRelease = findReleaseForPathOrAncestorAndSection(global, cluster, options, 'provisional'); let provisionalRelease = findReleaseForPathOrAncestorAndSection(
global,
cluster,
options,
'provisional'
);
if (provisionalRelease !== undefined) { if (provisionalRelease !== undefined) {
return provisionalRelease; return provisionalRelease;
} }
...@@ -1002,12 +1041,18 @@ function findProvisionalRelease(global, cluster, options) { ...@@ -1002,12 +1041,18 @@ function findProvisionalRelease(global, cluster, options) {
return findReleaseForPathOrAncestorAndSection( return findReleaseForPathOrAncestorAndSection(
global, global,
/* cluster does not apply to global attributes */ /* cluster does not apply to global attributes */
"", '',
/* /*
* Keep our options (e.g. in terms of isForIds bits), but replace * Keep our options (e.g. in terms of isForIds bits), but replace
* attribute with globalAttribute. * attribute with globalAttribute.
*/ */
{ hash: { ...options.hash, attribute: undefined, globalAttribute: attrName } }, {
hash: {
...options.hash,
attribute: undefined,
globalAttribute: attrName,
},
},
'provisional' 'provisional'
); );
} }
...@@ -1019,14 +1064,19 @@ function isProvisional(cluster, options) { ...@@ -1019,14 +1064,19 @@ function isProvisional(cluster, options) {
let introducedRelease = findReleaseForPath( let introducedRelease = findReleaseForPath(
data, data,
['introduced', ...path], ['introduced', ...path],
options); options
);
if (introducedRelease == undefined) { if (introducedRelease == undefined) {
// If it's not introduced, default to provisional. // If it's not introduced, default to provisional.
return true; return true;
} }
let provisionalRelease = findProvisionalRelease(this.global, cluster, options); let provisionalRelease = findProvisionalRelease(
this.global,
cluster,
options
);
if (provisionalRelease === undefined) { if (provisionalRelease === undefined) {
return false; return false;
} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册