Skip to content

Commit

Permalink
Move zzz to chef dir, write manifest, new opt
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed May 24, 2022
1 parent a345cb5 commit 53156a1
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 4 deletions.
21 changes: 17 additions & 4 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import textwrap
import shutil
import yaml
import hashlib
import json

import constants
import stateful_shell
Expand Down Expand Up @@ -167,6 +169,7 @@ def main(argv: Sequence[str]) -> None:
dest="tty", metavar="TTY", default=None)
parser.add_option("", "--generate_zzz", help="Populates zzz_generated/chef/<DEVICE_TYPE>/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("", "--validate_zzz", help="Checks if cached ZAP output needs to be regenrated, for use in CI. If this flag is set, all other arguments are ignored.", dest="validate_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)
Expand Down Expand Up @@ -197,10 +200,12 @@ def main(argv: Sequence[str]) -> None:
#
# Populate zzz_generated
#
chef_zzz_root = os.path.join(_CHEF_SCRIPT_PATH, "zzz_generated")
ci_manifest_file_name = os.path.join(_CHEF_SCRIPT_PATH, "cimanifest.json")
chef_devices_dir = os.path.join(_CHEF_SCRIPT_PATH, "devices")

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")
ci_manifest = {}
print(f"Cleaning {chef_zzz_root}")
if not os.path.exists(chef_zzz_root):
print(f"{chef_zzz_root} doesn't exist; creating")
Expand All @@ -211,9 +216,15 @@ def main(argv: Sequence[str]) -> None:
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'
target_file_ext = ".zap"
if device_dir_item.endswith(target_file_ext):
device_name = device_dir_item[:-len(target_file_ext)]
device_file_path = os.path.join(chef_devices_dir, device_dir_item)
with open(device_file_path, "rb") as device_file:
device_file_data = device_file.read()
device_file_md5 = hashlib.md5(device_file_data).hexdigest()
ci_manifest[device_name] = device_file_md5
print(f"Manifest for {device_name} : {device_file_md5}")
print(f"Generating files for {device_name}")
device_out_dir = os.path.join(chef_zzz_root, device_name)
os.mkdir(device_out_dir)
Expand All @@ -222,6 +233,8 @@ def main(argv: Sequence[str]) -> None:
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")
with open(ci_manifest_file_name, "w+", encoding="utf-8") as ci_manifest_file:
ci_manifest_file.write(json.dumps(ci_manifest, indent=4))
exit(0)

#
Expand Down Expand Up @@ -314,7 +327,7 @@ 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")
zzz_dir = os.path.join(_CHEF_SCRIPT_PATH, "zzz_generated", options.sample_device_type_name, "zap-generated")
if os.path.exists(gen_dir):
shutil.rmtree(gen_dir)
shutil.copytree(zzz_dir, gen_dir)
Expand Down
3 changes: 3 additions & 0 deletions examples/chef/cimanifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"lighting-app": "41c55e72d06a04d193901d6b5487f7fa"
}

0 comments on commit 53156a1

Please sign in to comment.