From d952a7be49a2c7db4f762270a599c776229b0461 Mon Sep 17 00:00:00 2001 From: LexManos Date: Sun, 27 May 2012 01:52:02 -0700 Subject: [PATCH] Added new source clean step to fix linux vs windows astyle issues. --- forge/forge.py | 33 ++++++++++++++++++++++++++++++++- forge/install/install.py | 4 +++- forge/setup.py | 4 +++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/forge/forge.py b/forge/forge.py index 719df8d95..111b44429 100644 --- a/forge/forge.py +++ b/forge/forge.py @@ -184,4 +184,35 @@ def zip_create(path, key, zip_name): zip_folder(path, key, zip) else: zip.write(path, key) - zip.close() \ No newline at end of file + zip.close() + +count = 0 +def cleanup_source(path): + path = os.path.normpath(path) + regex_cases_before = re.compile(r'((case|default).+\r?\n)\r?\n', re.MULTILINE) #Fixes newline after case before case body + regex_cases_after = re.compile(r'\r?\n(\r?\n[ \t]+(case|default))', re.MULTILINE) #Fixes newline after case body before new case + + def updatefile(src_file): + global count + tmp_file = src_file + '.tmp' + count = 0 + with open(src_file, 'r') as fh: + buf = fh.read() + + def fix_cases(match): + global count + count += 1 + return match.group(1) + + buf = regex_cases_before.sub(fix_cases, buf) + buf = regex_cases_after.sub(fix_cases, buf) + if count > 0: + with open(tmp_file, 'w') as fh: + fh.write(buf) + shutil.move(tmp_file, src_file) + + for path, _, filelist in os.walk(path, followlinks=True): + sub_dir = os.path.relpath(path, path) + for cur_file in fnmatch.filter(filelist, '*.java'): + src_file = os.path.normpath(os.path.join(path, cur_file)) + updatefile(src_file) diff --git a/forge/install/install.py b/forge/install/install.py index 2d6dff5dc..9ef800f77 100644 --- a/forge/install/install.py +++ b/forge/install/install.py @@ -14,7 +14,7 @@ from runtime.updatemd5 import updatemd5 from runtime.cleanup import cleanup from runtime.updatemcp import updatemcp -from forge import apply_patches, copytree, reset_logger, download_ff +from forge import apply_patches, copytree, reset_logger, download_ff, cleanup_source def main(): print '=================================== Minecraft Forge Setup Start =================================' @@ -50,6 +50,8 @@ def main(): print 'Something went wrong, src folder not found at: %s' % src_dir sys.exit(1) + cleanup_source(src_dir) + has_client = os.path.isdir(os.path.join(mcp_dir, 'src', 'minecraft')) has_server = os.path.isdir(os.path.join(mcp_dir, 'src', 'minecraft_server')) diff --git a/forge/setup.py b/forge/setup.py index ee4d702d2..a02305c0f 100644 --- a/forge/setup.py +++ b/forge/setup.py @@ -12,7 +12,7 @@ from runtime.decompile import decompile from runtime.updatenames import updatenames from runtime.updatemd5 import updatemd5 -from forge import apply_patches, copytree, reset_logger, download_ff +from forge import apply_patches, copytree, reset_logger, download_ff, cleanup_source def main(): @@ -38,6 +38,8 @@ def main(): if not os.path.isdir(src_dir): print 'Something went wrong, src folder not found at: %s' % src_dir sys.exit(1) + + cleanup_source(src_dir) setup_fml()