-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathpostcompiler.spec
More file actions
151 lines (134 loc) · 4.04 KB
/
postcompiler.spec
File metadata and controls
151 lines (134 loc) · 4.04 KB
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
"""Build the postcompiler script."""
from pathlib import Path
import shutil
import importlib.metadata
from srctools.dmx import Element as DMXElem
from PyInstaller.utils.hooks import collect_submodules
import versioningit
from hammeraddons.config import GameConfig
# PyInstaller-injected.
SPECPATH: str
workpath: str
root = Path(SPECPATH) # noqa
# Resave the games config as a binary DMX.
with open(root / 'games.dmx', 'rb') as f:
print('Reading: ', f.name)
games_conf, games_fmt_name, games_fmt_ver = DMXElem.parse(f)
# Validate all the options, by parsing them.
for game_attr in games_conf.values():
if game_attr.name != 'name':
try:
GameConfig.parse(game_attr.val_elem)
except Exception as exc:
exc.add_note(f'Bad config: {game_attr!r}')
raise
# Then merge search path entries to simplify.
GameConfig.optimise(games_conf)
version = versioningit.get_version(SPECPATH, {
'vcs': {'method': 'git'},
'default-version': '(dev)',
'format': {
'distance': '{version}.dev_{distance}+{rev}',
'dirty': '{version}+dirty_{build_date:%Y%m%d}',
'distance-dirty': '{version}.dev_{distance}+{rev}.dirty_{build_date:%Y%m%d}',
},
})
src_version = importlib.metadata.version('srctools')
with open(Path(SPECPATH, 'src', 'hammeraddons', '_version.py'), 'w') as f:
f.write(f'HADDONS_VER = {version!r}\nSRCTOOLS_VER = {src_version!r}\n')
DATAS = [
(str(root / 'crowbar_command/Crowbar.exe'), '.'),
(str(root / 'crowbar_command/FluentCommandLineParser.dll'), '.'),
]
a = Analysis(
['src/hammeraddons/postcompiler.py'],
binaries=[],
datas=DATAS,
hiddenimports=[
# Ensure these modules are available for plugins.
'abc', 'array', 'base64', 'binascii', 'graphlib',
'bisect', 'colorsys', 'collections', 'csv', 'datetime', 'contextlib',
'decimal', 'difflib', 'enum', 'fractions', 'functools',
'io', 'itertools', 'json', 'math', 'random', 're',
'statistics', 'string', 'struct',
*collect_submodules('srctools', filter=lambda name: 'scripts' not in name),
*collect_submodules('attr'),
*collect_submodules('attrs'),
*collect_submodules('hammeraddons'),
],
excludes=[
'IPython', # Via trio
'tkinter',
],
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='postcompiler',
debug=False,
bootloader_ignore_signals=False,
# Don't use bin/, in case someone puts this right in a game dir.
contents_directory='binaries',
strip=False,
upx=True,
console=True,
icon="postcompiler.ico",
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='postcompiler'
)
# Copy transforms to the same place as the EXE, not into the binaries subfolder.
app_folder = Path(coll.name)
for file in (root / 'transforms').rglob('*.py'):
dest = app_folder / file.relative_to(root)
print(file, '->', dest)
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(file, dest)
with open(app_folder / 'binaries' / 'games.dmx', 'wb') as f:
print('Writing: ', f.name)
games_conf.export_binary(f, fmt_name=games_fmt_name, fmt_ver=games_fmt_ver, unicode='format')
gen_choreo = Analysis(
['src/hammeraddons/gen_choreo.py'],
binaries=[],
datas=[],
hiddenimports=[],
excludes=[
'IPython', # Via trio
],
noarchive=False,
)
gen_choreo_pyz = PYZ(gen_choreo.pure, gen_choreo.zipped_data)
gen_choreo_exe = EXE(
gen_choreo_pyz,
gen_choreo.scripts,
[],
exclude_binaries=True,
name='gen_choreo',
debug=False,
bootloader_ignore_signals=False,
# Don't use bin/, in case someone puts this right in a game dir.
contents_directory='binaries',
strip=False,
upx=True,
console=True,
icon="postcompiler.ico",
)
gen_choreo_coll = COLLECT(
gen_choreo_exe,
gen_choreo.binaries,
gen_choreo.zipfiles,
gen_choreo.datas,
strip=False,
upx=True,
name='gen_choreo'
)