2012-04-26 16:25:04 +00:00
import shutil , optparse , os , re , sys , zipfile
2018-12-03 09:40:34 +00:00
from distutils . dir_util import copy_tree
2012-04-26 16:25:04 +00:00
os . chdir ( os . path . dirname ( os . path . realpath ( sys . argv [ 0 ] ) ) + " /.. " )
import twlib
2019-01-07 19:10:22 +00:00
arguments = optparse . OptionParser ( usage = " usage: % prog VERSION PLATFORM [options] \n \n VERSION - Version number \n PLATFORM - Target platform (f.e. linux_x86, linux_x86_64, osx, src, win32, win64) " )
2012-12-23 18:09:00 +00:00
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 " )
2012-04-26 16:25:04 +00:00
arguments . add_option ( " -s " , " --source-dir " , help = " Source directory which is used for building the package " )
( options , arguments ) = arguments . parse_args ( )
2012-12-23 18:09:00 +00:00
if len ( sys . argv ) != 3 :
print ( " wrong number of arguments " )
print ( sys . argv [ 0 ] , " VERSION PLATFORM " )
2012-07-07 10:26:25 +00:00
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 )
2012-04-26 16:25:04 +00:00
2019-01-06 21:09:54 +00:00
valid_platforms = [ " win32 " , " win64 " , " osx " , " linux_x86 " , " linux_x86_64 " , " src " ]
2012-04-26 16:25:04 +00:00
2008-03-22 18:40:27 +00:00
name = " teeworlds "
2012-12-23 18:09:00 +00:00
version = sys . argv [ 1 ]
2012-07-07 10:26:25 +00:00
platform = sys . argv [ 2 ]
2007-08-04 22:51:41 +00:00
exe_ext = " "
use_zip = 0
2007-12-09 13:36:54 +00:00
use_gz = 1
2009-01-11 12:10:30 +00:00
use_dmg = 0
2007-12-15 11:44:27 +00:00
use_bundle = 0
2007-12-09 13:36:54 +00:00
include_data = True
include_exe = True
include_src = False
2019-01-05 22:37:47 +00:00
if not platform in valid_platforms :
print ( " not a valid platform " )
print ( valid_platforms )
sys . exit ( - 1 )
2007-08-04 22:51:41 +00:00
2012-07-07 10:26:25 +00:00
if platform == " src " :
2012-04-26 16:25:04 +00:00
include_exe = False
include_src = True
use_zip = 1
2013-05-01 22:38:32 +00:00
elif platform == ' win32 ' or platform == ' win64 ' :
2007-08-04 22:51:41 +00:00
exe_ext = " .exe "
use_zip = 1
2007-12-09 13:36:54 +00:00
use_gz = 0
2012-07-07 10:26:25 +00:00
elif platform == ' osx ' :
2009-01-11 12:10:30 +00:00
use_dmg = 1
2007-12-15 11:44:27 +00:00
use_gz = 0
2008-10-08 16:33:08 +00:00
use_bundle = 1
2007-08-04 22:51:41 +00:00
2012-02-05 16:20:57 +00:00
def unzip ( filename , where ) :
try :
z = zipfile . ZipFile ( filename , " r " )
except :
return False
for name in z . namelist ( ) :
2012-12-23 18:09:00 +00:00
z . extract ( name , where )
2012-02-05 16:20:57 +00:00
z . close ( )
return z . namelist ( ) [ 0 ]
2007-12-09 13:36:54 +00:00
def copydir ( src , dst , excl = [ ] ) :
2007-08-04 22:51:41 +00:00
for root , dirs , files in os . walk ( src , topdown = True ) :
2007-08-04 23:06:58 +00:00
if " /. " in root or " \\ . " in root :
2007-08-04 22:51:41 +00:00
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 ) )
2012-02-05 16:20:57 +00:00
2012-12-23 18:09:00 +00:00
def copyfiles ( src , dst ) :
dir = os . listdir ( src )
for files in dir :
shutil . copy ( os . path . join ( src , files ) , os . path . join ( dst , files ) )
2012-02-05 16:20:57 +00:00
def clean ( ) :
print ( " *** cleaning *** " )
try :
2012-04-26 16:25:04 +00:00
shutil . rmtree ( package_dir )
shutil . rmtree ( languages_dir )
2012-12-23 18:09:00 +00:00
shutil . rmtree ( maps_dir )
2012-04-26 16:25:04 +00:00
os . remove ( src_package_languages )
2012-12-23 18:09:00 +00:00
os . remove ( src_package_maps )
2012-02-05 16:20:57 +00:00
except : pass
2012-07-07 10:26:25 +00:00
package = " %s - %s - %s " % ( name , version , platform )
2007-08-04 22:51:41 +00:00
package_dir = package
2018-11-23 18:41:54 +00:00
source_package_dir = " build/ "
if platform == ' win32 ' or platform == ' linux_x86 ' :
source_package_dir + = " x86/release/ "
else :
source_package_dir + = " x86_64/release/ "
2011-04-02 02:49:14 +00:00
print ( " cleaning target " )
2007-08-04 22:51:41 +00:00
shutil . rmtree ( package_dir , True )
os . mkdir ( package_dir )
2007-12-09 13:36:54 +00:00
2012-02-05 16:20:57 +00:00
print ( " download and extract languages " )
2012-04-26 16:25:04 +00:00
src_package_languages = twlib . fetch_file ( options . url_languages )
2012-02-05 16:20:57 +00:00
if not src_package_languages :
2012-04-26 16:25:04 +00:00
print ( " couldn ' t download languages " )
sys . exit ( - 1 )
2012-02-05 16:20:57 +00:00
languages_dir = unzip ( src_package_languages , " . " )
if not languages_dir :
2012-04-26 16:25:04 +00:00
print ( " couldn ' t unzip languages " )
sys . exit ( - 1 )
2012-02-05 16:20:57 +00:00
2012-12-23 18:09:00 +00:00
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 )
2011-04-02 02:49:14 +00:00
print ( " adding files " )
2014-06-19 17:56:03 +00:00
shutil . copy ( " readme.md " , package_dir )
2007-12-09 13:36:54 +00:00
shutil . copy ( " license.txt " , package_dir )
2010-10-06 21:07:35 +00:00
shutil . copy ( " storage.cfg " , package_dir )
2007-08-04 22:51:41 +00:00
2007-12-15 11:44:27 +00:00
if include_data and not use_bundle :
2018-12-03 09:40:34 +00:00
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 " )
2012-07-07 10:26:25 +00:00
if platform [ : 3 ] == " win " :
2007-12-13 18:46:43 +00:00
shutil . copy ( " other/config_directory.bat " , package_dir )
2018-11-23 18:41:54 +00:00
shutil . copy ( source_package_dir + " SDL2.dll " , package_dir )
shutil . copy ( source_package_dir + " freetype.dll " , package_dir )
2007-12-09 13:36:54 +00:00
2007-12-15 11:44:27 +00:00
if include_exe and not use_bundle :
2018-11-23 18:41:54 +00:00
shutil . copy ( source_package_dir + name + exe_ext , package_dir )
shutil . copy ( source_package_dir + name + " _srv " + exe_ext , package_dir )
2007-12-09 13:36:54 +00:00
if include_src :
2007-12-15 14:40:39 +00:00
for p in [ " src " , " scripts " , " datasrc " , " other " , " objs " ] :
2007-12-09 13:36:54 +00:00
os . mkdir ( os . path . join ( package_dir , p ) )
copydir ( p , package_dir )
2010-12-05 17:43:01 +00:00
shutil . copy ( " bam.lua " , package_dir )
shutil . copy ( " configure.lua " , package_dir )
2007-08-04 22:51:41 +00:00
2007-12-15 11:44:27 +00:00
if use_bundle :
2011-11-13 00:30:03 +00:00
bins = [ name , name + ' _srv ' , ' serverlaunch ' ]
2018-12-03 09:40:34 +00:00
platforms = ( ' x86_64 ' )
2011-11-13 00:30:03 +00:00
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 :
os . system ( " lipo -create -output " + bin + " " + " " . join ( to_lipo ) )
2009-01-12 20:04:14 +00:00
# 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 " )
2018-12-03 09:40:34 +00:00
binary_path = clientbundle_bin_dir + " / " + name + exe_ext
2018-12-03 19:26:07 +00:00
freetypelib_path = clientbundle_framework_dir + " /libfreetype.6.dylib "
2008-03-22 18:40:27 +00:00
os . mkdir ( os . path . join ( package_dir , " Teeworlds.app " ) )
2009-01-12 20:04:14 +00:00
os . mkdir ( clientbundle_content_dir )
os . mkdir ( clientbundle_bin_dir )
os . mkdir ( clientbundle_resource_dir )
os . mkdir ( clientbundle_framework_dir )
2018-12-03 09:40:34 +00:00
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 " )
2009-01-12 20:04:14 +00:00
shutil . copy ( " other/icons/Teeworlds.icns " , clientbundle_resource_dir )
2018-12-03 09:40:34 +00:00
shutil . copy ( source_package_dir + name + exe_ext , clientbundle_bin_dir )
os . system ( " install_name_tool -change /usr/local/opt/freetype/lib/libfreetype.6.dylib @executable_path/../Frameworks/libfreetype.6.dylib " + binary_path )
os . system ( " install_name_tool -change /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib @executable_path/../Frameworks/libSDL2-2.0.0.dylib " + binary_path )
os . system ( " cp /usr/local/opt/freetype/lib/libfreetype.6.dylib " + clientbundle_framework_dir )
2018-12-03 19:26:07 +00:00
os . system ( " cp /usr/local/opt/libpng/lib/libpng16.16.dylib " + clientbundle_framework_dir )
2018-12-03 09:40:34 +00:00
os . system ( " cp /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib " + clientbundle_framework_dir )
2018-12-03 19:26:07 +00:00
os . system ( " install_name_tool -change /usr/local/opt/libpng/lib/libpng16.16.dylib @executable_path/../Frameworks/libpng16.16.dylib " + freetypelib_path )
2009-01-12 20:04:14 +00:00
file ( os . path . join ( clientbundle_content_dir , " Info.plist " ) , " w " ) . write ( """
2007-12-15 13:01:09 +00:00
< ? 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 >
2012-04-26 16:25:04 +00:00
< 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 >
2018-12-03 09:40:34 +00:00
< key > CFBundleIdentifier < / key >
< string > com . TeeworldsClient . app < / string >
< key > NSHighResolutionCapable < / key >
2018-12-04 17:37:29 +00:00
< true / >
2007-12-15 13:01:09 +00:00
< / dict >
< / plist >
2012-07-07 10:26:25 +00:00
""" % (version))
2009-01-12 20:04:14 +00:00
file ( 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 " ) )
2010-10-06 21:07:35 +00:00
os . mkdir ( os . path . join ( serverbundle_resource_dir , " data/mapres " ) )
2018-12-03 09:40:34 +00:00
copy_tree ( maps_dir , serverbundle_resource_dir + " /data/maps " )
2009-01-12 20:04:14 +00:00
shutil . copy ( " other/icons/Teeworlds_srv.icns " , serverbundle_resource_dir )
2018-12-03 09:40:34 +00:00
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 " )
2009-01-12 20:04:14 +00:00
file ( 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 >
2012-04-26 16:25:04 +00:00
< 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 >
2009-01-12 20:04:14 +00:00
< / dict >
< / plist >
2012-07-07 10:26:25 +00:00
""" % (version))
2009-01-12 20:04:14 +00:00
file ( os . path . join ( serverbundle_content_dir , " PkgInfo " ) , " w " ) . write ( " APPL???? " )
2007-12-15 11:44:27 +00:00
2007-08-04 22:51:41 +00:00
if use_zip :
2011-04-02 02:49:14 +00:00
print ( " making zip archive " )
2007-08-04 22:51:41 +00:00
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 )
2007-12-09 13:36:54 +00:00
#zf.printdir()
2007-08-04 22:51:41 +00:00
zf . close ( )
2007-12-09 13:36:54 +00:00
if use_gz :
2011-04-02 02:49:14 +00:00
print ( " making tar.gz archive " )
2007-12-09 13:36:54 +00:00
os . system ( " tar czf %s .tar.gz %s " % ( package , package_dir ) )
2009-01-11 12:10:30 +00:00
if use_dmg :
2011-04-02 02:49:14 +00:00
print ( " making disk image " )
2009-01-11 12:10:30 +00:00
os . system ( " rm -f %s .dmg %s _temp.dmg " % ( package , package ) )
os . system ( " hdiutil create -srcfolder %s -volname Teeworlds -quiet %s _temp " % ( package_dir , package ) )
os . system ( " hdiutil convert %s _temp.dmg -format UDBZ -o %s .dmg -quiet " % ( package , package ) )
os . system ( " rm -f %s _temp.dmg " % package )
2012-02-05 16:20:57 +00:00
clean ( )
2007-12-09 13:36:54 +00:00
2011-04-02 02:49:14 +00:00
print ( " done " )