diff --git a/examples/chef/chef.py b/examples/chef/chef.py index b6b08af34ddd35..afe840b757fe92 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -41,6 +41,7 @@ _DEVICE_LIST = [file[:-4] for file in os.listdir(_DEVICE_FOLDER) if file.endswith(".zap")] _CHEF_ZZZ_ROOT = os.path.join(_CHEF_SCRIPT_PATH, "zzz_generated") _CI_MANIFEST_FILE_NAME = os.path.join(_CHEF_SCRIPT_PATH, "cimanifest.json") +_CICD_CONFIG_FILE_NAME = os.path.join(_CHEF_SCRIPT_PATH, "cicd_meta.json") _CI_ALLOW_LIST = ["lighting-app"] gen_dir = "" # Filled in after sample app type is read from args. @@ -139,13 +140,22 @@ def generate_device_manifest( return ci_manifest -def load_cicd_config() -> dict: - pass +def load_cicd_config() -> Dict[str, Any]: + with open(_CICD_CONFIG_FILE_NAME, "r", encoding="utf-8") as config_file: + config = json.loads(config_file.read()) + for platform_name, platform_config in config.items(): + has_build_dir = "build_dir" in platform_config + has_plat_label = "platform_label" in platform_config + if not has_build_dir or not has_plat_label: + print(f"{platform_name} CICD config missing build_dir or platform_label") + exit(1) + return config def main(argv: Sequence[str]) -> None: check_python_version() config = load_config() + cicd_config = load_cicd_config() # # Build environment switches @@ -328,11 +338,8 @@ def main(argv: Sequence[str]) -> None: if options.ci: if options.build_target == "nrfconnect": os.environ['GNUARMEMB_TOOLCHAIN_PATH'] = os.environ['PW_ARM_CIPD_INSTALL_DIR'] - for device_dir_item in os.listdir(_CHEF_DEVICES_DIR): - target_file_ext = ".zap" - if device_dir_item.endswith(target_file_ext) and device_dir_item in chef_util.ci_allowlist: - device_name = device_dir_item[:-len(target_file_ext)] - command = './chef.py -cbr --use_zzz -d {} -t {}'.format(device_name, options.build_target) + for device_name in [d for d in _DEVICE_LIST if d in _CI_ALLOW_LIST]: + command = f"./chef.py -cbr --use_zzz -d {device_name} -t {options.build_target}" subprocess.check_call(command, cwd=_CHEF_SCRIPT_PATH, shell=True) exit(0) @@ -347,17 +354,15 @@ def main(argv: Sequence[str]) -> None: if not os.path.exists(archive_prefix): os.mkdir(archive_prefix) archive_suffix = ".tar.gz" - - cd_platforms_meta = chef_util.cd_platforms_meta for device_name in _DEVICE_LIST: - for platform, platform_meta in cd_platforms_meta.items(): + for platform, platform_meta in cicd_config.items(): directory = platform_meta['build_dir'] label = platform_meta['platform_label'] output_dir = os.path.join(_CHEF_SCRIPT_PATH, directory) command = f"./chef.py -cbr --use_zzz -d {device_name} -t {platform}" - print('-' * 64, flush=True) + print("-" * 64, flush=True) print(f"Building {command}", flush=True) - print('-' * 64, flush=True) + print("-" * 64, flush=True) subprocess.check_call(command, cwd=_CHEF_SCRIPT_PATH, shell=True) archive_name = f"{label}-chef-{device_name}-wifi-rpc" archive_full_name = archive_prefix + archive_name + archive_suffix