diff --git a/examples/chef/chef.py b/examples/chef/chef.py index 299229e890a92f..288a3b79c70e49 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -19,12 +19,13 @@ import os import sys import textwrap -from typing import Sequence +import shutil import yaml import constants import stateful_shell +from typing import Sequence TermColors = constants.TermColors @@ -164,11 +165,65 @@ def main(argv: Sequence[str]) -> None: action="store_true", dest="do_rpc_console") parser.add_option("-y", "--tty", help="Enumerated USB tty/serial interface enumerated for your physical device. E.g.: /dev/ACM0", dest="tty", metavar="TTY", default=None) + parser.add_option("", "--generate_zzz", help="Populates zzz_generated/chef//zap-generated with output of ZAP tool for every device in examples/chef/devices. If this flag is set, all other arguments are ignored except for --bootstrap_zap.", + dest="generate_zzz", action="store_true") + parser.add_option("", "--use_zzz", help="Use pre generated output from the ZAP tool found in the zzz_generated folder. Used to decrease execution time of CI jobs", dest="use_zzz", action="store_true") options, _ = parser.parse_args(argv) splash() + # + # ZAP bootstrapping + # + + if options.do_bootstrap_zap: + if sys.platform == "linux" or sys.platform == "linux2": + print("Installing ZAP OS package dependencies") + shell.run_cmd( + f"sudo apt-get install sudo apt-get install node node-yargs npm\ + libpixman-1-dev libcairo2-dev libpango1.0-dev node-pre-gyp libjpeg9-dev libgif\ +-dev node-typescript") + if sys.platform == "darwin": + print("Installation of ZAP OS packages not supported on MacOS") + if sys.platform == "win32": + print( + "Installation of ZAP OS packages not supported on Windows") + + print("Running NPM to install ZAP Node.JS dependencies") + shell.run_cmd( + f"cd {_REPO_BASE_PATH}/third_party/zap/repo/ && npm install") + + # + # Populate zzz_generated + # + + if options.generate_zzz: + chef_zzz_root = os.path.join(_REPO_BASE_PATH, "zzz_generated/chef") + chef_devices_dir = os.path.join(_CHEF_SCRIPT_PATH, "devices") + print(f"Cleaning {chef_zzz_root}") + if not os.path.exists(chef_zzz_root): + print(f"{chef_zzz_root} doesn't exist; creating") + os.mkdir(chef_zzz_root) + else: + print(f"Deleting and recreating existing {chef_zzz_root}") + shutil.rmtree(chef_zzz_root) + os.mkdir(chef_zzz_root) + print(f"Generating files in {chef_zzz_root} for all devices") + for device_dir_item in os.listdir(chef_devices_dir): + target_file_ext = '.zap' + if device_dir_item.endswith(target_file_ext): + device_name = device_dir_item[:-len(target_file_ext)] + print(f"Generating files for {device_name}") + device_out_dir = os.path.join(chef_zzz_root, device_name) + os.mkdir(device_out_dir) + device_out_dir = os.path.join(device_out_dir, "zap-generated") + os.mkdir(device_out_dir) + shell.run_cmd(f"{_REPO_BASE_PATH}/scripts/tools/zap/generate.py\ + {_CHEF_SCRIPT_PATH}/devices/{device_name}.zap -o {device_out_dir}") + shell.run_cmd(f"touch {device_out_dir}/af-gen-event.h") + exit(0) + # # Platform Folder # @@ -217,25 +272,6 @@ def main(argv: Sequence[str]) -> None: elif options.build_target == "linux": print("Linux toolchain update not supported. Skipping") - # - # ZAP bootstrapping - # - - if options.do_bootstrap_zap: - if sys.platform == "linux" or sys.platform == "linux2": - print("Installing ZAP OS package dependencies") - shell.run_cmd( - f"sudo apt-get install sudo apt-get install node node-yargs npm libpixman-1-dev libcairo2-dev libpango1.0-dev node-pre-gyp libjpeg9-dev libgif-dev node-typescript") - if sys.platform == "darwin": - print("Installation of ZAP OS packages not supported on MacOS") - if sys.platform == "win32": - print( - "Installation of ZAP OS packages not supported on Windows") - - print("Running NPM to install ZAP Node.JS dependencies") - shell.run_cmd( - f"cd {_REPO_BASE_PATH}/third_party/zap/repo/ && npm install") - # # Cluster customization # @@ -276,6 +312,13 @@ def main(argv: Sequence[str]) -> None: # if options.do_build: + if options.use_zzz: + print("Using pre-generated ZAP output") + zzz_dir = os.path.join(_REPO_BASE_PATH, "zzz_generated/chef", options.sample_device_type_name, "zap-generated") + if os.path.exists(gen_dir): + shutil.rmtree(gen_dir) + shutil.copytree(zzz_dir, gen_dir) + print("Building...") if options.do_rpc: print("RPC PW enabled") @@ -331,9 +374,10 @@ def main(argv: Sequence[str]) -> None: elif options.build_target == "linux": shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/linux") with open(f"{_CHEF_SCRIPT_PATH}/linux/args.gni", "w") as f: + args_gni = os.path.join(_REPO_BASE_PATH, "config/standalone/args.gni") f.write(textwrap.dedent(f"""\ import("//build_overrides/chip.gni") - import("\\${{chip_root}}/config/standalone/args.gni") + import("{args_gni}") chip_shell_cmd_server = false target_defines = ["CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID={options.vid}", "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID={options.pid}", "CONFIG_ENABLE_PW_RPC={'1' if options.do_rpc else '0'}"] """))