forked from teeworlds/teeworlds
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_release.py
279 lines (251 loc) · 9.73 KB
/
make_release.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
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
import shutil, optparse, os, re, sys, zipfile
from distutils.dir_util import copy_tree
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])) + "/..")
import twlib
arguments = optparse.OptionParser(usage="usage: %prog VERSION PLATFORM [options]\n\nVERSION - Version number\nPLATFORM - Target platform (f.e. linux_x86, linux_x86_64, osx, src, win32, win64)")
arguments.add_option("-l", "--url-languages", default = "http://github.com/teeworlds/teeworlds-translation/archive/master.zip", help = "URL from which the teeworlds language files will be downloaded")
arguments.add_option("-m", "--url-maps", default = "http://github.com/teeworlds/teeworlds-maps/archive/master.zip", help = "URL from which the teeworlds maps files will be downloaded")
arguments.add_option("-s", "--source-dir", help = "Source directory which is used for building the package")
(options, arguments) = arguments.parse_args()
if len(sys.argv) != 3:
print("wrong number of arguments")
print(sys.argv[0], "VERSION PLATFORM")
sys.exit(-1)
if options.source_dir != None:
if os.path.exists(options.source_dir) == False:
print("Source directory " + options.source_dir + " doesn't exist")
exit(1)
os.chdir(options.source_dir)
valid_platforms = ["win32", "win64", "osx", "linux_x86", "linux_x86_64", "src"]
name = "teeworlds"
version = sys.argv[1]
platform = sys.argv[2]
exe_ext = ""
use_zip = 0
use_gz = 1
use_dmg = 0
use_bundle = 0
include_data = True
include_exe = True
include_src = False
if not platform in valid_platforms:
print("not a valid platform")
print(valid_platforms)
sys.exit(-1)
if platform == "src":
include_exe = False
include_src = True
use_zip = 1
elif platform == 'win32' or platform == 'win64':
exe_ext = ".exe"
use_zip = 1
use_gz = 0
elif platform == 'osx':
use_dmg = 1
use_gz = 0
use_bundle = 1
def unzip(filename, where):
try:
z = zipfile.ZipFile(filename, "r")
except:
return False
for name in z.namelist():
z.extract(name, where)
z.close()
return z.namelist()[0]
def copydir(src, dst, excl=[]):
for root, dirs, files in os.walk(src, topdown=True):
if "/." in root or "\\." in root:
continue
for name in dirs:
if name[0] != '.':
os.mkdir(os.path.join(dst, root, name))
for name in files:
if name[0] != '.':
shutil.copy(os.path.join(root, name), os.path.join(dst, root, name))
def copyfiles(src, dst):
dir = os.listdir(src)
for files in dir:
shutil.copy(os.path.join(src, files), os.path.join(dst, files))
def clean():
print("*** cleaning ***")
try:
shutil.rmtree(package_dir)
shutil.rmtree(languages_dir)
shutil.rmtree(maps_dir)
os.remove(src_package_languages)
os.remove(src_package_maps)
except: pass
def shell(cmd):
if os.system(cmd) != 0:
clean()
print("Non zero exit code on: os.system(%s)" % cmd)
sys.exit(1)
package = "%s-%s-%s" %(name, version, platform)
package_dir = package
source_package_dir = "build/"
if platform == 'win32' or platform == 'linux_x86':
source_package_dir += "x86/release/"
else:
source_package_dir += "x86_64/release/"
print("cleaning target")
shutil.rmtree(package_dir, True)
os.mkdir(package_dir)
print("download and extract languages")
src_package_languages = twlib.fetch_file(options.url_languages)
if not src_package_languages:
print("couldn't download languages")
sys.exit(-1)
languages_dir = unzip(src_package_languages, ".")
if not languages_dir:
print("couldn't unzip languages")
sys.exit(-1)
print("download and extract maps")
src_package_maps = twlib.fetch_file(options.url_maps)
if not src_package_maps:
print("couldn't download maps")
sys.exit(-1)
maps_dir = unzip(src_package_maps, ".")
if not maps_dir:
print("couldn't unzip maps")
sys.exit(-1)
print("adding files")
shutil.copy("readme.md", package_dir)
shutil.copy("license.txt", package_dir)
shutil.copy("storage.cfg", package_dir)
if include_data and not use_bundle:
copy_tree(source_package_dir+"data", package_dir+"/data")
copy_tree(languages_dir, package_dir+"/data/languages")
copy_tree(maps_dir, package_dir+"/data/maps")
if platform[:3] == "win":
shutil.copy("other/config_directory.bat", package_dir)
shutil.copy(source_package_dir+"SDL2.dll", package_dir)
shutil.copy(source_package_dir+"freetype.dll", package_dir)
if include_exe and not use_bundle:
shutil.copy(source_package_dir+name+exe_ext, package_dir)
shutil.copy(source_package_dir+name+"_srv"+exe_ext, package_dir)
if include_src:
for p in ["src", "scripts", "datasrc", "other", "objs"]:
os.mkdir(os.path.join(package_dir, p))
copydir(p, package_dir)
shutil.copy("bam.lua", package_dir)
shutil.copy("configure.lua", package_dir)
if use_bundle:
bins = [name, name+'_srv', 'serverlaunch']
platforms = ('x86_64')
for bin in bins:
to_lipo = []
for p in platforms:
fname = bin+'_'+p
if os.path.isfile(fname):
to_lipo.append(fname)
if to_lipo:
shell("lipo -create -output "+bin+" "+" ".join(to_lipo))
# create Teeworlds appfolder
clientbundle_content_dir = os.path.join(package_dir, "Teeworlds.app/Contents")
clientbundle_bin_dir = os.path.join(clientbundle_content_dir, "MacOS")
clientbundle_resource_dir = os.path.join(clientbundle_content_dir, "Resources")
clientbundle_framework_dir = os.path.join(clientbundle_content_dir, "Frameworks")
binary_path = clientbundle_bin_dir + "/" + name+exe_ext
freetypelib_path = clientbundle_framework_dir + "/libfreetype.6.dylib"
os.mkdir(os.path.join(package_dir, "Teeworlds.app"))
os.mkdir(clientbundle_content_dir)
os.mkdir(clientbundle_bin_dir)
os.mkdir(clientbundle_resource_dir)
os.mkdir(clientbundle_framework_dir)
copy_tree(source_package_dir+"data", clientbundle_resource_dir+"/data")
copy_tree(languages_dir, clientbundle_resource_dir+"/data/languages")
copy_tree(maps_dir, clientbundle_resource_dir+"/data/maps")
shutil.copy("other/icons/Teeworlds.icns", clientbundle_resource_dir)
shutil.copy(source_package_dir+name+exe_ext, clientbundle_bin_dir)
shell("install_name_tool -change /usr/local/opt/freetype/lib/libfreetype.6.dylib @executable_path/../Frameworks/libfreetype.6.dylib " + binary_path)
shell("install_name_tool -change /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib @executable_path/../Frameworks/libSDL2-2.0.0.dylib " + binary_path)
shell("cp /usr/local/opt/freetype/lib/libfreetype.6.dylib " + clientbundle_framework_dir)
shell("cp /usr/local/opt/libpng/lib/libpng16.16.dylib " + clientbundle_framework_dir)
shell("cp /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib " + clientbundle_framework_dir)
shell("install_name_tool -change /usr/local/opt/libpng/lib/libpng16.16.dylib @executable_path/../Frameworks/libpng16.16.dylib " + freetypelib_path)
open(os.path.join(clientbundle_content_dir, "Info.plist"), "w").write("""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>teeworlds</string>
<key>CFBundleIconFile</key>
<string>Teeworlds</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>%s</string>
<key>CFBundleIdentifier</key>
<string>com.TeeworldsClient.app</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
""" % (version))
open(os.path.join(clientbundle_content_dir, "PkgInfo"), "w").write("APPL????")
# create Teeworlds Server appfolder
serverbundle_content_dir = os.path.join(package_dir, "Teeworlds Server.app/Contents")
serverbundle_bin_dir = os.path.join(serverbundle_content_dir, "MacOS")
serverbundle_resource_dir = os.path.join(serverbundle_content_dir, "Resources")
os.mkdir(os.path.join(package_dir, "Teeworlds Server.app"))
os.mkdir(serverbundle_content_dir)
os.mkdir(serverbundle_bin_dir)
os.mkdir(serverbundle_resource_dir)
os.mkdir(os.path.join(serverbundle_resource_dir, "data"))
os.mkdir(os.path.join(serverbundle_resource_dir, "data/maps"))
os.mkdir(os.path.join(serverbundle_resource_dir, "data/mapres"))
copy_tree(maps_dir, serverbundle_resource_dir+"/data/maps")
shutil.copy("other/icons/Teeworlds_srv.icns", serverbundle_resource_dir)
shutil.copy(source_package_dir+name+"_srv"+exe_ext, serverbundle_bin_dir)
shutil.copy(source_package_dir+"serverlaunch"+exe_ext, serverbundle_bin_dir + "/"+name+"_server")
open(os.path.join(serverbundle_content_dir, "Info.plist"), "w").write("""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>teeworlds_server</string>
<key>CFBundleIconFile</key>
<string>Teeworlds_srv</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>%s</string>
</dict>
</plist>
""" % (version))
open(os.path.join(serverbundle_content_dir, "PkgInfo"), "w").write("APPL????")
if use_zip:
print("making zip archive")
zf = zipfile.ZipFile("%s.zip" % package, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(package_dir, topdown=True):
for name in files:
n = os.path.join(root, name)
zf.write(n, n)
#zf.printdir()
zf.close()
if use_gz:
print("making tar.gz archive")
shell("tar czf %s.tar.gz %s" % (package, package_dir))
if use_dmg:
print("making disk image")
shell("rm -f %s.dmg %s_temp.dmg" % (package, package))
shell("hdiutil create -srcfolder %s -volname Teeworlds -quiet %s_temp" % (package_dir, package))
shell("hdiutil convert %s_temp.dmg -format UDBZ -o %s.dmg -quiet" % (package, package))
shell("rm -f %s_temp.dmg" % package)
clean()
print("done")