From 87acec03f4eb3cf330ab31364f4e6acb9bd6341e Mon Sep 17 00:00:00 2001 From: ViperMaul Date: Mon, 13 Apr 2015 09:45:44 -0700 Subject: [PATCH] Protect against CfgConvert errors from crashing make.py and properly restore config.cpp - fixes #557 --- tools/make.py | 28 +++++++++++++++++----------- tools/make64.py | 28 +++++++++++++++++----------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/tools/make.py b/tools/make.py index 65f447bff9..6222932727 100644 --- a/tools/make.py +++ b/tools/make.py @@ -606,14 +606,17 @@ See the make.cfg file for additional build options. cmd = [os.path.join(arma3tools_path, "CfgConvert", "CfgConvert.exe"), "-bin", "-dst", os.path.join(work_drive, prefix, module, "config.bin"), os.path.join(work_drive, prefix, module, "config.cpp")] ret = subprocess.call(cmd) if ret != 0: - print_error("CfgConvert -bin return code == " + str(ret)) - input("Press Enter to continue...") + print_error("CfgConvert -bin return code == " + str(ret) + ". Usually means there is a syntax error within the config.cpp file.") + os.remove(os.path.join(work_drive, prefix, module, "config.cpp")) + shutil.copyfile(os.path.join(work_drive, prefix, module, "config.backup"), os.path.join(work_drive, prefix, module, "config.cpp")) cmd = [os.path.join(arma3tools_path, "CfgConvert", "CfgConvert.exe"), "-txt", "-dst", os.path.join(work_drive, prefix, module, "config.cpp"), os.path.join(work_drive, prefix, module, "config.bin")] ret = subprocess.call(cmd) if ret != 0: - print_error("CfgConvert -txt) return code == " + str(ret)) - input("Press Enter to continue...") + print_error("CfgConvert -txt return code == " + str(ret) + ". Usually means there is a syntax error within the config.cpp file.") + os.remove(os.path.join(work_drive, prefix, module, "config.cpp")) + shutil.copyfile(os.path.join(work_drive, prefix, module, "config.backup"), os.path.join(work_drive, prefix, module, "config.cpp")) + # Include build number try: @@ -622,13 +625,16 @@ See the make.cfg file for additional build options. configtext = f.read() f.close() - patchestext = re.search(r"class CfgPatches\n\{(.*?)\n\}", configtext, re.DOTALL).group(1) - patchestext = re.sub(r'version(.*?)="(.*?)"', r'version\1="\2-{}"'.format(commit_id), patchestext) - configtext = re.sub(r"class CfgPatches\n\{(.*?)\n\}", "class CfgPatches\n{"+patchestext+"\n}", configtext, flags=re.DOTALL) - - f = open(configpath, "w") - f.write(configtext) - f.close() + if configtext: + patchestext = re.search(r"class CfgPatches\n\{(.*?)\n\}", configtext, re.DOTALL).group(1) + patchestext = re.sub(r'version(.*?)="(.*?)"', r'version\1="\2-{}"'.format(commit_id), patchestext) + configtext = re.sub(r"class CfgPatches\n\{(.*?)\n\}", "class CfgPatches\n{"+patchestext+"\n}", configtext, flags=re.DOTALL) + f = open(configpath, "w") + f.write(configtext) + f.close() + else: + os.remove(os.path.join(work_drive, prefix, module, "config.cpp")) + os.rename(os.path.join(work_drive, prefix, module, "config.backup"), os.path.join(work_drive, prefix, module, "config.cpp")) except: raise print_error("Failed to include build number") diff --git a/tools/make64.py b/tools/make64.py index 0382bb9179..24f8ea2b0b 100644 --- a/tools/make64.py +++ b/tools/make64.py @@ -606,14 +606,17 @@ See the make.cfg file for additional build options. cmd = [os.path.join(arma3tools_path, "CfgConvert", "CfgConvert.exe"), "-bin", "-dst", os.path.join(work_drive, prefix, module, "config.bin"), os.path.join(work_drive, prefix, module, "config.cpp")] ret = subprocess.call(cmd) if ret != 0: - print_error("CfgConvert -bin return code == " + str(ret)) - input("Press Enter to continue...") + print_error("CfgConvert -bin return code == " + str(ret) + ". Usually means there is a syntax error within the config.cpp file.") + os.remove(os.path.join(work_drive, prefix, module, "config.cpp")) + shutil.copyfile(os.path.join(work_drive, prefix, module, "config.backup"), os.path.join(work_drive, prefix, module, "config.cpp")) cmd = [os.path.join(arma3tools_path, "CfgConvert", "CfgConvert.exe"), "-txt", "-dst", os.path.join(work_drive, prefix, module, "config.cpp"), os.path.join(work_drive, prefix, module, "config.bin")] ret = subprocess.call(cmd) if ret != 0: - print_error("CfgConvert -txt) return code == " + str(ret)) - input("Press Enter to continue...") + print_error("CfgConvert -txt return code == " + str(ret) + ". Usually means there is a syntax error within the config.cpp file.") + os.remove(os.path.join(work_drive, prefix, module, "config.cpp")) + shutil.copyfile(os.path.join(work_drive, prefix, module, "config.backup"), os.path.join(work_drive, prefix, module, "config.cpp")) + # Include build number try: @@ -622,13 +625,16 @@ See the make.cfg file for additional build options. configtext = f.read() f.close() - patchestext = re.search(r"class CfgPatches\n\{(.*?)\n\}", configtext, re.DOTALL).group(1) - patchestext = re.sub(r'version(.*?)="(.*?)"', r'version\1="\2-{}"'.format(commit_id), patchestext) - configtext = re.sub(r"class CfgPatches\n\{(.*?)\n\}", "class CfgPatches\n{"+patchestext+"\n}", configtext, flags=re.DOTALL) - - f = open(configpath, "w") - f.write(configtext) - f.close() + if configtext: + patchestext = re.search(r"class CfgPatches\n\{(.*?)\n\}", configtext, re.DOTALL).group(1) + patchestext = re.sub(r'version(.*?)="(.*?)"', r'version\1="\2-{}"'.format(commit_id), patchestext) + configtext = re.sub(r"class CfgPatches\n\{(.*?)\n\}", "class CfgPatches\n{"+patchestext+"\n}", configtext, flags=re.DOTALL) + f = open(configpath, "w") + f.write(configtext) + f.close() + else: + os.remove(os.path.join(work_drive, prefix, module, "config.cpp")) + os.rename(os.path.join(work_drive, prefix, module, "config.backup"), os.path.join(work_drive, prefix, module, "config.cpp")) except: raise print_error("Failed to include build number")