From 0ce298309de3169fd76934cc3940cf52305f69ae Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 21 Oct 2022 10:24:05 -0400 Subject: [PATCH 1/3] Special case NXP light app gen. Do not allow duplicate generation instructions --- scripts/tools/zap_regen_all.py | 54 +++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index db647387e2e61d..bc9ee6956ed9c5 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -21,10 +21,23 @@ import sys import subprocess import logging +from dataclasses import dataclass CHIP_ROOT_DIR = os.path.realpath( os.path.join(os.path.dirname(__file__), '../..')) +@dataclass(eq=True, frozen=True) +class ZapDistinctOutput: + """Defines the properties that determine if some output seems unique or + not, for the purposes of detecting codegen overlap. + + Not perfect, since separate templates may use the same file names, but + better than nothing. + """ + + input_template: str + output_directory: str + class ZAPGenerateTarget: def __init__(self, zap_config, template=None, output_dir=None): @@ -38,6 +51,9 @@ def __init__(self, zap_config, template=None, output_dir=None): else: self.output_dir = None + def distinct_output(self): + return ZapDistinctOutput(input_template = self.template, output_directory = self.output_dir) + def log_command(self): """Log the command that will get run for this target """ @@ -135,10 +151,17 @@ def getGlobalTemplatesTargets(): logging.info("Found example %s (via %s)" % (example_name, str(filepath))) + generate_subdir = example_name + + # Special casing lighting app because separate folders + if example_name == "lighting-app": + if 'nxp' in str(filepath): + generate_subdir = f"{example_name}/nxp" + # The name zap-generated is to make includes clear by using # a name like output_dir = os.path.join( - 'zzz_generated', example_name, 'zap-generated') + 'zzz_generated', generate_subdir, 'zap-generated') targets.append(ZAPGenerateTarget(filepath, output_dir=output_dir)) targets.append(ZAPGenerateTarget( @@ -162,19 +185,6 @@ def getTestsTemplatesTargets(test_target): } } - # Place holder has apps within each build - for filepath in Path('./examples/placeholder').rglob('*.zap'): - example_name = filepath.as_posix() - example_name = example_name[example_name.index( - 'apps/') + len('apps/'):] - example_name = example_name[:example_name.index('/')] - - templates[example_name] = { - 'zap': filepath, - 'template': 'examples/placeholder/templates/templates.json', - 'output_dir': os.path.join('zzz_generated', 'placeholder', example_name, 'zap-generated') - } - targets = [] for key, target in templates.items(): if test_target == 'all' or test_target == key: @@ -223,6 +233,22 @@ def getTargets(type, test_target): for target in targets: target.log_command() + # validate that every target as a DISTINCT directory (we had bugs here + # for various examples duplicating zap files) + distinct_outputs = set() + for target in targets: + o = target.distinct_output() + + if o in distinct_outputs: + logging.error("Same output %r:" % o) + for t in targets: + if t.distinct_output() == o: + logging.error(" %s" % t.zap_config) + + raise Exception("Duplicate/overlapping output directory: %r" % o) + + distinct_outputs.add(o) + return targets From 5954857bba9e5d83a8534575392b116cff8c5e62 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 21 Oct 2022 10:30:12 -0400 Subject: [PATCH 2/3] Ran zap regen --- zzz_generated/lighting-app/nxp/zap-generated/endpoint_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zzz_generated/lighting-app/nxp/zap-generated/endpoint_config.h b/zzz_generated/lighting-app/nxp/zap-generated/endpoint_config.h index 7caf9b7ee0ce99..8273a657c31589 100644 --- a/zzz_generated/lighting-app/nxp/zap-generated/endpoint_config.h +++ b/zzz_generated/lighting-app/nxp/zap-generated/endpoint_config.h @@ -320,7 +320,7 @@ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(4) }, /* ClusterRevision */ \ \ /* Endpoint: 1, Cluster: Groups (server) */ \ - { 0x00000000, ZAP_TYPE(BITMAP8), 1, 0, ZAP_EMPTY_DEFAULT() }, /* name support */ \ + { 0x00000000, ZAP_TYPE(BITMAP8), 1, 0, ZAP_EMPTY_DEFAULT() }, /* NameSupport */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(4) }, /* ClusterRevision */ \ \ From 4e61f0fe9e6b0e70d3b759d382f343685fc1b05b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 21 Oct 2022 10:39:13 -0400 Subject: [PATCH 3/3] Restyle --- scripts/tools/zap_regen_all.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index bc9ee6956ed9c5..61c8f6823663eb 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -26,6 +26,7 @@ CHIP_ROOT_DIR = os.path.realpath( os.path.join(os.path.dirname(__file__), '../..')) + @dataclass(eq=True, frozen=True) class ZapDistinctOutput: """Defines the properties that determine if some output seems unique or @@ -52,7 +53,7 @@ def __init__(self, zap_config, template=None, output_dir=None): self.output_dir = None def distinct_output(self): - return ZapDistinctOutput(input_template = self.template, output_directory = self.output_dir) + return ZapDistinctOutput(input_template=self.template, output_directory=self.output_dir) def log_command(self): """Log the command that will get run for this target @@ -243,7 +244,7 @@ def getTargets(type, test_target): logging.error("Same output %r:" % o) for t in targets: if t.distinct_output() == o: - logging.error(" %s" % t.zap_config) + logging.error(" %s" % t.zap_config) raise Exception("Duplicate/overlapping output directory: %r" % o)