Cleaned up update_patches to fix a few bugs. Updated applypatches to normalize the patch file's line endings to make them work cross platform. Added download_firnflower and setup script. As well as added the GnuWin32's diff binary, so windows can create patches as well. http://gnuwin32.sourceforge.net/
This commit is contained in:
parent
9220174dbc
commit
3a5c176af4
|
@ -3,3 +3,4 @@
|
||||||
/mods
|
/mods
|
||||||
/fmlbuild.properties
|
/fmlbuild.properties
|
||||||
/difflist.txt
|
/difflist.txt
|
||||||
|
/.metadata/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os, os.path, shutil
|
||||||
import commands
|
import commands
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import re
|
import re
|
||||||
|
@ -14,14 +14,52 @@ def main():
|
||||||
print("Applying patches")
|
print("Applying patches")
|
||||||
patches = os.path.abspath(sys.argv[1])
|
patches = os.path.abspath(sys.argv[1])
|
||||||
work = os.path.normpath(sys.argv[2])
|
work = os.path.normpath(sys.argv[2])
|
||||||
|
mcp = os.path.normpath(sys.argv[3])
|
||||||
|
temp = os.path.abspath('temp.patch')
|
||||||
|
|
||||||
|
cmd = cmdsplit('patch -p2 -i "%s" ' % temp)
|
||||||
|
display = True
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
mcp = os.path.abspath(os.path.join(mcp, 'runtime', 'bin', 'applydiff.exe'))
|
||||||
|
cmd = cmdsplit('"%s" -uf -p2 -i "%s"' % (mcp, temp))
|
||||||
|
display = False
|
||||||
|
|
||||||
for path, _, filelist in os.walk(patches, followlinks=True):
|
for path, _, filelist in os.walk(patches, followlinks=True):
|
||||||
for cur_file in fnmatch.filter(filelist, '*.patch'):
|
for cur_file in fnmatch.filter(filelist, '*.patch'):
|
||||||
patch_file = os.path.normpath(os.path.join(patches, path[len(patches)+1:], cur_file))
|
patch_file = os.path.normpath(os.path.join(patches, path[len(patches)+1:], cur_file))
|
||||||
print(patch_file)
|
if display:
|
||||||
cmd = 'patch -p1 -i "%s" ' % (patch_file)
|
print 'patching file %s' % os.path.join(path[len(patches)+1:], cur_file)
|
||||||
process = subprocess.Popen(cmdsplit(cmd), cwd=work, bufsize=-1)
|
normaliselines(patch_file, temp)
|
||||||
|
process = subprocess.Popen(cmd, cwd=work, bufsize=-1)
|
||||||
process.communicate()
|
process.communicate()
|
||||||
|
|
||||||
|
if os.path.isfile(temp):
|
||||||
|
os.remove(temp)
|
||||||
|
|
||||||
|
#Taken from MCP
|
||||||
|
def normaliselines(in_filename, out_filename=None):
|
||||||
|
in_filename = os.path.normpath(in_filename)
|
||||||
|
if out_filename is None:
|
||||||
|
tmp_filename = in_filename + '.tmp'
|
||||||
|
else:
|
||||||
|
out_filename = os.path.normpath(out_filename)
|
||||||
|
tmp_filename = out_filename
|
||||||
|
dir_name = os.path.dirname(out_filename)
|
||||||
|
if dir_name:
|
||||||
|
if not os.path.exists(dir_name):
|
||||||
|
os.makedirs(dir_name)
|
||||||
|
regex_ending = re.compile(r'\r?\n')
|
||||||
|
with open(in_filename, 'rb') as in_file:
|
||||||
|
with open(tmp_filename, 'wb') as out_file:
|
||||||
|
buf = in_file.read()
|
||||||
|
if os.linesep == '\r\n':
|
||||||
|
buf = regex_ending.sub(r'\r\n', buf)
|
||||||
|
else:
|
||||||
|
buf = buf.replace('\r\n', '\n')
|
||||||
|
out_file.write(buf)
|
||||||
|
if out_filename is None:
|
||||||
|
shutil.move(tmp_filename, in_filename)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -188,6 +188,7 @@
|
||||||
<arg value="${basedir}/applypatches.py" />
|
<arg value="${basedir}/applypatches.py" />
|
||||||
<arg value="${patch.src.dir}" />
|
<arg value="${patch.src.dir}" />
|
||||||
<arg value="${mcp.srcdir}" />
|
<arg value="${mcp.srcdir}" />
|
||||||
|
<arg value="${mcp.home}" />
|
||||||
</exec>
|
</exec>
|
||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,10 @@
|
||||||
|
import urllib
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
urllib.urlretrieve("http://goo.gl/PnJHp", './fernflower.zip')
|
||||||
|
zf = zipfile.ZipFile('fernflower.zip')
|
||||||
|
zf.extract('fernflower.jar', '../runtime/bin')
|
||||||
|
except:
|
||||||
|
print "Downloading Fernflower failed download manually from http://goo.gl/PnJHp"
|
|
@ -0,0 +1,34 @@
|
||||||
|
@echo off
|
||||||
|
echo =================================== Setup Start =================================
|
||||||
|
pushd .. >nul
|
||||||
|
|
||||||
|
if "%1" NEQ "-skipdecompile" (
|
||||||
|
if not exist "runtime\bin\fernflower.jar" (
|
||||||
|
popd >nul
|
||||||
|
..\runtime\bin\python\python_mcp download_fernflower.py
|
||||||
|
pushd .. >nul
|
||||||
|
)
|
||||||
|
if not exist "runtime\bin\fernflower.jar" (
|
||||||
|
echo Failed to download fernflower, install it manually and re-run setup.
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
rmdir /S /Q src
|
||||||
|
echo | cmd /C decompile.bat -d -n -r
|
||||||
|
)
|
||||||
|
|
||||||
|
echo | cmd /C updatemd5.bat -f
|
||||||
|
|
||||||
|
rmdir /S /Q src-base
|
||||||
|
rmdir /S /Q src-work
|
||||||
|
mkdir src-base
|
||||||
|
mkdir src-work
|
||||||
|
|
||||||
|
xcopy /Y /E /Q src\* src-base
|
||||||
|
xcopy /Y /E /Q src\* src-work
|
||||||
|
popd >nul
|
||||||
|
..\runtime\bin\python\python_mcp applypatches.py patches ..\src-work ..
|
||||||
|
echo =================================== Setup Finished =================================
|
||||||
|
|
||||||
|
if NOT "%1"=="-skipdecompile" (
|
||||||
|
pause
|
||||||
|
)
|
|
@ -0,0 +1,2 @@
|
||||||
|
@echo off
|
||||||
|
..\runtime\bin\python\python_mcp update_patches.py .. patches
|
|
@ -27,20 +27,20 @@ def cleanDirs(path):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Creating patches")
|
print("Creating patches")
|
||||||
base = 'src-reference'
|
mcp = sys.argv[1]
|
||||||
work = 'src-work'
|
base = os.path.normpath(os.path.join(mcp, 'src-base'))
|
||||||
patched_dir=os.path.normpath(os.path.join(sys.argv[1],work))
|
work = os.path.normpath(os.path.join(mcp, 'src-work'))
|
||||||
timestamp = re.compile(r'[0-9-]* [0-9:\.]* [+-][0-9]*\r?\n')
|
timestamp = re.compile(r'[0-9-]* [0-9:\.]* [+-][0-9]*\r?\n')
|
||||||
|
|
||||||
for path, _, filelist in os.walk(patched_dir, followlinks=True):
|
for path, _, filelist in os.walk(work, followlinks=True):
|
||||||
for cur_file in fnmatch.filter(filelist, '*.java'):
|
for cur_file in fnmatch.filter(filelist, '*.java'):
|
||||||
file_base = os.path.normpath(os.path.join(base, path[len(patched_dir)+1:], cur_file))
|
file_base = os.path.normpath(os.path.join(base, path[len(work)+1:], cur_file)).replace(os.path.sep, '/')
|
||||||
file_work = os.path.normpath(os.path.join(work, path[len(patched_dir)+1:], cur_file))
|
file_work = os.path.normpath(os.path.join(work, path[len(work)+1:], cur_file)).replace(os.path.sep, '/')
|
||||||
patch = ''
|
patch = ''
|
||||||
cmd = 'diff -u %s %s -r --strip-trailing-cr --new-file' % (file_base, file_work)
|
cmd = 'diff -u %s %s -r --strip-trailing-cr --new-file' % (file_base, file_work)
|
||||||
process = subprocess.Popen(cmdsplit(cmd), cwd=os.path.normpath(sys.argv[1]), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
|
process = subprocess.Popen(cmdsplit(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
|
||||||
patch, _ = process.communicate()
|
patch, _ = process.communicate()
|
||||||
patch_dir = os.path.join(sys.argv[2],path[len(patched_dir)+1:])
|
patch_dir = os.path.join(sys.argv[2], path[len(work)+1:])
|
||||||
patch_file = os.path.join(patch_dir, cur_file + '.patch')
|
patch_file = os.path.join(patch_dir, cur_file + '.patch')
|
||||||
|
|
||||||
if len(patch) > 0:
|
if len(patch) > 0:
|
||||||
|
@ -50,7 +50,7 @@ def main():
|
||||||
|
|
||||||
if not os.path.exists(patch_dir):
|
if not os.path.exists(patch_dir):
|
||||||
os.makedirs(patch_dir)
|
os.makedirs(patch_dir)
|
||||||
with open(patch_file, 'w') as fh:
|
with open(patch_file, 'wb') as fh:
|
||||||
fh.write(patch)
|
fh.write(patch)
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(patch_file):
|
if os.path.isfile(patch_file):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
python update_patches.py patches .. patches
|
Loading…
Reference in New Issue