forked from Chia-Network/chia-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyinstaller.spec
169 lines (126 loc) · 4.25 KB
/
pyinstaller.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- mode: python ; coding: utf-8 -*-
import importlib
import pathlib
import platform
from pkg_resources import get_distribution
from PyInstaller.utils.hooks import collect_submodules, copy_metadata
THIS_IS_WINDOWS = platform.system().lower().startswith("win")
ROOT = pathlib.Path(importlib.import_module("chia").__file__).absolute().parent.parent
def solve_name_collision_problem(analysis):
"""
There is a collision between the `chia` file name (which is the executable)
and the `chia` directory, which contains non-code resources like `english.txt`.
We move all the resources in the zipped area so there is no
need to create the `chia` directory, since the names collide.
Fetching data now requires going into a zip file, so it will be slower.
It's best if files that are used frequently are cached.
A sample large compressible file (1 MB of `/dev/zero`), seems to be
about eight times slower.
Note that this hack isn't documented, but seems to work.
"""
zipped = []
datas = []
for data in analysis.datas:
if str(data[0]).startswith("chia/"):
zipped.append(data)
else:
datas.append(data)
# items in this field are included in the binary
analysis.zipped_data = zipped
# these items will be dropped in the root folder uncompressed
analysis.datas = datas
keyring_imports = collect_submodules("keyring.backends")
# keyring uses entrypoints to read keyring.backends from metadata file entry_points.txt.
keyring_datas = copy_metadata("keyring")[0]
version_data = copy_metadata(get_distribution("chia-blockchain"))[0]
block_cipher = None
SERVERS = [
"wallet",
"full_node",
"harvester",
"farmer",
"introducer",
"timelord",
]
# TODO: collapse all these entry points into one `chia_exec` entrypoint that accepts the server as a parameter
entry_points = ["chia.cmds.chia"] + [f"chia.server.start_{s}" for s in SERVERS]
hiddenimports = []
hiddenimports.extend(entry_points)
hiddenimports.extend(keyring_imports)
binaries = []
if THIS_IS_WINDOWS:
hiddenimports.extend(["win32timezone", "win32cred", "pywintypes", "win32ctypes.pywin32"])
# this probably isn't necessary
if THIS_IS_WINDOWS:
entry_points.extend(["aiohttp", "chia.util.bip39"])
if THIS_IS_WINDOWS:
chia_mod = importlib.import_module("chia")
dll_paths = ROOT / "*.dll"
binaries = [
(
dll_paths,
".",
),
(
"C:\\Windows\\System32\\msvcp140.dll",
".",
),
(
"C:\\Windows\\System32\\vcruntime140_1.dll",
".",
),
]
datas = []
datas.append((f"{ROOT}/chia/util/english.txt", "chia/util"))
datas.append((f"{ROOT}/chia/util/initial-config.yaml", "chia/util"))
datas.append((f"{ROOT}/chia/wallet/puzzles/*.hex", "chia/wallet/puzzles"))
datas.append((f"{ROOT}/chia/ssl/*", "chia/ssl"))
datas.append((f"{ROOT}/mozilla-ca/*", "mozilla-ca"))
datas.append(version_data)
pathex = []
def add_binary(name, path_to_script, collect_args):
analysis = Analysis(
[path_to_script],
pathex=pathex,
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
solve_name_collision_problem(analysis)
binary_pyz = PYZ(analysis.pure, analysis.zipped_data, cipher=block_cipher)
binary_exe = EXE(
binary_pyz,
analysis.scripts,
[],
exclude_binaries=True,
name=name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
)
collect_args.extend(
[
binary_exe,
analysis.binaries,
analysis.zipfiles,
analysis.datas,
]
)
COLLECT_ARGS = []
add_binary("chia", f"{ROOT}/chia/cmds/chia.py", COLLECT_ARGS)
add_binary("daemon", f"{ROOT}/chia/daemon/server.py", COLLECT_ARGS)
for server in SERVERS:
add_binary(f"start_{server}", f"{ROOT}/chia/server/start_{server}.py", COLLECT_ARGS)
COLLECT_KWARGS = dict(
strip=False,
upx_exclude=[],
name="daemon",
)
coll = COLLECT(*COLLECT_ARGS, **COLLECT_KWARGS)