-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsconstruct.py
More file actions
342 lines (261 loc) · 9.79 KB
/
sconstruct.py
File metadata and controls
342 lines (261 loc) · 9.79 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# SPDX-FileCopyrightText: © 2025 Alexander Kromm <mmaulwurff@gmail.com>
# SPDX-License-Identifier: CC0-1.0
# This is build definitions for DoomToolbox.
# See https://scons.github.io/docs/scons-user.html for details.
# TODO: move autoadvance to config.ini?
# +wi_autoadvance 1\
# TODO: add targets to build all packages and to run all tests.
# TODO: fix parallel builds (-j 4). Check with moules of Typist.pk3.
# May be a problem with cleaning, if main target is built after a module.
from os import environ, makedirs, path
from pathlib import Path
from re import search, sub, MULTILINE
from shutil import copy, copytree, make_archive, move, rmtree, which
from subprocess import PIPE, STDOUT, TimeoutExpired, run
from SCons.Script import (
Alias,
AlwaysBuild,
Command,
Decider,
Default,
DefaultEnvironment,
Depends,
Glob,
Help,
)
import git
import reuse.project
import reuse.report
# General setup
Decider('timestamp-match')
Default(None)
DefaultEnvironment(ENV=environ.copy())
emacs = which('emacs-nox') or which('emacs') or Path('c:/tools/emacs/bin/emacs.exe')
uzdoom = which('uzdoom') or Path(path.expanduser('~')) / 'UZDoom.AppImage'
# Common functions
def make_project_name(org_file):
return path.splitext(path.basename(org_file))[0]
def make_export(source):
build_el_path = path.abspath('tools/build.el')
level = len(path.normpath(source).split(path.sep))
return f'{emacs} {source} --quick --batch \
--load {build_el_path}\
--eval "(dt-export {level})"'
# Target setup functions
def add_main_target(org_file, target_format):
name = make_project_name(org_file)
zscript_name = target_format.format(name)
build_el_path = path.abspath('tools/build.el')
tangle = f'{emacs} $SOURCE --quick --batch \
--load {build_el_path} \
--eval "(dt-tangle)"'
def clean(target, source, env):
rmtree(f'build/{name}', True)
return Alias(
name, Command(target=zscript_name, source=org_file, action=[clean, tangle])
)
def add_html_target(org_file, main_target):
name = make_project_name(org_file)
html_name = f'{name}Html'
def putHtml(target, source, env):
move(f'{name}.html', f'build/{name}/{name}.html')
makedirs(f'build/{name}/tools/', exist_ok=True)
copy('tools/org-adwaita.css', f'build/{name}/tools/org-adwaita.css')
return AlwaysBuild(Alias(html_name, main_target, [make_export(org_file), putHtml]))
def add_test_target(org_file, main_target):
name = make_project_name(org_file)
test_name = f'{name}Test'
def run_test(target, source, env):
args = [
uzdoom,
'-noautoload',
'-nosound',
'-config',
'./build/config.ini',
'-iwad',
'./tools/miniwad.wad',
'-file',
'./tools/ClematisM-v2.1.0.pk3',
f'./build/{name}',
f'./build/{name}Test',
f'+exec {f"./build/{name}Test/commands.txt"}',
]
if not Path('build/config.ini').exists():
copy('tools/config.ini', 'build/config.ini')
# Script errors cause an error window to appear,
# and execution waits for user to press the button.
# To not bother with closing this window programmatically, just time out.
try:
result = run(stdout=PIPE, stderr=STDOUT, text=True, args=args, timeout=60 * 3)
except TimeoutExpired:
print('timeout')
return 1
with open(
'tools/IgnoredEngineOutput.txt', encoding='utf-8'
) as lines_to_skip_file:
lines_to_skip = [line.rstrip() for line in lines_to_skip_file]
def printable(line):
return not any([search(to_skip, line) for to_skip in lines_to_skip])
has_errors = False
for line in filter(printable, result.stdout.splitlines()):
line = sub(r'(.*)/:(.*), line (.*)', r'\1/\2:\3', line)
line = sub(r'Script error, \"(.*)/:(.*)\" line (.*)', r'ERROR: \1/\2:\3', line)
line = sub(
r'Script warning, \"(.*)/:(.*)\" line (.*)', r'WARNING: \1/\2:\3', line
)
has_errors = has_errors or 'ERROR' in line or 'WARNING' in line
print(line)
return 1 if has_errors else 0
return AlwaysBuild(Alias(test_name, main_target, run_test))
def add_pack_target(org_file, main_target):
name = make_project_name(org_file)
pack_name = f'{name}.pk3'
build_path = Path(f'build/{name}')
def pack(target, source, env):
with open(org_file, encoding='utf-8') as project_file:
project_content = project_file.read()
commit_sha = git.Repo().head.object.hexsha[:10]
foundVersion = search('^#[+]version: *(.*)$', project_content, flags=MULTILINE)
version = foundVersion.group(1) if foundVersion is not None else commit_sha
copytree('documentation', build_path / 'documentation', dirs_exist_ok=True)
copy(org_file, build_path / org_file)
licenses_path = build_path / 'LICENSES'
makedirs(licenses_path, exist_ok=True)
project = reuse.project.Project.from_directory(build_path)
for license in reuse.report.ProjectReport.generate(project).used_licenses:
copy('LICENSES/' + license + '.txt', licenses_path)
archive = make_archive(Path(str(build_path) + '-' + version), 'zip', build_path)
move(archive, Path(archive).with_suffix('.pk3'))
return AlwaysBuild(Alias(pack_name, main_target, pack))
def make_check_compatibility_target():
names = []
for org_file in Glob('*.org'):
if str(org_file) != 'README.org':
names.append(make_project_name(org_file))
projects = ['./build/' + name for name in names]
def check_compatibility(target, source, env):
args = [
uzdoom,
'-noautoload',
'-nosound',
'-config',
'./build/config.ini',
'-iwad',
'./tools/miniwad.wad',
'+map map01; wait 2; quit',
'-file',
]
args += projects
if not Path('build/config.ini').exists():
copy('tools/config.ini', 'build/config.ini')
# Script errors cause an error window to appear,
# and execution waits for user to press the button.
# To not bother with closing this window programmatically, just time out.
try:
result = run(stdout=PIPE, stderr=STDOUT, text=True, args=args, timeout=60 * 3)
except TimeoutExpired:
print('timeout')
return 1
with open(
'tools/IgnoredEngineOutput.txt', encoding='utf-8'
) as lines_to_skip_file:
lines_to_skip = [line.rstrip() for line in lines_to_skip_file]
def printable(line):
return not any([search(to_skip, line) for to_skip in lines_to_skip])
for line in filter(printable, result.stdout.splitlines()):
print(line)
return 0
return check_compatibility
def make_index(target, source, env):
copy('README.html', 'index.html')
# Targets
pk3_all = Alias('Pk3All', None, None)
test_all = Alias('TestAll', None, None)
module_targets = []
for org_file in Glob('modules/*.org'):
main_target = add_main_target(org_file, 'build/{0}/{0}.zs')
test_target = add_test_target(org_file, main_target)
Depends(test_all, test_target)
module_targets.append(f'{main_target[0]}, {test_target[0]}')
project_targets = []
for org_file in Glob('*.org'):
if str(org_file) != 'README.org':
main_target = add_main_target(org_file, 'build/{0}/zscript.zs')
html_target = add_html_target(org_file, main_target)
test_target = add_test_target(org_file, main_target)
pack_target = add_pack_target(org_file, html_target)
Depends(test_all, test_target)
Depends(pk3_all, pack_target)
project_targets.append(
f'{main_target[0]}, {html_target[0]}, {test_target[0]}, {pack_target[0]}'
)
html_all = Alias('HtmlAll', None, make_index)
for org_file in Glob('*/*.org') + Glob('*.org'):
html_name = f'{path.splitext(org_file)[0]}.html'
Depends(
html_all,
Command(target=html_name, source=org_file, action=make_export(org_file)),
)
AlwaysBuild(
Alias(
'LintAll',
None,
[
f'{emacs} {org_file} --quick --batch --eval "(print (org-lint))"'
for org_file in Glob('*/*.org') + Glob('*.org')
],
)
)
AlwaysBuild(Alias('CheckCompatibility', None, make_check_compatibility_target()))
for org_file in Glob('*.org'):
if str(org_file) != 'README.org':
Depends('CheckCompatibility', make_project_name(org_file))
# Dependencies
def add_dependency(project, module, namespace):
target_directory = f'build/{project}/zscript'
def export_module(target, source, env):
makedirs(target_directory, exist_ok=True)
destination = f'{target_directory}/{namespace}{module}.zs'
with open(destination, 'w', encoding='utf-8') as target_file:
with open(source[0], encoding='utf-8') as module_file:
target_file.write(module_file.read().replace('NAMESPACE_', namespace))
Depends(
project,
Command(
target=project + module,
source=f'build/{module}/{module}.zs',
action=export_module,
),
)
add_dependency('VmAbortReporter', 'StringUtils', 'NAMESPACE_')
add_dependency('DoomDoctor', 'StringUtils', 'dd_')
add_dependency('DoomDoctor', 'VmAbortReporter', 'dd_')
add_dependency('FinalCustomDoom', 'PlainTranslator', 'cd_')
add_dependency('SoundToScreen', 'PlainTranslator', 'st_')
add_dependency('TargetSpy', 'StringUtils', 'ts_')
add_dependency('TargetSpy', 'libeye', 'ts_')
add_dependency('Typist.pk3', 'libeye', 'tt_le_')
add_dependency('Typist.pk3', 'LazyPoints', 'tt_lp_')
add_dependency('Typist.pk3', 'StringUtils', 'tt_su_')
add_dependency('Typist.pk3', 'PlainTranslator', 'tt_')
add_dependency('Gearbox', 'MD5', 'gb_')
add_dependency('Gearbox', 'PreviousWeapon', 'gb_')
add_dependency('Gearbox', 'StringUtils', 'gb_')
add_dependency('Gearbox', 'VmAbortReporter', 'gb_')
add_dependency('Gearbox', 'PlainTranslator', 'gb_')
# Help
Help(
f"""
Modules:
- {'\n- '.join(module_targets)}
Projects:
- {'\n- '.join(project_targets)}
General targets:
- Pk3All: build packages for all mods
- TestAll: test all packages and modules
- LintAll: run org-lint for all Org files
- CheckCompatibility: check that all projects can be loaded together
Type 'scons <target>' to build a target.
""",
append=False,
)