1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

chore(common): include error explanation in protobuf messages check

This commit is contained in:
grdddj 2022-03-07 12:22:37 +01:00 committed by matejcik
parent b9858f00c5
commit 42fab282af

View File

@ -10,10 +10,12 @@ MYDIR = os.path.dirname(__file__)
EXPECTED_PREFIX_RE = re.compile(r"messages-(\w+)(?:-.*)?\.proto") EXPECTED_PREFIX_RE = re.compile(r"messages-(\w+)(?:-.*)?\.proto")
# Checking all protobuf files for their `enum` and `message` declarations
# and making sure their names start with expected prefix
for fn in sorted(glob(os.path.join(MYDIR, "messages-*.proto"))): for fn in sorted(glob(os.path.join(MYDIR, "messages-*.proto"))):
with open(fn, "rt") as f: with open(fn, "rt") as f:
prefix = EXPECTED_PREFIX_RE.search(fn).group(1).capitalize() prefix = EXPECTED_PREFIX_RE.search(fn).group(1).capitalize()
if prefix in ["Bitcoin", "Bootloader", "Common", "Crypto", "Management"]: if prefix in ("Bitcoin", "Bootloader", "Common", "Crypto", "Management"):
continue continue
if prefix == "Nem": if prefix == "Nem":
prefix = "NEM" prefix = "NEM"
@ -21,12 +23,14 @@ for fn in sorted(glob(os.path.join(MYDIR, "messages-*.proto"))):
prefix = "WebAuthn" prefix = "WebAuthn"
for line in f: for line in f:
line = line.strip().split(" ") line = line.strip().split(" ")
if line[0] not in ["enum", "message"]: if line[0] not in ("enum", "message"):
continue continue
if not line[1].startswith(prefix) and not line[1].startswith( expected_prefixes = (prefix, f"Debug{prefix}")
"Debug" + prefix if not line[1].startswith(expected_prefixes):
): print("ERROR: protobuf message does not start with expected prefix")
print("ERROR:", fn, line[1]) print(f" file: {fn}")
print(f" message: {line[1]}")
print(f" expected prefixes: {expected_prefixes}")
error = True error = True
if error: if error: