From 89804c843fc2bea5f473ebf26fe9562acd134106 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 | 21 +++++++++++++++++++++ src/platform/BUILD.gn | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/examples/chef/chef.py b/examples/chef/chef.py index fafad0178952b7..9ce08f86fb02b6 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -25,6 +25,7 @@ from typing import Any, Dict, Sequence import yaml +import re import constants import stateful_shell @@ -241,6 +242,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,6 +493,22 @@ def main(argv: Sequence[str]) -> None: # if options.do_build: + if options.do_automated_test_stamp: + branch = "" + for branch_text in shell.run_cmd("git branch", return_cmd_output=True).split("\n"): + match_texts = re.findall("\* (.*)", branch_text) + if match_texts: + branch = match_texts[0] + break + 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") zzz_dir = os.path.join(_CHEF_SCRIPT_PATH, @@ -569,6 +588,7 @@ 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: + sw_ver_string_config_text = f"chip_device_config_device_software_version_string = \"{sw_ver_string}\"" if options.do_automated_test_stamp else "" f.write(textwrap.dedent(f"""\ import("//build_overrides/chip.gni") import("${{chip_root}}/config/standalone/args.gni") @@ -576,6 +596,7 @@ def main(argv: Sequence[str]) -> None: 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'}"] + {sw_ver_string_config_text} """)) with open(f"{_CHEF_SCRIPT_PATH}/linux/sample.gni", "w") as f: f.write(textwrap.dedent(f"""\ diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index a71d473baa653e..1914ca1386aadc 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -65,6 +65,9 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { # Indication that the CHIP data model is included chip_enable_data_model = false + + # The string of device software version was built. + chip_device_config_device_software_version_string = "" } if (chip_stack_lock_tracking == "auto") { @@ -254,6 +257,10 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { "CHIP_DEVICE_LAYER_TARGET=Zephyr", ] } + + if (chip_device_config_device_software_version_string != "") { + defines += [ "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${chip_device_config_device_software_version_string}\"" ] + } } } else if (chip_device_platform == "none") { buildconfig_header("platform_buildconfig") {