-
Notifications
You must be signed in to change notification settings - Fork 80
/
trezor-t-emu.spec
130 lines (108 loc) · 4.67 KB
/
trezor-t-emu.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- mode: python -*-
import glob
import os
import sys
block_cipher = None
base_dir = os.path.dirname(os.path.realpath('__file__'))
data_files = []
binary_files = []
version_str = '?.?.?'
emu_binary = os.path.join(base_dir, 'hardware-wallets', 'trezor-core-emu', sys.platform, 'micropython')
emu_base_dir_from = os.path.join(base_dir, 'hardware-wallets', 'trezor-core-emu')
def add_data_file(file: str, dest_dir: str):
data_files.append((file, dest_dir))
print(f'Adding file {file} to dest dir {dest_dir}')
def add_binary_file(file: str, dest_dir: str):
global bianry_files
binary_files.append((file, dest_dir))
print(f'Adding binary file {file} to dest dir {dest_dir}')
with open(os.path.join(emu_base_dir_from, 'version.txt')) as fptr:
for line in fptr:
parts = [elem.strip() for elem in line.split('=')]
if len(parts) == 2 and parts[0].lower() == 'version_str':
version_str = parts[1].strip("'")
break
if os.path.exists(emu_base_dir_from):
emu_dir_len_src = len(emu_base_dir_from)
print('Trezor emulator dir exists: ' + emu_base_dir_from)
for subdir, recursive in (('embed/**', True), ('src/**', True), ('**', False)):
for fname in glob.iglob(os.path.join(emu_base_dir_from, subdir), recursive=recursive):
if os.path.isfile(fname):
if fname.startswith(base_dir):
dest_dir = fname[emu_dir_len_src:]
if dest_dir and dest_dir[0] == '/' or '\\':
dest_dir = dest_dir[1:]
dest_dir = os.path.dirname(dest_dir)
if not dest_dir:
dest_dir = '.'
else:
dest_dir = '.'
add_data_file(fname, dest_dir)
add_binary_file(emu_binary, '.')
if sys.platform == 'darwin':
add_binary_file('/usr/lib/libSystem.B.dylib', '.')
add_binary_file('/usr/local/opt/sdl2_image/lib/libSDL2_image-2.0.0.dylib', '.')
add_binary_file('/usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib', '.')
add_binary_file('/usr/local/lib/libwebp.7.dylib', '.')
add_binary_file('/usr/local/lib/libusb-1.0.dylib', '.')
add_binary_file('/usr/local/lib/libpng16.16.dylib', '.')
add_binary_file('/usr/local/lib/libjpeg.9.dylib', '.')
add_binary_file('/usr/local/lib/libtiff.5.dylib', '.')
add_binary_file('/usr/local/lib/libpng16.16.dylib', '.')
add_binary_file('/usr/local/lib/libpng16.16.dylib', '.')
elif sys.platform == 'linux':
add_binary_file('/usr/lib/x86_64-linux-gnu/libSDL2_image-2.0.so.0', '.')
add_binary_file('/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0', '.')
add_binary_file('/usr/lib/x86_64-linux-gnu/libwebp.so.5', '.')
add_binary_file('/usr/lib/x86_64-linux-gnu/libusb-1.0.so', '.')
add_binary_file('/usr/lib/x86_64-linux-gnu/libsndio.so.6.1', '.')
else:
print('Trezor emulator dir does not exist: ' + emu_base_dir_from)
a = Analysis(['src/trezor-t-emu.py'],
pathex=[base_dir],
binaries=binary_files,
datas=data_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='TrezorT-emulator',
debug=False,
strip=False,
upx=False,
console=False,
icon=os.path.join('img',('hw-emulator.%s' % ('icns' if sys.platform=='darwin' else 'ico'))))
if sys.platform == 'darwin':
app = BUNDLE(exe,
name='TrezorT-emulator.app',
icon='img/hw-emulator.icns',
bundle_identifier=None,
info_plist={
'NSHighResolutionCapable': 'True'
})
dist_path = os.path.join(base_dir, DISTPATH)
all_bin_dir = os.path.join(dist_path, '..', 'all')
if not os.path.exists(all_bin_dir):
os.makedirs(all_bin_dir)
# zip archives
print(dist_path)
print(all_bin_dir)
os.chdir(dist_path)
if sys.platform == 'darwin':
print('Compressing Mac executable')
os.system('zip -r "%s" "%s"' % (os.path.join(all_bin_dir, 'TrezorT-emulator_' + version_str + '.mac.zip'), 'TrezorT-emulator.app'))
elif sys.platform == 'linux':
print('Compressing Linux executable')
os.system('tar -zcvf %s %s' % (os.path.join(all_bin_dir, 'TrezorT-emulator_' + version_str + '.linux.tar.gz'), 'TrezorT-emulator'))