2010-12-05 22:01:05 +00:00
|
|
|
import imp, optparse, os, re, shutil, sys, zipfile
|
|
|
|
from optparse import OptionParser
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
import urllib
|
|
|
|
url_lib = urllib
|
|
|
|
elif sys.version_info[0] == 3:
|
|
|
|
import urllib.request
|
|
|
|
url_lib = urllib.request
|
2011-04-02 02:47:19 +00:00
|
|
|
match = re.search('(.*)/', sys.argv[0])
|
2010-12-05 22:01:05 +00:00
|
|
|
if match != None:
|
2011-04-02 02:47:19 +00:00
|
|
|
os.chdir(match.group(1))
|
2011-05-06 16:27:06 +00:00
|
|
|
os.chdir('../')
|
2010-12-05 22:01:05 +00:00
|
|
|
|
|
|
|
url_bam = "http://github.com/matricks/bam/zipball/master"
|
|
|
|
url_teeworlds = "http://github.com/oy/teeworlds/zipball/master"
|
|
|
|
release_type = "server_release client_release"
|
|
|
|
|
|
|
|
arguments = OptionParser()
|
|
|
|
arguments.add_option("-b", "--url_bam", dest = "url_bam")
|
|
|
|
arguments.add_option("-t", "--url_teeworlds", dest = "url_teeworlds")
|
|
|
|
arguments.add_option("-r", "--release_type", dest = "release_type")
|
|
|
|
(options, arguments) = arguments.parse_args()
|
|
|
|
if options.url_bam == None:
|
|
|
|
options.url_bam = url_bam
|
|
|
|
if options.url_teeworlds == None:
|
|
|
|
options.url_teeworlds = url_teeworlds
|
|
|
|
if options.release_type == None:
|
|
|
|
options.release_type = release_type
|
|
|
|
|
|
|
|
bam = options.url_bam[7:].split("/")
|
|
|
|
version_bam = re.search(r"\d\.\d\.\d", bam[len(bam)-1])
|
|
|
|
if version_bam:
|
|
|
|
version_bam = version_bam.group(0)
|
|
|
|
else:
|
|
|
|
version_bam = "trunk"
|
|
|
|
teeworlds = options.url_teeworlds[7:].split("/")
|
|
|
|
version_teeworlds = re.search(r"\d\.\d\.\d", teeworlds[len(teeworlds)-1])
|
|
|
|
if version_teeworlds:
|
|
|
|
version_teeworlds = version_teeworlds.group(0)
|
|
|
|
else:
|
|
|
|
version_teeworlds = "trunk"
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
bam_execution_path = ""
|
|
|
|
if version_bam < "0.3.0":
|
|
|
|
bam_execution_path = "src%s" % os.sep
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
name = "teeworlds"
|
2008-03-22 18:40:27 +00:00
|
|
|
|
2007-12-12 21:53:06 +00:00
|
|
|
flag_clean = True
|
2011-04-02 02:58:45 +00:00
|
|
|
flag_download = True
|
|
|
|
flag_unpack = True
|
|
|
|
flag_build_bam = True
|
|
|
|
flag_build_teeworlds = True
|
|
|
|
flag_make_release = True
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
if os.name == "nt":
|
|
|
|
platform = "win32"
|
|
|
|
else:
|
|
|
|
# get name
|
2008-03-22 19:33:45 +00:00
|
|
|
osname = os.popen("uname").readline().strip().lower()
|
|
|
|
if osname == "darwin":
|
|
|
|
osname = "osx"
|
2010-12-05 22:01:05 +00:00
|
|
|
|
2007-12-12 21:53:06 +00:00
|
|
|
# get arch
|
|
|
|
machine = os.popen("uname -m").readline().strip().lower()
|
|
|
|
arch = "unknown"
|
2010-12-05 22:01:05 +00:00
|
|
|
|
2007-12-12 21:53:06 +00:00
|
|
|
if machine[0] == "i" and machine[2:] == "86":
|
|
|
|
arch = "x86"
|
|
|
|
elif machine == "x86_64":
|
|
|
|
arch = "x86_64"
|
|
|
|
elif "power" in machine.lower():
|
|
|
|
arch = "ppc"
|
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
platform = osname + "_" + arch
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
print("%s-%s-%s" % (name, version_teeworlds, platform))
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
root_dir = os.getcwd() + os.sep
|
2011-05-06 16:27:06 +00:00
|
|
|
work_dir = root_dir + "scripts/work"
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
def fetch_file(url):
|
2007-12-12 21:53:06 +00:00
|
|
|
try:
|
2010-12-05 22:01:05 +00:00
|
|
|
print("trying %s" % url)
|
|
|
|
real_url = url_lib.urlopen(url).geturl()
|
|
|
|
local = real_url.split("/")
|
|
|
|
local = local[len(local)-1].split("?")
|
|
|
|
local = local[0]
|
|
|
|
url_lib.urlretrieve(real_url, local)
|
|
|
|
return local
|
2007-12-12 21:53:06 +00:00
|
|
|
except:
|
2010-12-05 22:01:05 +00:00
|
|
|
return False
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
def unzip(filename, where):
|
2010-12-05 22:01:05 +00:00
|
|
|
try:
|
|
|
|
z = zipfile.ZipFile(filename, "r")
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
list = "\n"
|
2007-12-12 21:53:06 +00:00
|
|
|
for name in z.namelist():
|
2010-12-05 22:01:05 +00:00
|
|
|
list += "%s\n" % name
|
2007-12-12 21:53:06 +00:00
|
|
|
try: os.makedirs(where+"/"+os.path.dirname(name))
|
|
|
|
except: pass
|
2010-12-05 22:01:05 +00:00
|
|
|
|
2009-01-11 12:35:37 +00:00
|
|
|
try:
|
2010-12-05 22:01:05 +00:00
|
|
|
f = open(where+"/"+name, "wb")
|
2009-01-11 12:35:37 +00:00
|
|
|
f.write(z.read(name))
|
|
|
|
f.close()
|
|
|
|
except: pass
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
z.close()
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
directory = "[^/\n]*?/"
|
|
|
|
part_1 = "(?<=\n)"
|
|
|
|
part_2 = "[^/\n]+(?=\n)"
|
|
|
|
regular_expression = r"%s%s" % (part_1, part_2)
|
|
|
|
main_directory = re.search(regular_expression, list)
|
|
|
|
while main_directory == None:
|
|
|
|
part_1 += directory
|
|
|
|
regular_expression = r"%s%s" % (part_1, part_2)
|
|
|
|
main_directory = re.search(regular_expression, list)
|
|
|
|
main_directory = re.search(r".*/", "./%s" % main_directory.group(0))
|
|
|
|
return main_directory.group(0)
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
def bail(reason):
|
2010-12-05 22:01:05 +00:00
|
|
|
print(reason)
|
|
|
|
os.chdir(work_dir)
|
2007-12-12 21:53:06 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
def clean():
|
|
|
|
print("*** cleaning ***")
|
2011-05-06 16:27:06 +00:00
|
|
|
try: shutil.rmtree(work_dir)
|
2007-12-12 21:53:06 +00:00
|
|
|
except: pass
|
2010-12-05 22:01:05 +00:00
|
|
|
|
|
|
|
def file_exists(file):
|
|
|
|
try:
|
|
|
|
open(file).close()
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
return False;
|
|
|
|
|
2011-04-02 02:58:45 +00:00
|
|
|
def search_object(directory, object):
|
|
|
|
directory = os.listdir(directory)
|
|
|
|
for entry in directory:
|
|
|
|
match = re.search(object, entry)
|
|
|
|
if match != None:
|
|
|
|
return entry
|
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
# clean
|
|
|
|
if flag_clean:
|
|
|
|
clean()
|
|
|
|
|
2007-12-12 21:53:06 +00:00
|
|
|
# make dir
|
2011-05-06 16:27:06 +00:00
|
|
|
try: os.mkdir(work_dir)
|
2007-12-12 21:53:06 +00:00
|
|
|
except: pass
|
|
|
|
|
|
|
|
# change dir
|
2010-12-05 22:01:05 +00:00
|
|
|
os.chdir(work_dir)
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
# download
|
|
|
|
if flag_download:
|
2010-12-05 22:01:05 +00:00
|
|
|
print("*** downloading bam source package ***")
|
|
|
|
src_package_bam = fetch_file(options.url_bam)
|
|
|
|
if src_package_bam:
|
|
|
|
if version_bam == 'trunk':
|
|
|
|
version = re.search(r"-[^-]*?([^-]*?)\.[^.]*$", src_package_bam)
|
|
|
|
if version:
|
|
|
|
version_bam = version.group(1)
|
|
|
|
else:
|
2011-04-02 02:58:45 +00:00
|
|
|
bail("couldn't find bam source package and couldn't download it")
|
2010-12-05 22:01:05 +00:00
|
|
|
|
|
|
|
print("*** downloading %s source package ***" % name)
|
|
|
|
src_package_teeworlds = fetch_file(options.url_teeworlds)
|
|
|
|
if src_package_teeworlds:
|
|
|
|
if version_teeworlds == 'trunk':
|
|
|
|
version = re.search(r"-[^-]*?([^-]*?)\.[^.]*$", src_package_teeworlds)
|
|
|
|
if version:
|
|
|
|
version_teeworlds = version.group(1)
|
|
|
|
else:
|
2011-04-02 02:58:45 +00:00
|
|
|
bail("couldn't find %s source package and couldn't download it" % name)
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
# unpack
|
2011-04-02 02:58:45 +00:00
|
|
|
if flag_unpack:
|
|
|
|
print("*** unpacking source ***")
|
|
|
|
if hasattr(locals(), 'src_package_bam') == False:
|
|
|
|
src_package_bam = search_object(work_dir, r"bam.*?\.")
|
|
|
|
if not src_package_bam:
|
|
|
|
bail("couldn't find bam source package")
|
|
|
|
src_dir_bam = unzip(src_package_bam, ".")
|
|
|
|
if not src_dir_bam:
|
|
|
|
bail("couldn't unpack bam source package")
|
2010-12-05 22:01:05 +00:00
|
|
|
|
2011-04-02 02:58:45 +00:00
|
|
|
if hasattr(locals(), 'src_package_teeworlds') == False:
|
|
|
|
src_package_teeworlds = search_object(work_dir, r"teeworlds.*?\.")
|
|
|
|
if not src_package_bam:
|
|
|
|
bail("couldn't find %s source package" % name)
|
|
|
|
src_dir_teeworlds = unzip(src_package_teeworlds, ".")
|
|
|
|
if not src_dir_teeworlds:
|
|
|
|
bail("couldn't unpack %s source package" % name)
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
# build bam
|
2011-04-02 02:58:45 +00:00
|
|
|
if flag_build_bam:
|
2010-12-05 22:01:05 +00:00
|
|
|
print("*** building bam ***")
|
|
|
|
os.chdir("%s/%s" % (work_dir, src_dir_bam))
|
2007-12-12 21:53:06 +00:00
|
|
|
if os.name == "nt":
|
2010-12-05 22:01:05 +00:00
|
|
|
bam_compiled = False
|
|
|
|
compiler_bam = ["cl", "gcc"]
|
|
|
|
for compiler in compiler_bam:
|
|
|
|
if compiler == "cl":
|
|
|
|
os.system("make_win32_msvc.bat")
|
|
|
|
elif compiler == "gcc":
|
|
|
|
os.system("make_win32_mingw.bat")
|
|
|
|
if file_exists("%sbam.exe" % bam_execution_path) == True:
|
|
|
|
bam_compiled = True
|
|
|
|
break
|
|
|
|
if bam_compiled == False:
|
2007-12-12 21:53:06 +00:00
|
|
|
bail("failed to build bam")
|
|
|
|
else:
|
2010-12-05 22:01:05 +00:00
|
|
|
os.system("sh make_unix.sh")
|
|
|
|
if file_exists("%sbam" % bam_execution_path) == False:
|
2007-12-12 21:53:06 +00:00
|
|
|
bail("failed to build bam")
|
2010-12-05 22:01:05 +00:00
|
|
|
os.chdir(work_dir)
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2008-03-22 18:40:27 +00:00
|
|
|
# build the game
|
2011-04-02 02:58:45 +00:00
|
|
|
if flag_build_teeworlds:
|
2010-12-05 22:01:05 +00:00
|
|
|
print("*** building %s ***" % name)
|
2011-04-02 02:58:45 +00:00
|
|
|
if hasattr(locals(), 'src_dir_bam') == False:
|
|
|
|
src_dir_bam = search_object(work_dir, r"bam[^\.]*$") + os.sep
|
|
|
|
if src_dir_bam:
|
|
|
|
directory = src_dir_bam + bam_execution_path
|
|
|
|
file = r"bam"
|
|
|
|
if os.name == "nt":
|
|
|
|
file += r"\.exe"
|
|
|
|
if not search_object(directory, file):
|
|
|
|
bail("couldn't find bam")
|
|
|
|
else:
|
|
|
|
bail("couldn't find bam")
|
|
|
|
if hasattr(locals(), 'src_dir_teeworlds') == False:
|
|
|
|
src_dir_teeworlds = search_object(work_dir, r"teeworlds[^\.]*$")
|
|
|
|
if not src_dir_teeworlds:
|
|
|
|
bail("couldn't find %s source" % name)
|
|
|
|
command = 1
|
2010-12-05 22:01:05 +00:00
|
|
|
if os.name == "nt":
|
2010-12-16 02:14:31 +00:00
|
|
|
file = open("build.bat", "wb")
|
|
|
|
content = "@echo off\n"
|
|
|
|
content += "@REM check if we already have the tools in the environment\n"
|
|
|
|
content += "if exist \"%VCINSTALLDIR%\" (\ngoto compile\n)\n"
|
|
|
|
content += "@REM Check for Visual Studio\n"
|
|
|
|
content += "if exist \"%VS100COMNTOOLS%\" (\nset VSPATH=\"%VS100COMNTOOLS%\"\ngoto set_env\n)\n"
|
|
|
|
content += "if exist \"%VS90COMNTOOLS%\" (\nset VSPATH=\"%VS90COMNTOOLS%\"\ngoto set_env\n)\n"
|
|
|
|
content += "if exist \"%VS80COMNTOOLS%\" (\nset VSPATH=\"%VS80COMNTOOLS%\"\ngoto set_env\n)\n\n"
|
|
|
|
content += "echo You need Microsoft Visual Studio 8, 9 or 10 installed\n"
|
|
|
|
content += "exit\n"
|
|
|
|
content += "@ setup the environment\n"
|
|
|
|
content += ":set_env\n"
|
|
|
|
content += "call %VSPATH%vsvars32.bat\n\n"
|
|
|
|
content += ":compile\n"
|
|
|
|
content += 'cd %s\n"%s\\%s%sbam" config\n"%s\\%s%sbam" %s' % (src_dir_teeworlds, work_dir, src_dir_bam, bam_execution_path, work_dir, src_dir_bam, bam_execution_path, options.release_type)
|
2011-04-02 02:49:14 +00:00
|
|
|
file.write(content.encode())
|
2010-12-16 02:14:31 +00:00
|
|
|
file.close()
|
|
|
|
command = os.system("build.bat")
|
2010-12-05 22:01:05 +00:00
|
|
|
else:
|
|
|
|
os.chdir(src_dir_teeworlds)
|
|
|
|
command = os.system("%s/%s%sbam %s" % (work_dir, src_dir_bam, bam_execution_path, options.release_type))
|
|
|
|
if command != 0:
|
2008-03-22 18:40:27 +00:00
|
|
|
bail("failed to build %s" % name)
|
2010-12-05 22:01:05 +00:00
|
|
|
os.chdir(work_dir)
|
2007-12-12 21:53:06 +00:00
|
|
|
|
|
|
|
# make release
|
2011-04-02 02:58:45 +00:00
|
|
|
if flag_make_release:
|
2010-12-05 22:01:05 +00:00
|
|
|
print("*** making release ***")
|
2011-04-02 02:58:45 +00:00
|
|
|
if hasattr(locals(), 'src_dir_teeworlds') == False:
|
|
|
|
src_dir_teeworlds = search_object(work_dir, r"teeworlds[^\.]*$")
|
|
|
|
if not src_dir_teeworlds:
|
|
|
|
bail("couldn't find %s source" % name)
|
2010-12-05 22:01:05 +00:00
|
|
|
os.chdir(src_dir_teeworlds)
|
2010-12-22 11:34:48 +00:00
|
|
|
command = '"%s/%s/scripts/make_release.py" %s %s' % (work_dir, src_dir_teeworlds, version_teeworlds, platform)
|
2010-12-05 22:01:05 +00:00
|
|
|
if os.name != "nt":
|
|
|
|
command = "python %s" % command
|
|
|
|
if os.system(command) != 0:
|
|
|
|
bail("failed to make a relase of %s" % name)
|
2007-12-12 21:53:06 +00:00
|
|
|
final_output = "FAIL"
|
|
|
|
for f in os.listdir("."):
|
2010-12-05 22:01:05 +00:00
|
|
|
if version_teeworlds in f and platform in f and name in f and (".zip" in f or ".tar.gz" in f):
|
2007-12-12 21:53:06 +00:00
|
|
|
final_output = f
|
2010-12-05 22:01:05 +00:00
|
|
|
os.chdir(work_dir)
|
|
|
|
shutil.copy("%s/%s" % (src_dir_teeworlds, final_output), "../"+final_output)
|
2007-12-12 21:53:06 +00:00
|
|
|
os.chdir(root_dir)
|
2010-12-05 22:01:05 +00:00
|
|
|
clean()
|
2007-12-12 21:53:06 +00:00
|
|
|
|
2010-12-05 22:01:05 +00:00
|
|
|
print("*** all done ***")
|