diff --git a/fml/.gitignore b/fml/.gitignore index c5a46eb4c4..6c6c3b08e4 100644 --- a/fml/.gitignore +++ b/fml/.gitignore @@ -9,3 +9,4 @@ /target fmlbranding.properties /fernflower.zip +/commands.py.bck diff --git a/fml/build.xml b/fml/build.xml index e07b5c8afc..c6222bb000 100644 --- a/fml/build.xml +++ b/fml/build.xml @@ -307,7 +307,7 @@ - + diff --git a/fml/commands.patch b/fml/commands.patch new file mode 100644 index 0000000000..8197d8ac23 --- /dev/null +++ b/fml/commands.patch @@ -0,0 +1,93 @@ +--- commands.py ++++ commands.py +@@ -22,6 +22,7 @@ + import errno + import shlex + import platform ++import pprint + from hashlib import md5 # pylint: disable-msg=E0611 + from contextlib import closing + from textwrap import TextWrapper +@@ -502,6 +503,7 @@ + self.binclienttmp = os.path.normpath(config.get('OUTPUT', 'BinClientTemp')) + self.binservertmp = os.path.normpath(config.get('OUTPUT', 'BinServerTemp')) + self.srcclient = os.path.normpath(config.get('OUTPUT', 'SrcClient')) ++ self.srcshared = os.path.normpath(os.path.join(self.dirsrc, 'common')) + self.srcserver = os.path.normpath(config.get('OUTPUT', 'SrcServer')) + self.testclient = config.get('OUTPUT', 'TestClient') + self.testserver = config.get('OUTPUT', 'TestServer') +@@ -1039,6 +1041,7 @@ + all_files = True + append_pattern = False + pkglist = filterdirs(pathsrclk[side], '*.java', append_pattern=append_pattern, all_files=all_files) ++ pkglist = pkglist + filterdirs(self.srcshared, '*.java', append_pattern=True) #FML, Add Common folder + dirs = ' '.join(pkglist) + classpath = os.pathsep.join(cplk[side]) + forkcmd = self.cmdrecomp.format(classpath=classpath, sourcepath=pathsrclk[side], outpath=pathbinlk[side], +@@ -1238,6 +1241,11 @@ + + # HINT: We pathwalk the sources + for path, _, filelist in os.walk(pathsrclk[side], followlinks=True): ++ for cur_file in fnmatch.filter(filelist, '*.java'): ++ updatefile(os.path.normpath(os.path.join(path, cur_file))) ++ ++ # FML, copy of the above, for the common folder ++ for path, _, filelist in os.walk(self.srcshared, followlinks=True): + for cur_file in fnmatch.filter(filelist, '*.java'): + updatefile(os.path.normpath(os.path.join(path, cur_file))) + return True +@@ -1320,12 +1328,14 @@ + pathsrclk = {CLIENT: self.srcclient, SERVER: self.srcserver} + + strip_comments(pathsrclk[side]) ++ strip_comments(self.srcshared) + + def process_cleanup(self, side): + """Do lots of random cleanups including stripping comments, trailing whitespace and extra blank lines""" + pathsrclk = {CLIENT: self.srcclient, SERVER: self.srcserver} + + src_cleanup(pathsrclk[side], fix_imports=True, fix_unicode=True, fix_charval=True, fix_pi=True, fix_round=False) ++ src_cleanup(self.srcshared, fix_imports=True, fix_unicode=True, fix_charval=True, fix_pi=True, fix_round=False) + + def process_javadoc(self, side): + """Add CSV descriptions to methods and fields as javadoc""" +@@ -1334,6 +1344,21 @@ + if not self.has_doc_csv: + self.logger.warning('!! javadoc disabled due to no csvs !!') + return False ++ ++ #FML Recall this function on the common folder ++ #Potential bug: If this is called without a subsiquent rename call, will cause double comments ++ if pathsrclk[side] != self.srcshared: ++ if side == CLIENT: ++ tmp = self.srcclient ++ self.srcclient = self.srcshared ++ process_javadoc(self, side) ++ self.srcclient = tmp ++ else: ++ tmp = self.srcserver ++ self.srcserver = self.srcshared ++ process_javadoc(self, side) ++ self.srcserver = tmp ++ + + #HINT: We read the relevant CSVs + methodsreader = csv.DictReader(open(self.csvmethods, 'r')) +@@ -1420,6 +1445,7 @@ + + # HINT: We create the list of source directories based on the list of packages + pkglist = filterdirs(pathsrclk[side], '*.java', append_pattern=True) ++ pkglist = pkglist + filterdirs(self.srcshared, '*.java', append_pattern=True) #FML, Add Common folder + dirs = ' '.join(pkglist) + forkcmd = self.cmdastyle.format(classes=dirs, conffile=self.astyleconf) + self.runcmd(forkcmd) +@@ -1592,6 +1618,9 @@ + sys.exit(1) + + for entry in newfiles: ++ if 'commands.py' in entry[0]: #FML, Disable updating of Commands.py ++ print 'Update to runtime/commands.py found, but disbled due to using fml' ++ continue + if entry[3] == 'U': + self.logger.info('Retrieving file from server : %s', entry[0]) + cur_file = os.path.normpath(entry[0]) diff --git a/fml/decompile.py b/fml/decompile.py index 3a4ab6f64a..435718f4fd 100644 --- a/fml/decompile.py +++ b/fml/decompile.py @@ -13,6 +13,7 @@ if __name__ == '__main__': sys.path.append(os.path.join(fml_dir, 'install')) - from fml import setup_fml + from fml import setup_fml, setup_mcp + setup_mcp(fml_dir, mcp_dir) setup_fml(fml_dir, mcp_dir) diff --git a/fml/install/fml.py b/fml/install/fml.py index 877fea18c7..51a03c17f0 100644 --- a/fml/install/fml.py +++ b/fml/install/fml.py @@ -1,7 +1,7 @@ import os, os.path, sys import urllib, zipfile import shutil, glob, fnmatch -import subprocess, logging, re +import subprocess, logging, re, shlex from hashlib import md5 # pylint: disable-msg=E0611 #class flushout(object): @@ -157,7 +157,7 @@ def setup_fml(fml_dir, mcp_dir): #Compile AccessTransformer forkcmd = ('%s -Xlint:-options -deprecation -g -source 1.6 -target 1.6 -classpath "{classpath}" -sourcepath {sourcepath} -d {outpath} {target}' % self.cmdjavac).format( - classpath=os.path.join(mcp_dir, 'lib', '*'), sourcepath=os.path.join(fml_dir, 'common'), outpath=os.path.join(fml_dir, 'bin'), + classpath=os.pathsep.join(['.', os.path.join(mcp_dir, 'lib', '*')]), sourcepath=os.path.join(fml_dir, 'common'), outpath=os.path.join(fml_dir, 'bin'), target=os.path.join(fml_dir, 'transformers', 'cpw', 'mods', 'fml', 'common', 'asm', 'transformers', 'AccessTransformer.java')) print forkcmd self.runcmd(forkcmd) @@ -429,3 +429,42 @@ def merge_tree(root_src_dir, root_dst_dir): if os.path.exists(dst_file): os.remove(dst_file) shutil.copy(src_file, dst_dir) + +def setup_mcp(fml_dir, mcp_dir): + backup = os.path.join(fml_dir, 'commands.py.bck') + runtime = os.path.join(mcp_dir, 'runtime', 'commands.py') + patch = os.path.join(fml_dir, 'commands.patch') + + print 'Setting up MCP' + if os.path.isfile(backup): + print '> Restoring commands.py backup' + if os.path.exists(runtime): + os.remove(runtime) + shutil.copy(backup, runtime) + else: + print '> Backing up commands.py' + shutil.copy(runtime, backup) + + if not os.path.isfile(patch): + return + + temp = os.path.abspath('temp.patch') + cmd = 'patch -i "%s" ' % temp + + windows = os.name == 'nt' + if windows: + applydiff = os.path.abspath(os.path.join(mcp_dir, 'runtime', 'bin', 'applydiff.exe')) + cmd = '"%s" -uf -i "%s"' % (applydiff, temp) + + if os.sep == '\\': + cmd = cmd.replace('\\', '\\\\') + cmd = shlex.split(cmd) + + if windows: + print 'Patching file %s' % os.path.normpath(runtime) + fix_patch(patch, temp) + process = subprocess.Popen(cmd, cwd=os.path.join(mcp_dir, 'runtime'), bufsize=-1) + process.communicate() + + if os.path.isfile(temp): + os.remove(temp) \ No newline at end of file diff --git a/fml/install/install.py b/fml/install/install.py index 5170dbc059..6b4ca83bca 100644 --- a/fml/install/install.py +++ b/fml/install/install.py @@ -3,10 +3,11 @@ import os, os.path, sys fml_dir = os.path.dirname(os.path.abspath(__file__)) mcp_dir = os.path.abspath('..') -from fml import setup_fml, finish_setup_fml, apply_fml_patches +from fml import setup_fml, finish_setup_fml, apply_fml_patches, setup_mcp def main(): print '================ Forge ModLoader Setup Start ===================' + setup_mcp(fml_dir, mcp_dir) setup_fml(fml_dir, mcp_dir) apply_fml_patches(fml_dir, mcp_sir, os.path.join(mcp_dir, 'src')) finish_setup_fml(fml_dir, mcp_dir) diff --git a/fml/update_patches.py b/fml/update_patches.py index f012215f84..f1fe703de1 100644 --- a/fml/update_patches.py +++ b/fml/update_patches.py @@ -3,7 +3,7 @@ import os import commands import fnmatch import re -import subprocess, shlex +import subprocess, shlex, shutil import difflib, time @@ -30,7 +30,8 @@ def cleanDirs(path): def main(): print("Creating patches") mcp = os.path.normpath(sys.argv[1]) - patchd = os.path.normpath(sys.argv[2]) + fml_dir = os.path.normpath(sys.argv[2]) + patchd = os.path.normpath(os.path.join(fml_dir, 'patches')) base = os.path.normpath(os.path.join(mcp, 'src-base')) work = os.path.normpath(os.path.join(mcp, 'src-work')) @@ -62,5 +63,24 @@ def main(): cleanDirs(patchd) + backup = os.path.join(fml_dir, 'commands.py.bck') + runtime = os.path.join(mcp, 'runtime', 'commands.py') + patch_file = os.path.join(fml_dir, 'commands.patch') + + if not os.path.exists(backup): + shutil.copy(runtime, backup) + + patch = ''.join(difflib.unified_diff(open(backup, 'U').readlines(), open(runtime, 'U').readlines(), 'commands.py', 'commands.py', '', '', n=3)) + if len(patch) > 0: + print 'Creating commands.py patch' + patch = patch.replace('\r\n', '\n') + + with open(patch_file, 'wb') as fh: + fh.write(patch) + else: + if os.path.isfile(patch_file): + print("Deleting empty commands.py patch") + os.remove(patch_file) + if __name__ == '__main__': main()