Introduced patching of runtime/commands.py to allow for usage of the src/common folder.

This commit is contained in:
LexManos 2012-08-02 00:51:51 -07:00
parent 582a785fb8
commit 1e47f3e468
7 changed files with 162 additions and 7 deletions

1
fml/.gitignore vendored
View File

@ -9,3 +9,4 @@
/target
fmlbranding.properties
/fernflower.zip
/commands.py.bck

View File

@ -307,7 +307,7 @@
<exec executable="${python.exe}" dir="${basedir}">
<arg value="${basedir}/update_patches.py" />
<arg value="${mcp.home}"/>
<arg value="${patch.src.dir}"/>
<arg value="${basedir}"/>
</exec>
</target>

93
fml/commands.patch Normal file
View File

@ -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])

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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()