Skip to content

Commit

Permalink
Example bundle function
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Jun 7, 2022
1 parent 55ab764 commit 5f7c41c
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
_CI_ZAP_MANIFEST_NAME = "ZAPSHA.txt"
_CICD_CONFIG_FILE_NAME = os.path.join(_CHEF_SCRIPT_PATH, "cicd_meta.json")
_CI_ALLOW_LIST = ["lighting-app"]
_CD_STAGING_DIR = os.path.join(_CHEF_SCRIPT_PATH, "staging")

gen_dir = "" # Filled in after sample app type is read from args.

Expand Down Expand Up @@ -173,6 +174,61 @@ def flush_print(
print(to_print, flush=True)


def bundle(platform: str, device_name: str) -> None:
"""Filters files from the build output folder for CD.
calls bundle_platform(device_name).
Clears the staging dir
Args:
platform: the platform to bundle
device_name: the example to bundle
"""
shutil.rmtree(_CD_STAGING_DIR, ignore_errors=True)
os.mkdir(_CD_STAGING_DIR)
bundle_fn_name = f"bundle_{platform}"
if bundle_fn_name in globals():
globals()[bundle_fn_name](device_name)
else:
flush_print(f"No bundle function for {platform}!")
exit(1)


#
# Bundle functions
#


def bundle_linux(device_name: str) -> None:
exit(1)


def bundle_nrfconnect(device_name: str) -> None:
exit(1)


def bundle_esp32(device_name: str) -> None:
"""Reference example for bundle_
Should copy/move files crom cicd_config()['build_dir']
into _CD_STAGING_DIR.
Args:
device_name: the device currently built.
"""
esp_root = os.path.join(_CHEF_SCRIPT_PATH,
"esp32",
"build")
manifest = os.path.join(esp_root,
"chip-shell.flashbundle.txt")
os.mkdir(os.path.join(_CD_STAGING_DIR, "partition_table"))
os.mkdir(os.path.join(_CD_STAGING_DIR, "bootloader")) # TODO UNHARDCODE
with open(manifest) as m:
for item in m:
item = item.replace("\n", "")
src_item = os.path.join(esp_root, item)
dest_item = os.path.join(_CD_STAGING_DIR, item)
shutil.copy(src_item, dest_item)


def main(argv: Sequence[str]) -> None:
check_python_version()
config = load_config()
Expand Down Expand Up @@ -370,8 +426,8 @@ def main(argv: Sequence[str]) -> None:
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
command = f"./chef.py -cbr --use_zzz -d {device_name} -t {options.build_target}"
flush_print(f"Building {command}", with_border=True)
shell.run_cmd(command)
# TODO call per-platform bundle function for extra validation
shell.run_cmd(command) built once, only testing bundle
bundle(options.build_target, device_name)
exit(0)

#
Expand All @@ -393,12 +449,12 @@ def main(argv: Sequence[str]) -> None:
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
shell.run_cmd("export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"")
shell.run_cmd(command)
# TODO Needs to call per-platform bundle function
bundle(platform, device_name)
archive_name = f"{label}-{device_name}"
archive_full_name = archive_prefix + archive_name + archive_suffix
flush_print(f"Adding build output to archive {archive_full_name}")
with tarfile.open(archive_full_name, "w:gz") as tar:
tar.add(output_dir, arcname=".")
tar.add(_CD_STAGING_DIR, arcname=".")
exit(0)

#
Expand Down

0 comments on commit 5f7c41c

Please sign in to comment.