Skip to content

Commit

Permalink
Truncate the branch info of the software version string while the tot…
Browse files Browse the repository at this point in the history
…al length greater equal to 64 bytes.

Make the filling of software version string with <branch>:<commit_id> as
an option.
The new option for it is '-a' or '--automated_test_stamp'.
  • Loading branch information
MtTsai committed Jun 21, 2022
1 parent 2ac3ee7 commit bec37c9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ def main(argv: Sequence[str]) -> None:
metavar="TARGET",
default="esp32")
parser.add_option("-r", "--rpc", help="enables Pigweed RPC interface. Enabling RPC disables the shell interface. Your sdkconfig configurations will be reverted to default. Default is PW RPC off. When enabling or disabling this flag, on the first build force a clean build with -c", action="store_true", dest="do_rpc")
parser.add_option("-a", "--automated_test_stamp", help="provide the additional stamp \"branch:commit_id\" as the software version string for automated tests.",
action="store_true", dest="do_automated_test_stamp")
parser.add_option("-v", "--vid", dest="vid", type=int,
help="specifies the Vendor ID. Default is 0xFFF1", metavar="VID", default=0xFFF1)
parser.add_option("-p", "--pid", dest="pid", type=int,
Expand Down Expand Up @@ -490,9 +492,17 @@ def main(argv: Sequence[str]) -> None:
#

if options.do_build:
branch = shell.run_cmd(
"git branch | awk -v FS=' ' '/\*/{print $NF}' | sed 's|[()]||g'", return_cmd_output=True).replace("\n", "")
commit_id = shell.run_cmd("git rev-parse HEAD", return_cmd_output=True).replace("\n", "")
if options.do_automated_test_stamp:
branch = shell.run_cmd(
"git branch | awk -v FS=' ' '/\*/{print $NF}' | sed 's|[()]||g'", return_cmd_output=True).replace("\n", "")
commit_id = shell.run_cmd("git rev-parse HEAD", return_cmd_output=True).replace("\n", "")
sw_ver_string = f"""{branch}:{commit_id}"""
# 64 bytes space could only contain 63 bytes string + 1 byte EOS.
if len(sw_ver_string) >= 64:
truncated_sw_ver_string = f"""{branch[:22]}:{commit_id}"""
flush_print(
f"""Truncate the software version string from \"{sw_ver_string}\" to \"{truncated_sw_ver_string}\" due to 64 bytes limitation""")
sw_ver_string = truncated_sw_ver_string

if options.use_zzz:
flush_print("Using pre-generated ZAP output")
Expand Down Expand Up @@ -573,13 +583,18 @@ 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:
target_defines = [
f"\"CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID={options.vid}\"", f"\"CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID={options.pid}\""]
target_defines.append(f"\"CONFIG_ENABLE_PW_RPC={'1' if options.do_rpc else '0'}\"")
if options.do_automated_test_stamp:
target_defines.append(f"\"CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\\\"{sw_ver_string}\\\"\"")
f.write(textwrap.dedent(f"""\
import("//build_overrides/chip.gni")
import("${{chip_root}}/config/standalone/args.gni")
chip_shell_cmd_server = false
chip_build_libshell = true
chip_config_network_layer_ble = 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'}", "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\\"{branch}:{commit_id}\\""]
target_defines = [{", ".join(target_defines)}]
"""))
with open(f"{_CHEF_SCRIPT_PATH}/linux/sample.gni", "w") as f:
f.write(textwrap.dedent(f"""\
Expand Down

0 comments on commit bec37c9

Please sign in to comment.