forked from renpy/renpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distribute.py
executable file
·236 lines (169 loc) · 5.9 KB
/
distribute.py
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
#!/home/tom/ab/renpy/lib/linux-x86_64/python -O
# Builds a distribution of Ren'Py.
import sys
import os
import compileall
import shutil
import subprocess
import argparse
import glob
if not sys.flags.optimize:
raise Exception("Optimization disabled.")
ROOT = os.path.dirname(os.path.abspath(__file__))
def copy_tutorial_file(src, dest):
"""
Copies a file from src to dst. Lines between "# tutorial-only" and
"# end-tutorial-only" comments are omitted from the copy.
"""
sf = open(src, "rb")
df = open(dest, "wb")
# True if we want to copy the line.
copy = True
for l in sf:
if "# tutorial-only" in l:
copy = False
elif "# end-tutorial-only" in l:
copy = True
else:
if copy:
df.write(l)
sf.close()
df.close()
def main():
if not sys.flags.optimize:
raise Exception("Not running with python optimization.")
ap = argparse.ArgumentParser()
ap.add_argument("version")
ap.add_argument("--fast", action="store_true")
ap.add_argument("--pygame", action="store", default=None)
ap.add_argument("--no-rapt", action="store_true")
args = ap.parse_args()
# Revision updating is done early, so we can do it even if the rest
# of the program fails.
# Determine the version. We grab the current revision, and if any
# file has changed, bump it by 1.
import renpy
match_version = ".".join(str(i) for i in renpy.version_tuple[:2]) #@UndefinedVariable
s = subprocess.check_output([ "git", "describe", "--tags", "--dirty", "--match", "start-" + match_version ])
parts = s.strip().split("-")
if len(parts) <= 3:
vc_version = 0
else:
vc_version = int(parts[2])
if parts[-1] == "dirty":
vc_version += 1
with open("renpy/vc_version.py", "w") as f:
f.write("vc_version = {}".format(vc_version))
try:
reload(sys.modules['renpy.vc_version']) #@UndefinedVariable
except:
import renpy.vc_version # @UnusedImport
reload(sys.modules['renpy'])
# Check that the versions match.
full_version = renpy.version_only #@UndefinedVariable
if "-" not in args.version \
and not full_version.startswith(args.version):
raise Exception("The command-line and Ren'Py versions do not match.")
os.environ['RENPY_BUILD_VERSION'] = args.version
# The destination directory.
destination = os.path.join("dl", args.version)
print "Version {} ({})".format(args.version, full_version)
# Perhaps autobuild.
if "RENPY_BUILD_ALL" in os.environ:
print("Autobuild...")
subprocess.check_call(["scripts/autobuild.sh"])
# Copy over the screens, to keep them up to date.
copy_tutorial_file("tutorial/game/screens.rpy", "templates/english/game/screens.rpy")
# Compile all the python files.
compileall.compile_dir("renpy/", ddir="renpy/", force=1, quiet=1)
# Compile the various games.
if not args.fast:
for i in [ 'tutorial', 'launcher', 'the_question' ]:
print "Compiling", i
subprocess.check_call(["./renpy.sh", i, "quit" ])
# Kick off the rapt build.
if not args.fast:
print "Cleaning RAPT."
sys.path.insert(0, os.path.join(ROOT, "rapt", "buildlib"))
import rapt.interface # @UnresolvedImport
import rapt.build # @UnresolvedImport
interface = rapt.interface.Interface()
rapt.build.distclean(interface)
print "Compiling RAPT and renios."
compileall.compile_dir("rapt/buildlib/", ddir="rapt/buildlib/", quiet=1)
compileall.compile_dir("renios/buildlib/", ddir="renios/buildlib/", quiet=1)
if not os.path.exists(destination):
os.makedirs(destination)
if args.fast:
cmd = [
"./renpy.sh",
"launcher",
"distribute",
"launcher",
"--package",
"sdk",
"--destination",
destination,
"--no-update",
]
else:
cmd = [
"./renpy.sh",
"launcher",
"distribute",
"launcher",
"--destination",
destination,
]
print
subprocess.check_call(cmd)
# Sign the update.
if not args.fast:
subprocess.check_call([
"scripts/sign_update.py",
"/home/tom/ab/keys/renpy_private.pem",
os.path.join(destination, "updates.json"),
])
# Package pygame_sdl2.
if not args.fast:
subprocess.check_call([
"pygame_sdl2/distribute.py",
"for-renpy-" + args.version,
"--dest",
os.path.abspath(destination)
])
# Write 7z.exe.
sdk = "renpy-{}-sdk".format(args.version)
if not args.fast:
# shutil.copy("renpy-ppc.zip", os.path.join(destination, "renpy-ppc.zip"))
with open("7z.sfx", "rb") as f:
sfx = f.read()
os.chdir(destination)
if os.path.exists(sdk):
shutil.rmtree(sdk)
subprocess.check_call([ "unzip", "-q", sdk + ".zip" ])
if os.path.exists(sdk + ".7z"):
os.unlink(sdk + ".7z")
sys.stdout.write("Creating -sdk.7z")
p = subprocess.Popen([ "7z", "a", sdk +".7z", sdk], stdout=subprocess.PIPE)
for i, _l in enumerate(p.stdout):
if i % 10 != 0:
continue
sys.stdout.write(".")
sys.stdout.flush()
if p.wait() != 0:
raise Exception("7z failed")
with open(sdk + ".7z", "rb") as f:
data = f.read()
with open(sdk + ".7z.exe", "wb") as f:
f.write(sfx)
f.write(data)
os.unlink(sdk + ".7z")
shutil.rmtree(sdk)
else:
os.chdir(destination)
if os.path.exists(sdk + ".7z.exe"):
os.unlink(sdk + ".7z.exe")
print
if __name__ == "__main__":
main()