Skip to content

Commit

Permalink
Update scripts/tools/zap_regen_all.py to be able to generate only the…
Browse files Browse the repository at this point in the history
… test targets if needed
  • Loading branch information
vivien-apple committed Feb 16, 2022
1 parent cacf844 commit eebe6a1
Showing 1 changed file with 65 additions and 18 deletions.
83 changes: 65 additions & 18 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import argparse
import os
from pathlib import Path
import sys
Expand Down Expand Up @@ -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)

Expand All @@ -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 = []

Expand All @@ -81,8 +94,6 @@ def getGlobalTemplatesTargets():
# a name like <zap-generated/foo.h>
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))
Expand All @@ -97,9 +108,6 @@ def getGlobalTemplatesTargets():
# a name like <zap-generated/foo.h>
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(
Expand All @@ -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 = {
Expand All @@ -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


Expand All @@ -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()

Expand Down

0 comments on commit eebe6a1

Please sign in to comment.