-
Notifications
You must be signed in to change notification settings - Fork 2
/
makerules
executable file
·105 lines (85 loc) · 3.11 KB
/
makerules
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
#!/usr/bin/env python3
#
# Copyright (C) 2024 Simon Howard
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. This program is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
from glob import glob
import os
from os.path import dirname, basename, exists, join
import shlex
import sys
import yaml
def escape_filename(filename):
return filename.replace("#", "\\#")
def read_config(path):
if path == '':
return {}
# Config deeper in the hierarchy can override config files from
# higher up in the hierarchy:
result = read_config(dirname(path))
config_file = join(path, ".democonfig")
if exists(config_file):
with open(config_file) as f:
result.update(yaml.safe_load(f))
return result
class Rule:
def __init__(self, expect_file):
self.out_file = expect_file.replace("expected/", "output/")
self.lmp_file = (
expect_file.replace("expected/", "demos/")
.replace(".txt", ".lmp"))
self.cfg = read_config(self.lmp_file)
def wads(self):
yield join("iwads", self.cfg["iwad"])
pwad = self.cfg.get("pwad")
if pwad is not None:
yield join("extract", pwad)
def dependencies(self):
yield self.lmp_file
yield "$(SOURCE_PORT)"
yield from self.wads()
deh = self.cfg.get("deh")
if deh is not None:
yield join("extract", deh)
def game_arguments(self):
result = [
"$(DOOMOPTS)",
"-statdump", "$@",
"-iwad", join("iwads", self.cfg["iwad"]),
"-timedemo", "$<"
]
if "extra_args" in self.cfg:
result.extend(shlex.split(self.cfg["extra_args"]))
if "deh" in self.cfg:
result.extend(("-deh", join("extract", self.cfg["deh"])))
if "gameversion" in self.cfg:
result.extend(("-gameversion", self.cfg["gameversion"]))
if "pwad" in self.cfg:
result.extend(("-merge", join("extract", self.cfg["pwad"])))
return result
def command(self):
args = self.game_arguments()
return "$(SOURCE_PORT) " + " ".join(args) + " >/dev/null 2>&1"
def rule_output(self):
result = "%s: %s\n" % (
escape_filename(self.out_file), " ".join(
escape_filename(f) for f in self.dependencies()),
)
result += "\t@mkdir -p %s\n" % (shlex.quote(dirname(self.out_file)))
result += "\t%s || true\n\n" % self.command()
return result
depends_file = sys.argv[1]
rules = []
all_wads = set()
with open(depends_file, "w") as f:
for filename in sorted(glob("expected/**/*.txt", recursive=True)):
r = Rule(filename)
f.write(r.rule_output())
all_wads = all_wads | set(r.wads())
f.write("wads: %s\n" % shlex.join(all_wads))