From 9da9302fc1f2d54694054443c877956728849fb0 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 14 Jan 2022 20:57:28 -0500 Subject: [PATCH] Move IDL files *.matter to reside together with input zap files (#13603) * A first version of regen all which renames matter IDLs to sit along with source zap file * Re-generate zap (which moves Clusters.matter to stay with zap files) --- .../all-clusters-app.matter | 0 .../bridge-common/bridge-app.matter | 0 .../door-lock-common/door-lock-app.matter | 0 .../lighting-common/lighting-app.matter | 0 .../lock-app/lock-common/lock-app.matter | 0 .../log-source-common/log-source-app.matter | 0 .../ota-provider-app.matter | 0 .../ota-requestor-app.matter | 0 .../placeholder/linux/apps/app1/config.matter | 0 .../placeholder/linux/apps/app2/config.matter | 0 .../pump-app/pump-common/pump-app.matter | 0 .../pump-controller-app.matter | 0 .../esp32/main/temperature-measurement.matter | 0 .../thermostat-common/thermostat.matter | 0 .../tv-app/tv-common/tv-app.matter | 0 .../tv-casting-common/tv-casting-app.matter | 0 .../window-app/common/window-app.matter | 0 scripts/tools/zap_regen_all.py | 77 +++++++++++++++---- .../data_model/controller-clusters.matter | 0 19 files changed, 63 insertions(+), 14 deletions(-) rename zzz_generated/all-clusters-app/zap-generated/Clusters.matter => examples/all-clusters-app/all-clusters-common/all-clusters-app.matter (100%) rename zzz_generated/bridge-app/zap-generated/Clusters.matter => examples/bridge-app/bridge-common/bridge-app.matter (100%) rename zzz_generated/door-lock-app/zap-generated/Clusters.matter => examples/door-lock-app/door-lock-common/door-lock-app.matter (100%) rename zzz_generated/lighting-app/zap-generated/Clusters.matter => examples/lighting-app/lighting-common/lighting-app.matter (100%) rename zzz_generated/lock-app/zap-generated/Clusters.matter => examples/lock-app/lock-common/lock-app.matter (100%) rename zzz_generated/log-source-app/zap-generated/Clusters.matter => examples/log-source-app/log-source-common/log-source-app.matter (100%) rename zzz_generated/ota-provider-app/zap-generated/Clusters.matter => examples/ota-provider-app/ota-provider-common/ota-provider-app.matter (100%) rename zzz_generated/ota-requestor-app/zap-generated/Clusters.matter => examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter (100%) rename zzz_generated/placeholder/app1/zap-generated/Clusters.matter => examples/placeholder/linux/apps/app1/config.matter (100%) rename zzz_generated/placeholder/app2/zap-generated/Clusters.matter => examples/placeholder/linux/apps/app2/config.matter (100%) rename zzz_generated/pump-app/zap-generated/Clusters.matter => examples/pump-app/pump-common/pump-app.matter (100%) rename zzz_generated/pump-controller-app/zap-generated/Clusters.matter => examples/pump-controller-app/pump-controller-common/pump-controller-app.matter (100%) rename zzz_generated/temperature-measurement-app/zap-generated/Clusters.matter => examples/temperature-measurement-app/esp32/main/temperature-measurement.matter (100%) rename zzz_generated/thermostat/zap-generated/Clusters.matter => examples/thermostat/thermostat-common/thermostat.matter (100%) rename zzz_generated/tv-app/zap-generated/Clusters.matter => examples/tv-app/tv-common/tv-app.matter (100%) rename zzz_generated/tv-casting-app/zap-generated/Clusters.matter => examples/tv-casting-app/tv-casting-common/tv-casting-app.matter (100%) rename zzz_generated/window-app/zap-generated/Clusters.matter => examples/window-app/common/window-app.matter (100%) rename zzz_generated/controller-clusters/zap-generated/Clusters.matter => src/controller/data_model/controller-clusters.matter (100%) diff --git a/zzz_generated/all-clusters-app/zap-generated/Clusters.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter similarity index 100% rename from zzz_generated/all-clusters-app/zap-generated/Clusters.matter rename to examples/all-clusters-app/all-clusters-common/all-clusters-app.matter diff --git a/zzz_generated/bridge-app/zap-generated/Clusters.matter b/examples/bridge-app/bridge-common/bridge-app.matter similarity index 100% rename from zzz_generated/bridge-app/zap-generated/Clusters.matter rename to examples/bridge-app/bridge-common/bridge-app.matter diff --git a/zzz_generated/door-lock-app/zap-generated/Clusters.matter b/examples/door-lock-app/door-lock-common/door-lock-app.matter similarity index 100% rename from zzz_generated/door-lock-app/zap-generated/Clusters.matter rename to examples/door-lock-app/door-lock-common/door-lock-app.matter diff --git a/zzz_generated/lighting-app/zap-generated/Clusters.matter b/examples/lighting-app/lighting-common/lighting-app.matter similarity index 100% rename from zzz_generated/lighting-app/zap-generated/Clusters.matter rename to examples/lighting-app/lighting-common/lighting-app.matter diff --git a/zzz_generated/lock-app/zap-generated/Clusters.matter b/examples/lock-app/lock-common/lock-app.matter similarity index 100% rename from zzz_generated/lock-app/zap-generated/Clusters.matter rename to examples/lock-app/lock-common/lock-app.matter diff --git a/zzz_generated/log-source-app/zap-generated/Clusters.matter b/examples/log-source-app/log-source-common/log-source-app.matter similarity index 100% rename from zzz_generated/log-source-app/zap-generated/Clusters.matter rename to examples/log-source-app/log-source-common/log-source-app.matter diff --git a/zzz_generated/ota-provider-app/zap-generated/Clusters.matter b/examples/ota-provider-app/ota-provider-common/ota-provider-app.matter similarity index 100% rename from zzz_generated/ota-provider-app/zap-generated/Clusters.matter rename to examples/ota-provider-app/ota-provider-common/ota-provider-app.matter diff --git a/zzz_generated/ota-requestor-app/zap-generated/Clusters.matter b/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter similarity index 100% rename from zzz_generated/ota-requestor-app/zap-generated/Clusters.matter rename to examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter diff --git a/zzz_generated/placeholder/app1/zap-generated/Clusters.matter b/examples/placeholder/linux/apps/app1/config.matter similarity index 100% rename from zzz_generated/placeholder/app1/zap-generated/Clusters.matter rename to examples/placeholder/linux/apps/app1/config.matter diff --git a/zzz_generated/placeholder/app2/zap-generated/Clusters.matter b/examples/placeholder/linux/apps/app2/config.matter similarity index 100% rename from zzz_generated/placeholder/app2/zap-generated/Clusters.matter rename to examples/placeholder/linux/apps/app2/config.matter diff --git a/zzz_generated/pump-app/zap-generated/Clusters.matter b/examples/pump-app/pump-common/pump-app.matter similarity index 100% rename from zzz_generated/pump-app/zap-generated/Clusters.matter rename to examples/pump-app/pump-common/pump-app.matter diff --git a/zzz_generated/pump-controller-app/zap-generated/Clusters.matter b/examples/pump-controller-app/pump-controller-common/pump-controller-app.matter similarity index 100% rename from zzz_generated/pump-controller-app/zap-generated/Clusters.matter rename to examples/pump-controller-app/pump-controller-common/pump-controller-app.matter diff --git a/zzz_generated/temperature-measurement-app/zap-generated/Clusters.matter b/examples/temperature-measurement-app/esp32/main/temperature-measurement.matter similarity index 100% rename from zzz_generated/temperature-measurement-app/zap-generated/Clusters.matter rename to examples/temperature-measurement-app/esp32/main/temperature-measurement.matter diff --git a/zzz_generated/thermostat/zap-generated/Clusters.matter b/examples/thermostat/thermostat-common/thermostat.matter similarity index 100% rename from zzz_generated/thermostat/zap-generated/Clusters.matter rename to examples/thermostat/thermostat-common/thermostat.matter diff --git a/zzz_generated/tv-app/zap-generated/Clusters.matter b/examples/tv-app/tv-common/tv-app.matter similarity index 100% rename from zzz_generated/tv-app/zap-generated/Clusters.matter rename to examples/tv-app/tv-common/tv-app.matter diff --git a/zzz_generated/tv-casting-app/zap-generated/Clusters.matter b/examples/tv-casting-app/tv-casting-common/tv-casting-app.matter similarity index 100% rename from zzz_generated/tv-casting-app/zap-generated/Clusters.matter rename to examples/tv-casting-app/tv-casting-common/tv-casting-app.matter diff --git a/zzz_generated/window-app/zap-generated/Clusters.matter b/examples/window-app/common/window-app.matter similarity index 100% rename from zzz_generated/window-app/zap-generated/Clusters.matter rename to examples/window-app/common/window-app.matter diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index 99b0fafb4f6257..58f73f0d2a8f71 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -25,6 +25,56 @@ os.path.join(os.path.dirname(__file__), '../..')) +class ZAPGenerateTarget: + def __init__(self, zap_config, template=None, output_dir=None): + self.script = './scripts/tools/zap/generate.py' + self.zap_config = str(zap_config) + self.template = template + + if output_dir: + # make sure we convert any os.PathLike object to string + self.output_dir = str(output_dir) + else: + self.output_dir = None + + def generate(self): + """Runs a ZAP generate command on the configured zap/template/outputs. + """ + cmd = [self.script, self.zap_config] + + if self.template: + cmd.append('-t') + cmd.append(self.template) + + if self.output_dir: + cmd.append('-o') + cmd.append(self.output_dir) + + logging.info("Generating target: %s" % " ".join(cmd)) + subprocess.check_call(cmd) + + def extractAnyGeneratedIDL(self): + """Searches for Clusters.matter in the output directory and if found, + will move it to stay along with the zap file config + """ + if not self.output_dir: + # TODO: where do things get generated if no output dir? + # Assume here that IDL is not generated in such cases + return + + idl_path = os.path.join(self.output_dir, "Clusters.matter") + if not os.path.exists(idl_path): + return + + target_path = self.zap_config.replace(".zap", ".matter") + if not target_path.endswith(".matter"): + # We expect "something.zap" and don't handle corner cases of + # multiple extensions. This is to work with existing codebase only + raise Error("Unexpected input zap file %s" % self.zap_config) + + os.rename(idl_path, target_path) + + def checkPythonVersion(): if sys.version_info[0] < 3: print('Must use Python 3. Current version is ' + @@ -55,8 +105,10 @@ def getGlobalTemplatesTargets(): if not os.path.exists(output_dir): os.makedirs(output_dir) template = 'examples/placeholder/templates/templates.json' - targets.append([str(filepath), '-o', output_dir]) - targets.append([str(filepath), '-o', output_dir, '-t', template]) + + targets.append(ZAPGenerateTarget(filepath, output_dir=output_dir)) + targets.append( + ZAPGenerateTarget(filepath, output_dir=output_dir, template=template)) continue logging.info("Found example %s (via %s)" % @@ -69,13 +121,11 @@ def getGlobalTemplatesTargets(): if not os.path.exists(output_dir): os.makedirs(output_dir) - targets.append([str(filepath), '-o', output_dir]) + targets.append(ZAPGenerateTarget(filepath, output_dir=output_dir)) - targets.extend([ - [ - './src/controller/data_model/controller-clusters.zap', - '-o', - os.path.join('zzz_generated/controller-clusters/zap-generated')]]) + targets.append(ZAPGenerateTarget( + './src/controller/data_model/controller-clusters.zap', + output_dir=os.path.join('zzz_generated/controller-clusters/zap-generated'))) return targets @@ -94,12 +144,12 @@ def getSpecificTemplatesTargets(): } for template, output_dir in templates.items(): - target = [ - 'src/controller/data_model/controller-clusters.zap', '-t', template] + target = ZAPGenerateTarget( + 'src/controller/data_model/controller-clusters.zap', template=template) if output_dir is not None: if not os.path.exists(output_dir): os.makedirs(output_dir) - target.extend(['-o', output_dir]) + target.output_dir = output_dir targets.append(target) @@ -123,9 +173,8 @@ def main(): targets = getTargets() for target in targets: - exec_list = ['./scripts/tools/zap/generate.py'] + target - logging.info("Generating target: %s" % " ".join(exec_list)) - subprocess.check_call(exec_list) + target.generate() + target.extractAnyGeneratedIDL() if __name__ == '__main__': diff --git a/zzz_generated/controller-clusters/zap-generated/Clusters.matter b/src/controller/data_model/controller-clusters.matter similarity index 100% rename from zzz_generated/controller-clusters/zap-generated/Clusters.matter rename to src/controller/data_model/controller-clusters.matter