build: more resilient setup.py build process

pull/25/head
matejcik 6 years ago
parent 2243535ca0
commit 9a27ada067

@ -2,6 +2,7 @@
import os.path import os.path
import shutil import shutil
import subprocess import subprocess
import tempfile
from setuptools import setup, Command from setuptools import setup, Command
from setuptools.command.build_py import build_py from setuptools.command.build_py import build_py
@ -19,13 +20,14 @@ install_requires = [
from trezorlib import __version__ as VERSION from trezorlib import __version__ as VERSION
CWD = os.path.dirname(os.path.realpath(__file__))
TREZOR_COMMON = os.path.join(CWD, 'vendor', 'trezor-common')
class PrebuildCommand(Command): class PrebuildCommand(Command):
description = 'update vendored files (coins.json, protobuf messages)' description = 'update vendored files (coins.json, protobuf messages)'
user_options = [] user_options = []
TREZOR_COMMON = os.path.join('vendor', 'trezor-common')
def initialize_options(self): def initialize_options(self):
pass pass
@ -34,19 +36,20 @@ class PrebuildCommand(Command):
def run(self): def run(self):
# check for existence of the submodule directory # check for existence of the submodule directory
common_defs = os.path.join(self.TREZOR_COMMON, 'defs') common_defs = os.path.join(TREZOR_COMMON, 'defs')
if not os.path.exists(common_defs): if not os.path.exists(common_defs):
raise Exception('trezor-common submodule seems to be missing.\n' + raise Exception('trezor-common submodule seems to be missing.\n' +
'Use "git submodule update --init" to retrieve it.') 'Use "git submodule update --init" to retrieve it.')
# generate and copy coins.json to the tree # generate and copy coins.json to the tree
build_coins = os.path.join(self.TREZOR_COMMON, 'defs', 'coins', 'tools', 'build_coins.py') with tempfile.TemporaryDirectory() as tmpdir:
subprocess.check_call([build_coins]) build_coins = os.path.join(TREZOR_COMMON, 'defs', 'coins', 'tools', 'build_coins.py')
shutil.move('coins.json', 'trezorlib') subprocess.check_call([build_coins], cwd=tmpdir)
shutil.copy(os.path.join(tmpdir, 'coins.json'), os.path.join(CWD, 'trezorlib', 'coins.json'))
# regenerate messages # regenerate messages
try: try:
subprocess.check_call([os.path.join(os.getcwd(), 'tools', 'build_protobuf'), '--no-core']) subprocess.check_call([os.path.join(CWD, 'tools', 'build_protobuf'), '--no-core'])
except Exception as e: except Exception as e:
print(e) print(e)
print("Generating protobuf failed. Maybe you don't have 'protoc', or maybe you are on Windows?") print("Generating protobuf failed. Maybe you don't have 'protoc', or maybe you are on Windows?")

Loading…
Cancel
Save