More work on dos line endings, FFS

This commit is contained in:
2025-06-23 16:08:24 -04:00
parent 83accd91df
commit e9fbd8fc46
2 changed files with 12 additions and 19 deletions

View File

@@ -96,26 +96,19 @@ def expand_json_file(sourcefile, outputfile, config):
# patch, and then convert the appropriate files back.
#
def patched_files(patchfn):
patch_lines = Path(patchfn).read_text().splitlines()
file_names = [line[4:].split()[0] for line in patch_lines if line.startswith('--- ')]
return [ '/'.join(file.split('/')[1:]) for file in file_names ]
def dos2unix(fn):
before = Path(fn).read_text()
after = before.replace("\r\n", "\n")
before = Path(fn).read_bytes()
after = before.replace(b"\r\n", b"\n")
if before != after:
Path(fn).write_text(after)
return True
return False
print("dos2unix ", fn)
Path(fn).write_bytes(after)
def unix2dos(fn):
before = Path(fn).read_text()
after = before.replace("\n", "\r\n")
before = Path(fn).read_bytes()
after = before.replace(b"\n", b"\r\n")
if before != after:
Path(fn).write_text(after)
return True
return False
print("unix2dos ", fn)
Path(fn).write_bytes(after)
#
# Given a patch file, generate a list of the files being modified.
@@ -203,12 +196,11 @@ def unzip_unreal_engine_and_apply_patch():
shutil.rmtree(unrealversion, ignore_errors=True)
shell(INTEGRATION, "unzip UnrealEngine.zip")
patchfile = f"{INTEGRATION}/EnginePatches/EnginePatch"
dosfiles = Path(f"{INTEGRATION}/EnginePatches/PatchedDosFiles").read_text().splitlines()
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)]
for file in dosfiles: dos2unix(f"{unrealversion}/{file}")
shell(unrealversion, f"patch -p1 < {patchfile}")
for file in dos_files: unix2dos(file)
for file in dosfiles: unix2dos(f"{unrealversion}/{file}")
Path(unrealversion).rename(UNREALENGINE)
def generate_buildconfiguration_xml():