m143: Generate Dawn version as array instead of string This can reduce the device key's length further. Bug: 439845637 Fixed: 461363158 Change-Id: I10812ad74cc7f4e8ee727f283374ea46cbb5d2e6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/272236 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Quyen Le <lehoangquyen@chromium.org> (cherry picked from commit c650c2e0cfb08afb0d40ddb6f8c05d1af8ba2e92) Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/274237
diff --git a/generator/dawn_version_generator.py b/generator/dawn_version_generator.py index 7e2bc8c..71a6fb7 100644 --- a/generator/dawn_version_generator.py +++ b/generator/dawn_version_generator.py
@@ -106,9 +106,24 @@ return get_git_hash(os.path.abspath(args.dawn_dir)) +def get_version_byte_array(version_str): + version_str = version_str.strip() + if not version_str: + # If the version string is empty, generate an array of 20 zero bytes. + return ", ".join(["0x00"] * 20) + assert len( + version_str + ) == 40, "Version string must be a 40-character git hash if not empty." + byte_values = [ + f"0x{version_str[i:i+2]}" for i in range(0, len(version_str), 2) + ] + return ", ".join(byte_values) + + def compute_params(args): + version = get_version(args) return { - "get_version": lambda: get_version(args), + "get_version_byte_array": lambda: get_version_byte_array(version), }
diff --git a/generator/templates/dawn/common/Version.h b/generator/templates/dawn/common/Version.h index fbfd493..ca540d6 100644 --- a/generator/templates/dawn/common/Version.h +++ b/generator/templates/dawn/common/Version.h
@@ -28,14 +28,14 @@ #ifndef COMMON_VERISON_AUTOGEN_H_ #define COMMON_VERISON_AUTOGEN_H_ -#include <string_view> +#include <array> +#include <cstdint> namespace dawn { -// The version string should either be a valid git hash or empty. -static constexpr std::string_view kDawnVersion("{{get_version()}}"); -static_assert(kDawnVersion.size() == 40 || kDawnVersion.size() == 0); +// The version is a 20-byte SHA1 hash. If the hash is not available, it is all zeros. +static constexpr std::array<uint8_t, 20> kDawnVersion = { {{get_version_byte_array()}} }; -} // namespace dawn +} // namespace dawn #endif // COMMON_VERISON_AUTOGEN_H_