From dd1e60f073d1819b510c1b28fcbd3c836db158ba Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 16 May 2023 10:40:54 -0400 Subject: [PATCH] Treat introduction after ancestor deprecation as lack of support for Darwin. (#1026) If something gets renamed and the old name is deprecated, then a new thing inside the renamed thing is added (e.g. a new value for an enum that got renamed), we should not generate the new thing combined with the old name. --- .../darwin/Framework/CHIP/templates/helper.js | 74 +++++++++++++------ 1 file changed, 51 insertions(+), 23 deletions(-) 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 065fcee988..21a83797d9 100644 --- a/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js +++ b/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js @@ -589,6 +589,42 @@ function findPathToContainer(availabilityPath) { } } +/** + * Finds the release in which this path, or one of its ancestors, was + * deprecated, if such a release exists. If no such release exists, returns + * undefined. + */ +function findDeprecationRelease(global, path, options) { + if (path === undefined) { + return undefined; + } + + const data = fetchAvailabilityData(global); + let deprecatedRelease = undefined; + let deprecationPath = [...path]; + while (deprecatedRelease === undefined && deprecationPath != undefined) { + deprecatedRelease = findReleaseForPath( + data, + ['deprecated', ...deprecationPath], + options + ); + deprecationPath = findPathToContainer(deprecationPath); + } + if (options.hash.deprecatedRelease) { + let minimalDeprecatedRelease = findReleaseByName( + data, + options.hash.deprecatedRelease + ); + if ( + deprecatedRelease === undefined || + data.indexOf(deprecatedRelease) > data.indexOf(minimalDeprecatedRelease) + ) { + deprecatedRelease = minimalDeprecatedRelease; + } + } + return deprecatedRelease; +} + async function availability(clusterName, options) { const data = fetchAvailabilityData(this.global); const path = makeAvailabilityPath(clusterName, options); @@ -636,28 +672,7 @@ async function availability(clusterName, options) { } let introducedVersions = introducedRelease?.versions; - let deprecatedRelease = undefined; - let deprecationPath = [...path]; - while (deprecatedRelease === undefined && deprecationPath != undefined) { - deprecatedRelease = findReleaseForPath( - data, - ['deprecated', ...deprecationPath], - options - ); - deprecationPath = findPathToContainer(deprecationPath); - } - if (options.hash.deprecatedRelease) { - let minimalDeprecatedRelease = findReleaseByName( - data, - options.hash.deprecatedRelease - ); - if ( - deprecatedRelease === undefined || - data.indexOf(deprecatedRelease) > data.indexOf(minimalDeprecatedRelease) - ) { - deprecatedRelease = minimalDeprecatedRelease; - } - } + let deprecatedRelease = findDeprecationRelease(this.global, path, options); const deprecatedVersions = deprecatedRelease?.versions; if (introducedVersions === undefined && deprecatedVersions !== undefined) { @@ -842,17 +857,30 @@ function pathsEqual(path1, path2) { } function isSupported(cluster, options) { + // Things that are removed are not supported. if (wasRemoved.call(this, cluster, options)) { return false; } + // Things that have a deprecated container and were not introduced before the + // deprecation are not supported. + let path = makeAvailabilityPath(cluster, options); + let deprecationRelease = findDeprecationRelease(this.global, findPathToContainer(path), options); + if (deprecationRelease !== undefined) { + let comparisonStatus = compareIntroductionToReferenceRelease(this.global, path, options, deprecationRelease); + // The only case where we might be supported is if we have an explicit + // introduction and the introduction comes before the ancestor deprecation. + if (comparisonStatus != -1) { + return false; + } + } + let provisionalRelease = findReleaseForPathOrAncestorAndSection(this.global, cluster, options, 'provisional'); if (provisionalRelease === undefined) { // Default to enabled, even if not explicitly introduced. return true; } - let path = makeAvailabilityPath(cluster, options); while (path !== undefined) { let comparisonStatus = compareIntroductionToReferenceRelease( this.global,