Debian Codegraph @

src/device_trezor/trezor/tools/build_protob.py

raw symbols SCIP
1 #!/usr/bin/env python
2 import os
3 import subprocess
4 import sys
5 import argparse
6
7
8 parser = argparse.ArgumentParser()
9 parser.add_argument("-d", "--debug-msg", default=False, action="store_const", const=True, help="Build debug messages")
10 args = parser.parse_args()
11
12 CWD = os.path.dirname(os.path.realpath(__file__))
13 ROOT_DIR = os.path.abspath(os.path.join(CWD, "..", "..", "..", ".."))
14 TREZOR_COMMON = os.path.join(ROOT_DIR, "external", "trezor-common")
15 TREZOR_MESSAGES = os.path.join(CWD, "..", "messages")
16
17 # check for existence of the submodule directory
18 common_defs = os.path.join(TREZOR_COMMON, "defs")
19 if not os.path.exists(common_defs):
20 raise ValueError(
21 "trezor-common submodule seems to be missing.\n"
22 + 'Use "git submodule update --init --recursive" to retrieve it.'
23 )
24
25 # regenerate messages
26 try:
27 selected = [
28 "messages.proto",
29 "messages-common.proto",
30 "messages-management.proto",
31 "messages-monero.proto",
32 ]
33
34 if args.debug_msg:
35 selected += ["messages-debug.proto"]
36
37 proto_srcs = [os.path.join(TREZOR_COMMON, "protob", x) for x in selected]
38 exec_args = [
39 sys.executable,
40 os.path.join(CWD, "pb2cpp.py"),
41 "-o",
42 TREZOR_MESSAGES,
43 ] + proto_srcs
44
45 subprocess.check_call(exec_args)
46
47 except Exception as e:
48 raise