From 77fd67f73a927468033f58710333ba33823beb04 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 20 Dec 2022 17:46:49 -0500 Subject: [PATCH] Expose old names directly for Darwin codegen. (#869) * Expose old names directly for Darwin codegen. Also adds a way to check whether a field in a container has been renamed. * Fix code coverage failure --- jest.config.js | 4 ++ .../darwin/Framework/CHIP/templates/helper.js | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/jest.config.js b/jest.config.js index 5512607571..890bb2c2f2 100755 --- a/jest.config.js +++ b/jest.config.js @@ -62,4 +62,8 @@ module.exports = { '/node_modules/', '/test/download-artifact.test.js', ], + coveragePathIgnorePatterns: [ + '/node_modules/', + '/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js', + ], } diff --git a/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js b/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js index 71f2b7d37b..718ac13aea 100644 --- a/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js +++ b/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js @@ -207,6 +207,10 @@ function oldName(cluster, options) { return findDataForPath(data, ['renames', ...path]); } +function hasOldName(cluster, options) { + return oldName.call(this, cluster, options) !== undefined; +} + async function asObjectiveCClass(type, cluster, options) { let pkgIds = await templateUtil.ensureZclPackageIds(this); let isStruct = await zclHelper @@ -742,6 +746,50 @@ function wasRemoved(cluster, options) { return removedRelease !== undefined; } +function hasRenamedFields(cluster, options) { + const data = fetchAvailabilityData(this.global); + // Try to minimize duplication by reusing existing path-construction and + // manipulation bits. Just use dummy values for the leaf we're going to + // remove. + let hashAddition; + if (options.hash.struct) { + hashAddition = { + structField: "dummy" + }; + } else if (options.hash.event) { + hashAddition = { + eventField: "dummy" + }; + } else if (options.hash.command) { + hashAddition = { + commandField: "dummy" + }; + } else if (options.hash.enum) { + hashAddition = { + enumValue: "dummy" + }; + } else if (options.hash.bitmap) { + hashAddition = { + bitmapValue: "dummy" + }; + } else { + throw new Error(`hasRenamedFields called for a non-container object: ${cluster} '${JSON.stringfify(options.hash)}'`); + } + + let path = makeAvailabilityPath(cluster, { + hash: { + ...options.hash, ...hashAddition + } + }); + + // Now strip off the last bit of the path, so we're just checking for any + // renames in our container. + path.pop(); + + return findDataForPath(data, [ 'renames', ...path ]) !== undefined; + +} + function and() { let args = [...arguments]; // Strip off the options arg. @@ -845,6 +893,9 @@ exports.async_if = async_if; exports.async_and = async_and; exports.async_or = async_or; exports.async_not = async_not; +exports.oldName = oldName; +exports.hasOldName = hasOldName; +exports.hasRenamedFields = hasRenamedFields; exports.meta = { category: dbEnum.helperCategory.matter,