diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index db647387e2e61d..61c8f6823663eb 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -21,11 +21,25 @@ 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): self.script = './scripts/tools/zap/generate.py' @@ -38,6 +52,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 +152,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 +186,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 +234,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 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 */ \ \