Modify build.py to make the patch-application process resistant to CRLF nonsense
This commit is contained in:
46
build.py
46
build.py
@@ -7,8 +7,6 @@
|
||||
# script are in README.md
|
||||
#
|
||||
|
||||
#
|
||||
|
||||
|
||||
import sys, os, json, shutil, subprocess, re, time, tarfile
|
||||
import itertools, hashlib, zipfile, fnmatch
|
||||
@@ -88,6 +86,40 @@ def expand_json_file(sourcefile, outputfile, config):
|
||||
expanded = expand_json(data, vars(config))
|
||||
Path(outputfile).write_text(json.dumps(expanded, indent=4))
|
||||
|
||||
#
|
||||
# Applying patches to files with DOS line endings.
|
||||
#
|
||||
# We want to apply a patch to the UnrealEngine source, and some but not all
|
||||
# of the files we want to patch have DOS line endings. Unfortunately, the
|
||||
# unix patch utility can't handle a codebase with mixed line endings.
|
||||
# To make it work, we convert all files to UNIX line endings, apply the
|
||||
# patch, and then convert the appropriate files back.
|
||||
#
|
||||
|
||||
def patched_files(patchfn):
|
||||
patch_lines = Path(patchfn).read_text().splitlines()
|
||||
return [line[6:].strip() for line in patch_lines if line.startswith('--- a/')]
|
||||
|
||||
def dos2unix(fn):
|
||||
before = Path(fn).read_text()
|
||||
after = before.replace("\r\n", "\n")
|
||||
if before != after:
|
||||
Path(fn).write_text(after)
|
||||
return True
|
||||
return False
|
||||
|
||||
def unix2dos(fn):
|
||||
before = Path(fn).read_text()
|
||||
after = before.replace("\n", "\r\n")
|
||||
if before != after:
|
||||
Path(fn).write_text(after)
|
||||
return True
|
||||
return False
|
||||
|
||||
#
|
||||
# Given a patch file, generate a list of the files being modified.
|
||||
#
|
||||
|
||||
#
|
||||
# Determining the build configuration.
|
||||
#
|
||||
@@ -159,7 +191,6 @@ def unzip_unreal_engine_and_apply_patch():
|
||||
"""
|
||||
Unzip the unreal engine source, then apply a patch.
|
||||
"""
|
||||
# Find out the unreal version that we're using
|
||||
if not Path(UNREALENGINE).is_dir():
|
||||
zipfn = f"{INTEGRATION}/UnrealEngine.zip";
|
||||
with zipfile.ZipFile(zipfn, 'r') as z:
|
||||
@@ -170,9 +201,14 @@ def unzip_unreal_engine_and_apply_patch():
|
||||
shutil.rmtree(UNREALENGINE, ignore_errors=True)
|
||||
shutil.rmtree(unrealversion, ignore_errors=True)
|
||||
shell(INTEGRATION, "unzip UnrealEngine.zip")
|
||||
patchfile = f"{INTEGRATION}/EnginePatches/EnginePatch"
|
||||
dos2unix(patchfile)
|
||||
rel_files = patched_files(patchfile)
|
||||
abs_files = [ os.path.join(unrealversion, file) for file in rel_files ]
|
||||
dos_files = [ file for file in abs_files if dos2unix(file)]
|
||||
shell(unrealversion, f"patch -p1 < {patchfile}")
|
||||
for file in dos_files: unix2dos(file)
|
||||
Path(unrealversion).rename(UNREALENGINE)
|
||||
shell(UNREALENGINE, f"patch -p1 < {INTEGRATION}/EnginePatches/EnginePatch")
|
||||
|
||||
|
||||
def generate_buildconfiguration_xml():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user