From bec37c94c6ec3e477ac4f40204cc8a7a27b315ed Mon Sep 17 00:00:00 2001 From: MT Tsai Date: Tue, 21 Jun 2022 03:47:03 +0000 Subject: [PATCH] Truncate the branch info of the software version string while the total length greater equal to 64 bytes. Make the filling of software version string with : as an option. The new option for it is '-a' or '--automated_test_stamp'. --- examples/chef/chef.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/chef/chef.py b/examples/chef/chef.py index f75dbe47034a48..387e1651cda0ed 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -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, @@ -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") @@ -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"""\