2012-04-06 13:10:11 +00:00
|
|
|
import os, os.path, sys
|
|
|
|
import urllib, zipfile
|
|
|
|
import shutil, glob, fnmatch
|
|
|
|
import subprocess, logging, re
|
2012-08-05 02:29:54 +00:00
|
|
|
import csv, shutil
|
2012-08-04 09:33:46 +00:00
|
|
|
import pprint
|
2012-04-06 13:10:11 +00:00
|
|
|
|
|
|
|
forge_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
def reset_logger():
|
|
|
|
log = logging.getLogger()
|
|
|
|
while len(log.handlers) > 0:
|
|
|
|
log.removeHandler(log.handlers[0])
|
|
|
|
|
|
|
|
version_reg = re.compile(r'(([a-z]+)Version[\s]+=[\s]+)(\d+);')
|
|
|
|
def load_version(build=0):
|
|
|
|
info = {'major' : -1,
|
|
|
|
'minor' : -1,
|
|
|
|
'revision' : -1,
|
|
|
|
'build' : -1
|
|
|
|
}
|
2012-08-05 05:42:17 +00:00
|
|
|
hook_file = os.path.join(forge_dir, 'common/net/minecraftforge/common/ForgeVersion.java'.replace('/', os.sep))
|
2012-04-06 13:10:11 +00:00
|
|
|
with open(hook_file, 'r') as fh:
|
|
|
|
buf = fh.read()
|
|
|
|
|
|
|
|
def proc(match):
|
|
|
|
try:
|
|
|
|
info[match.group(2)] = int(match.group(3))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return match.group(0)
|
|
|
|
|
|
|
|
buf = version_reg.sub(proc, buf)
|
|
|
|
info['build'] = build
|
|
|
|
return info
|
|
|
|
|
|
|
|
def inject_version(src_file, build=0):
|
|
|
|
version = load_version(build)
|
|
|
|
|
|
|
|
tmp_file = src_file + '.tmp'
|
|
|
|
with open(src_file, 'r') as fh:
|
|
|
|
buf = fh.read()
|
|
|
|
|
|
|
|
def mapname(match):
|
|
|
|
try:
|
|
|
|
return '%s%s;' % (match.group(1), version[match.group(2)])
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
return match.group(0)
|
|
|
|
|
2012-04-06 14:16:14 +00:00
|
|
|
buf = version_reg.sub(mapname, buf).replace('\r\n', '\n')
|
2012-04-06 13:10:11 +00:00
|
|
|
|
2012-04-06 14:16:14 +00:00
|
|
|
with open(tmp_file, 'wb') as fh:
|
2012-04-06 13:10:11 +00:00
|
|
|
fh.write(buf)
|
|
|
|
shutil.move(tmp_file, src_file)
|
|
|
|
|
|
|
|
def zip_folder(path, key, zip):
|
2012-12-18 07:53:33 +00:00
|
|
|
import pprint
|
2012-04-06 13:10:11 +00:00
|
|
|
files = os.listdir(path)
|
|
|
|
for file in files:
|
|
|
|
file_path = os.path.join(path, file)
|
|
|
|
file_key = os.path.join(key, file)
|
|
|
|
if os.path.isdir(file_path):
|
|
|
|
zip_folder(file_path, file_key, zip)
|
|
|
|
else:
|
2012-12-18 07:53:33 +00:00
|
|
|
if not file_key.replace(os.sep, '/') in zip.NameToInfo:
|
|
|
|
print file_key
|
|
|
|
zip.write(file_path, file_key)
|
2012-04-06 13:10:11 +00:00
|
|
|
|
|
|
|
def zip_create(path, key, zip_name):
|
|
|
|
zip = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
zip_folder(path, key, zip)
|
|
|
|
else:
|
|
|
|
zip.write(path, key)
|
2012-05-27 08:52:02 +00:00
|
|
|
zip.close()
|
2012-08-04 07:55:17 +00:00
|
|
|
|
|
|
|
def apply_forge_patches(fml_dir, mcp_dir, forge_dir, src_dir, copy_files=True):
|
|
|
|
sys.path.append(fml_dir)
|
|
|
|
from fml import copytree, apply_patches
|
2012-05-27 08:52:02 +00:00
|
|
|
|
2012-08-04 07:55:17 +00:00
|
|
|
#patch files
|
|
|
|
print 'Applying Minecraft Forge patches'
|
|
|
|
sys.stdout.flush()
|
2012-08-15 06:57:16 +00:00
|
|
|
|
|
|
|
if os.path.isdir(os.path.join(forge_dir, 'patches', 'minecraft')):
|
|
|
|
apply_patches(mcp_dir, os.path.join(forge_dir, 'patches', 'minecraft'), src_dir)
|
2012-12-13 07:38:51 +00:00
|
|
|
|
2012-08-15 06:57:16 +00:00
|
|
|
if copy_files and os.path.isdir(os.path.join(forge_dir, 'client')):
|
|
|
|
copytree(os.path.join(forge_dir, 'client'), os.path.join(src_dir, 'minecraft'))
|
2012-08-04 07:55:17 +00:00
|
|
|
if copy_files and os.path.isdir(os.path.join(forge_dir, 'common')):
|
2012-12-13 07:38:51 +00:00
|
|
|
copytree(os.path.join(forge_dir, 'common'), os.path.join(src_dir, 'minecraft'))
|
2012-08-04 09:33:46 +00:00
|
|
|
|
2012-08-05 05:42:17 +00:00
|
|
|
def build_forge_dev(mcp_dir, forge_dir, fml_dir, build_num=0):
|
|
|
|
version = load_version(build_num)
|
|
|
|
print '=================================== Build %d.%d.%d.%d Start =================================' % (version['major'], version['minor'], version['revision'], version['build'])
|
|
|
|
|
|
|
|
src_dir = os.path.join(mcp_dir, 'src')
|
|
|
|
if os.path.isdir(src_dir):
|
|
|
|
shutil.rmtree(src_dir)
|
|
|
|
|
|
|
|
sys.path.append(fml_dir)
|
|
|
|
from fml import copytree
|
|
|
|
|
|
|
|
print 'src_work -> src'
|
|
|
|
copytree(os.path.join(mcp_dir, 'src_work'), src_dir)
|
|
|
|
print '\nCopying Client Code'
|
|
|
|
copytree(os.path.join(forge_dir, 'client'), os.path.join(src_dir, 'minecraft'), -1)
|
|
|
|
print '\nCopying Common Code'
|
2012-12-13 07:38:51 +00:00
|
|
|
copytree(os.path.join(forge_dir, 'common'), os.path.join(src_dir, 'minecraft'), -1)
|
2012-08-05 05:42:17 +00:00
|
|
|
print
|
2012-12-13 07:38:51 +00:00
|
|
|
inject_version(os.path.join(src_dir, 'minecraft/net/minecraftforge/common/ForgeVersion.java'.replace('/', os.sep)), build_num)
|
2012-08-05 05:42:17 +00:00
|
|
|
|
|
|
|
error_level = 0
|
|
|
|
try:
|
|
|
|
sys.path.append(mcp_dir)
|
|
|
|
from runtime.recompile import recompile
|
|
|
|
|
|
|
|
os.chdir(mcp_dir)
|
|
|
|
reset_logger()
|
2012-10-21 12:46:10 +00:00
|
|
|
recompile(None, True, False)
|
2012-08-05 05:42:17 +00:00
|
|
|
reset_logger()
|
|
|
|
os.chdir(forge_dir)
|
|
|
|
except SystemExit, e:
|
2012-12-04 02:15:38 +00:00
|
|
|
if not e.code == 0:
|
|
|
|
print 'Recompile Exception: %d ' % e.code
|
|
|
|
error_level = e.code
|
2012-08-05 05:42:17 +00:00
|
|
|
|
|
|
|
print '=================================== Build Finished %d =================================' % error_level
|
|
|
|
return error_level
|