Skip to content

Commit

Permalink
Expose old names directly for Darwin codegen. (#869)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bzbarsky-apple authored Dec 20, 2022
1 parent 4f12354 commit 77fd67f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ module.exports = {
'/node_modules/',
'<rootDir>/test/download-artifact.test.js',
],
coveragePathIgnorePatterns: [
'/node_modules/',
'<rootDir>/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js',
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 77fd67f

Please sign in to comment.