2018-08-24 00:50:53 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2018-11-20 15:40:51 +02:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-d", "--debug-msg", default=False, action="store_const", const=True, help="Build debug messages")
|
|
|
|
args = parser.parse_args()
|
2018-08-24 00:50:53 +03:00
|
|
|
|
|
|
|
CWD = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
ROOT_DIR = os.path.abspath(os.path.join(CWD, "..", "..", "..", ".."))
|
|
|
|
TREZOR_COMMON = os.path.join(ROOT_DIR, "external", "trezor-common")
|
|
|
|
TREZOR_MESSAGES = os.path.join(CWD, "..", "messages")
|
|
|
|
|
|
|
|
# check for existence of the submodule directory
|
|
|
|
common_defs = os.path.join(TREZOR_COMMON, "defs")
|
|
|
|
if not os.path.exists(common_defs):
|
|
|
|
raise ValueError(
|
|
|
|
"trezor-common submodule seems to be missing.\n"
|
|
|
|
+ 'Use "git submodule update --init --recursive" to retrieve it.'
|
|
|
|
)
|
|
|
|
|
|
|
|
# regenerate messages
|
|
|
|
try:
|
|
|
|
selected = [
|
|
|
|
"messages.proto",
|
|
|
|
"messages-common.proto",
|
|
|
|
"messages-management.proto",
|
|
|
|
"messages-monero.proto",
|
|
|
|
]
|
2018-11-20 15:40:51 +02:00
|
|
|
|
|
|
|
if args.debug_msg:
|
|
|
|
selected += ["messages-debug.proto"]
|
|
|
|
|
2018-08-24 00:50:53 +03:00
|
|
|
proto_srcs = [os.path.join(TREZOR_COMMON, "protob", x) for x in selected]
|
|
|
|
exec_args = [
|
|
|
|
sys.executable,
|
|
|
|
os.path.join(CWD, "pb2cpp.py"),
|
|
|
|
"-o",
|
|
|
|
TREZOR_MESSAGES,
|
|
|
|
] + proto_srcs
|
|
|
|
|
|
|
|
subprocess.check_call(exec_args)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
raise
|