2012-12-07 19:25:19 +00:00
|
|
|
import os, os.path, sys, glob
|
2012-08-01 23:35:35 +00:00
|
|
|
import shutil, fnmatch
|
|
|
|
import logging, zipfile, re
|
2012-12-04 02:15:38 +00:00
|
|
|
from optparse import OptionParser
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
forge_dir = os.path.dirname(os.path.abspath(__file__))
|
2012-08-10 01:37:52 +00:00
|
|
|
from forge import reset_logger, load_version, zip_folder, zip_create, inject_version, build_forge_dev
|
2012-10-29 05:04:47 +00:00
|
|
|
from changelog import make_changelog
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
zip = None
|
|
|
|
zip_name = None
|
|
|
|
zip_base = None
|
|
|
|
version_str = None
|
2012-11-18 06:58:34 +00:00
|
|
|
version_mc = None
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
global version_str
|
2012-11-18 06:58:34 +00:00
|
|
|
global version_mc
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-m', '--mcp-dir', action='store', dest='mcp_dir', help='MCP Path', default=None)
|
|
|
|
parser.add_option('-b', '--build', action='store', dest='build', help='Build number', default=None)
|
2012-12-10 23:43:19 +00:00
|
|
|
parser.add_option('-s', '--skipchangelog', action='store_true', dest='skip_changelog', help='Skip Changelog', default=False)
|
2012-12-04 02:15:38 +00:00
|
|
|
options, _ = parser.parse_args()
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
build_num = 0
|
2012-12-04 02:15:38 +00:00
|
|
|
if not options.build is None:
|
2012-08-01 23:35:35 +00:00
|
|
|
try:
|
2012-12-04 02:15:38 +00:00
|
|
|
build_num = int(options.build)
|
2012-08-01 23:35:35 +00:00
|
|
|
except:
|
|
|
|
pass
|
2012-12-04 02:15:38 +00:00
|
|
|
|
|
|
|
mcp_dir = os.path.join(forge_dir, 'mcp')
|
|
|
|
if not options.mcp_dir is None:
|
|
|
|
mcp_dir = os.path.abspath(options.mcp_dir)
|
|
|
|
elif os.path.isfile(os.path.join('..', 'runtime', 'commands.py')):
|
|
|
|
mcp_dir = os.path.abspath('..')
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
ret = 0
|
2012-08-10 01:37:52 +00:00
|
|
|
fml_dir = os.path.join(forge_dir, 'fml')
|
|
|
|
build_forge_dev(mcp_dir, forge_dir, fml_dir, build_num)
|
2012-08-01 23:35:35 +00:00
|
|
|
if ret != 0:
|
|
|
|
sys.exit(ret)
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
print '=================================== Release Start ================================='
|
|
|
|
error_level = 0
|
|
|
|
try:
|
2012-12-04 02:15:38 +00:00
|
|
|
sys.path.append(mcp_dir)
|
|
|
|
from runtime.reobfuscate import reobfuscate
|
2012-08-01 23:35:35 +00:00
|
|
|
os.chdir(mcp_dir)
|
|
|
|
reset_logger()
|
2012-10-21 17:39:05 +00:00
|
|
|
reobfuscate(None, False, True, True, True, False)
|
2012-08-01 23:35:35 +00:00
|
|
|
reset_logger()
|
|
|
|
os.chdir(forge_dir)
|
|
|
|
except SystemExit, e:
|
|
|
|
print 'Reobfusicate Exception: %d ' % e.code
|
|
|
|
error_level = e.code
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
src_dir = os.path.join(mcp_dir, 'src')
|
|
|
|
reobf_dir = os.path.join(mcp_dir, 'reobf')
|
|
|
|
client_dir = os.path.join(reobf_dir, 'minecraft')
|
|
|
|
|
|
|
|
extract_fml_obfed(mcp_dir, reobf_dir, client_dir)
|
|
|
|
extract_paulscode(mcp_dir, client_dir)
|
2012-08-01 23:35:35 +00:00
|
|
|
version = load_version(build_num)
|
2012-11-18 06:58:34 +00:00
|
|
|
version_forge = '%d.%d.%d.%d' % (version['major'], version['minor'], version['revision'], version['build'])
|
|
|
|
version_mc = load_mc_version(forge_dir)
|
2012-12-04 02:15:38 +00:00
|
|
|
branch = get_branch_name()
|
2012-11-18 06:58:34 +00:00
|
|
|
|
|
|
|
version_str = '%s-%s' % (version_mc, version_forge)
|
2012-12-04 02:15:38 +00:00
|
|
|
if not branch == "":
|
|
|
|
version_str = '%s-%s' % (version_str, branch)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
out_folder = os.path.join(forge_dir, 'forge-%s' % version_str)
|
|
|
|
if os.path.isdir(out_folder):
|
|
|
|
shutil.rmtree(out_folder)
|
|
|
|
|
|
|
|
os.makedirs(out_folder)
|
2012-11-18 06:58:34 +00:00
|
|
|
|
2012-12-13 07:38:51 +00:00
|
|
|
options.skip_changelog = True #Disable till jenkins fixes its shit
|
2012-12-07 21:42:32 +00:00
|
|
|
if not options.skip_changelog:
|
|
|
|
changelog_file = 'forge-%s/minecraftforge-changelog-%s.txt' % (version_str, version_str)
|
|
|
|
make_changelog("http://jenkins.minecraftforge.net/job/minecraftforge/", build_num, changelog_file, version_str)
|
2012-11-18 06:58:34 +00:00
|
|
|
|
2012-10-15 22:32:12 +00:00
|
|
|
version_file = 'forgeversion.properties'
|
|
|
|
if os.path.exists(version_file):
|
|
|
|
os.remove(version_file)
|
|
|
|
|
|
|
|
with open(version_file, 'wb') as fh:
|
|
|
|
fh.write('forge.major.number=%d\n' % version['major'])
|
|
|
|
fh.write('forge.minor.number=%d\n' % version['minor'])
|
|
|
|
fh.write('forge.revision.number=%d\n' % version['revision'])
|
|
|
|
fh.write('forge.build.number=%d\n' % version['build'])
|
|
|
|
|
2012-08-14 05:28:23 +00:00
|
|
|
zip_start('minecraftforge-universal-%s.zip' % version_str)
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_folder(client_dir, '', zip)
|
2012-08-14 05:28:23 +00:00
|
|
|
zip_add('client/forge_logo.png')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_add('install/MinecraftForge-Credits.txt')
|
|
|
|
zip_add('install/MinecraftForge-License.txt')
|
|
|
|
zip_add('fml/CREDITS-fml.txt')
|
|
|
|
zip_add('fml/LICENSE-fml.txt')
|
|
|
|
zip_add('fml/README-fml.txt')
|
2012-08-10 01:37:52 +00:00
|
|
|
zip_add('fml/common/fml_at.cfg')
|
|
|
|
zip_add('fml/common/fml_marker.cfg')
|
|
|
|
zip_add('fml/common/fmlversion.properties')
|
2012-10-25 14:27:58 +00:00
|
|
|
zip_add('fml/common/mcpmod.info')
|
|
|
|
zip_add('fml/client/mcp.png')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_add('install/Paulscode IBXM Library License.txt')
|
|
|
|
zip_add('install/Paulscode SoundSystem CodecIBXM License.txt')
|
2012-08-10 09:25:48 +00:00
|
|
|
zip_add('common/forge_at.cfg')
|
2012-10-15 22:32:12 +00:00
|
|
|
zip_add(version_file)
|
2012-12-10 23:43:19 +00:00
|
|
|
if not options.skip_changelog:
|
|
|
|
zip_add(changelog_file, 'MinecraftForge-Changelog.txt')
|
2012-10-19 01:31:39 +00:00
|
|
|
zip_add('MANIFEST.MF','META-INF/MANIFEST.MF')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_end()
|
|
|
|
|
2012-12-07 19:25:19 +00:00
|
|
|
zips = glob.glob('fml/mcp*.zip')
|
|
|
|
for i in zips:
|
|
|
|
print 'Removing MCP Zip: %s' % os.path.basename(i)
|
|
|
|
os.remove(i)
|
|
|
|
|
2012-08-10 01:37:52 +00:00
|
|
|
inject_version(os.path.join(forge_dir, 'common/net/minecraftforge/common/ForgeVersion.java'.replace('/', os.sep)), build_num)
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_start('minecraftforge-src-%s.zip' % version_str, 'forge')
|
2012-08-10 01:37:52 +00:00
|
|
|
zip_add('client', 'client')
|
|
|
|
zip_add('common', 'common')
|
|
|
|
zip_add('patches', 'patches')
|
|
|
|
zip_add('fml', 'fml')
|
2012-12-04 02:15:38 +00:00
|
|
|
zip_add('install', '')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_add('forge.py')
|
2012-10-15 22:32:12 +00:00
|
|
|
zip_add(version_file)
|
2012-12-10 23:43:19 +00:00
|
|
|
if not options.skip_changelog:
|
|
|
|
zip_add(changelog_file, 'MinecraftForge-Changelog.txt')
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_end()
|
2012-08-10 01:37:52 +00:00
|
|
|
inject_version(os.path.join(forge_dir, 'common/net/minecraftforge/common/ForgeVersion.java'.replace('/', os.sep)), 0)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2012-10-15 22:32:12 +00:00
|
|
|
if os.path.exists(version_file):
|
|
|
|
os.remove(version_file)
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
print '=================================== Release Finished %d =================================' % error_level
|
|
|
|
sys.exit(error_level)
|
|
|
|
|
|
|
|
def zip_add(file, key=None):
|
|
|
|
if key == None:
|
|
|
|
key = os.path.basename(file)
|
|
|
|
else:
|
|
|
|
key = key.replace('/', os.sep)
|
|
|
|
if not zip_base is None:
|
|
|
|
key = os.path.join(zip_base, key)
|
|
|
|
file = os.path.join(forge_dir, file.replace('/', os.sep))
|
|
|
|
if os.path.isdir(file):
|
|
|
|
zip_folder(file, key, zip)
|
|
|
|
else:
|
|
|
|
if os.path.isfile(file):
|
|
|
|
print key
|
|
|
|
zip.write(file, key)
|
|
|
|
|
|
|
|
def zip_start(name, base=None):
|
|
|
|
global zip, zip_name, zip_base
|
|
|
|
zip_name = name
|
|
|
|
|
2012-11-18 06:58:34 +00:00
|
|
|
print '================== %s Start ==================' % zip_name
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_file = os.path.join(forge_dir, 'forge-%s' % version_str, name)
|
|
|
|
zip = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
zip_base = base
|
|
|
|
|
|
|
|
def zip_end():
|
|
|
|
global zip, zip_name, zip_base
|
|
|
|
zip.close()
|
2012-11-18 06:58:34 +00:00
|
|
|
print '================== %s Finished ==================' % zip_name
|
2012-08-01 23:35:35 +00:00
|
|
|
zip_name = None
|
|
|
|
zip_base = None
|
|
|
|
|
2012-11-18 06:58:34 +00:00
|
|
|
def load_mc_version(forge_dir):
|
|
|
|
props = os.path.join(forge_dir, 'fml', 'common', 'fmlversion.properties')
|
|
|
|
|
|
|
|
if not os.path.isfile(props):
|
|
|
|
print 'Could not load fmlversion.properties, build failed'
|
|
|
|
sys.exit(1)
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2012-11-18 06:58:34 +00:00
|
|
|
with open(props, 'r') as fh:
|
|
|
|
for line in fh:
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith('fmlbuild.mcversion'):
|
|
|
|
return line.split('=')[1].strip()
|
|
|
|
|
|
|
|
print 'Could not load fmlversion.properties, build failed'
|
|
|
|
sys.exit(1)
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
def extract_fml_obfed(mcp_dir, reobf_dir, client_dir):
|
2012-08-01 23:35:35 +00:00
|
|
|
fml_file = os.path.join(forge_dir, 'fml', 'difflist.txt')
|
|
|
|
if not os.path.isfile(fml_file):
|
|
|
|
print 'Could not find Forge ModLoader\'s DiffList, looking for it at: %s' % fml_file
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
with open(fml_file, 'r') as fh:
|
|
|
|
lines = fh.readlines()
|
|
|
|
|
|
|
|
client = zipfile.ZipFile(os.path.join(mcp_dir, 'temp', 'client_reobf.jar'))
|
|
|
|
|
|
|
|
print 'Extracting Reobfed Forge ModLoader classes'
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
line = line.replace('\n', '').replace('\r', '').replace('/', os.sep)
|
|
|
|
if not os.path.isfile(os.path.join(reobf_dir, line)):
|
2012-09-12 21:58:46 +00:00
|
|
|
print ' %s' % line
|
2012-08-01 23:35:35 +00:00
|
|
|
side = line.split(os.sep)[0]
|
|
|
|
if side == 'minecraft':
|
|
|
|
client.extract(line[10:].replace(os.sep, '/'), client_dir)
|
|
|
|
|
|
|
|
client.close()
|
|
|
|
|
2012-12-04 02:15:38 +00:00
|
|
|
def extract_paulscode(mcp_dir, client_dir):
|
2012-09-12 21:58:46 +00:00
|
|
|
client = zipfile.ZipFile(os.path.join(mcp_dir, 'temp', 'client_reobf.jar'))
|
|
|
|
|
|
|
|
print 'Extracting Reobfed Paulscode for mac users -.-'
|
|
|
|
|
|
|
|
for i in client.filelist:
|
|
|
|
if i.filename.startswith('paulscode'):
|
|
|
|
if not os.path.isfile(os.path.join(client_dir, i.filename)):
|
|
|
|
print ' %s' % i.filename
|
|
|
|
client.extract(i.filename, client_dir)
|
|
|
|
|
|
|
|
client.close()
|
2012-12-04 02:15:38 +00:00
|
|
|
|
|
|
|
def get_branch_name():
|
|
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
branch = ''
|
|
|
|
if os.getenv("GIT_BRANCH") is None:
|
|
|
|
try:
|
|
|
|
process = Popen(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=PIPE, stderr=STDOUT, bufsize=-1)
|
|
|
|
branch, _ = process.communicate()
|
|
|
|
branch = branch.rstrip('\r\n')
|
|
|
|
except OSError:
|
|
|
|
print "Git not found"
|
|
|
|
else:
|
|
|
|
branch = os.getenv("GIT_BRANCH").rpartition('/')[2]
|
|
|
|
branch = branch.replace('master', '')
|
2012-12-06 03:09:01 +00:00
|
|
|
branch = branch.replace('HEAD', '')
|
2012-12-04 02:15:38 +00:00
|
|
|
print 'Detected Branch as \'%s\'' % branch
|
|
|
|
return branch
|
2012-09-12 21:58:46 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|