diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index eb19dab5089989..5a5b3f33d624b7 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -15,6 +15,7 @@ # limitations under the License. # +import argparse import os from pathlib import Path import sys @@ -47,6 +48,8 @@ def generate(self): cmd.append(self.template) if self.output_dir: + if not os.path.exists(self.output_dir): + os.makedirs(self.output_dir) cmd.append('-o') cmd.append(self.output_dir) @@ -61,6 +64,16 @@ def checkPythonVersion(): exit(1) +def setupArgumentsParser(): + parser = argparse.ArgumentParser( + description='Generate content from ZAP files') + parser.add_argument('--type', default='all', choices=['all', 'tests'], + help='Choose which content type to generates (default: all)') + parser.add_argument('--tests', default='all', choices=['all', 'chip-tool', 'darwin', 'app1', 'app2'], + help='When generating tests only target, Choose which tests to generates (default: all)') + return parser.parse_args() + + def getGlobalTemplatesTargets(): targets = [] @@ -81,8 +94,6 @@ def getGlobalTemplatesTargets(): # a name like output_dir = os.path.join( 'zzz_generated', 'placeholder', example_name, 'zap-generated') - if not os.path.exists(output_dir): - os.makedirs(output_dir) template = 'examples/placeholder/templates/templates.json' targets.append(ZAPGenerateTarget(filepath, output_dir=output_dir)) @@ -97,9 +108,6 @@ def getGlobalTemplatesTargets(): # a name like output_dir = os.path.join( 'zzz_generated', example_name, 'zap-generated') - if not os.path.exists(output_dir): - os.makedirs(output_dir) - targets.append(ZAPGenerateTarget(filepath, output_dir=output_dir)) targets.append(ZAPGenerateTarget( @@ -109,8 +117,45 @@ def getGlobalTemplatesTargets(): return targets -def getSpecificTemplatesTargets(): +def getTestsTemplatesTargets(test_target): + templates = { + 'chip-tool': { + 'zap': 'src/controller/data_model/controller-clusters.zap', + 'template': 'examples/chip-tool/templates/tests/templates.json', + 'output_dir': 'zzz_generated/chip-tool/zap-generated' + }, + 'darwin': { + 'zap': 'src/controller/data_model/controller-clusters.zap', + 'template': 'src/darwin/Framework/CHIP/templates/tests/templates.json', + 'output_dir': None + } + } + + # 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/') + 5:] + 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: + logging.info("Found test target %s (via %s)" % + (key, target['template'])) + targets.append(ZAPGenerateTarget( + target['zap'], template=target['template'], output_dir=target['output_dir'])) + + return targets + + +def getSpecificTemplatesTargets(): + zap_filepath = 'src/controller/data_model/controller-clusters.zap' # Mapping of required template and output directory templates = { @@ -122,23 +167,24 @@ def getSpecificTemplatesTargets(): 'src/app/tests/suites/templates/templates.json': 'zzz_generated/controller-clusters/zap-generated', } + targets = [] for template, output_dir in templates.items(): - 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.output_dir = output_dir - - targets.append(target) + targets.append(ZAPGenerateTarget( + zap_filepath, template=template, output_dir=output_dir)) return targets -def getTargets(): +def getTargets(type, test_target): targets = [] - targets.extend(getGlobalTemplatesTargets()) - targets.extend(getSpecificTemplatesTargets()) + + if type == 'all': + targets.extend(getGlobalTemplatesTargets()) + targets.extend(getTestsTemplatesTargets('all')) + targets.extend(getSpecificTemplatesTargets()) + elif type == 'tests': + targets.extend(getTestsTemplatesTargets(test_target)) + return targets @@ -149,8 +195,9 @@ def main(): ) checkPythonVersion() os.chdir(CHIP_ROOT_DIR) + args = setupArgumentsParser() - targets = getTargets() + targets = getTargets(args.type, args.tests) for target in targets: target.generate()