Files
integration/patch-integration.py

140 lines
4.6 KiB
Python
Raw Normal View History

#!/usr/bin/python3
#
# This script applies patches to the integration repository.
#
# There are certain files that can't be easily checked into git
# because the contents of these files must contain hardwired
# paths, or hardwired machine-specific settings. These include:
#
# integration/Saved/UnrealBuildTool/BuildConfiguration.xml
# integration/Integration.uproject
# integration/Integration.code-workspace
# integration/Makefile
# integration/Source/Integration/lpx-paths.hpp
#
# This python program will generate these files as necessary.
#
# It is safe to run this patch program a second time to repair
# any of these files, if necessary. Doing so will not corrupt
# anything.
#
#-------------------------------------------------------------
#
# Details you may need to know someday:
2024-10-03 15:31:51 -04:00
#
# The BuildConfiguration.xml file specifies that this project will
# use visual studio code (on linux) or visual studio (on windows).
# It can't be checked into git because it differs by platform.
#
# Unreal needs "Integration.uproject". This config file tells
# UnrealBuildTool what version of the unreal engine to link this game
# with. It also specifies a couple of other game-specific configuration
# settings. It can't easily be checked into git because it contains
2024-10-03 15:31:51 -04:00
# a GUID which is specific to your local machine. We generate
# Integration.uproject from scratch. Later, the unreal
# editor will inject the engine GUID into the file.
#
# VSCode needs "Integration.code-workspace," it tells vscode how to
# compile this game and how to run it under the debugger. It can't
# be checked into git because it contains many hardwired
# paths.
#
2024-10-03 15:31:51 -04:00
# We don't really need a Makefile, since Unreal games are build using
# UnrealBuildTool, not make. But, having a one-liner makefile can at
# least make it obvious what command you're supposed to type to build
# things. UnrealBuildTool creates a Makefile, but we delete that, and
# replace it with a simple one-liner.
#
2024-10-03 15:31:51 -04:00
# The file lpx-paths.hpp contains hardwired absolute paths of the
# Luprex DLL and Luprex root path. Eventually, we're going to write
# C++ code to calculate these dynamically, so that they don't need to
# be hardwired in. But this will do for now.
#
#-------------------------------------------------------------
2024-10-14 14:28:42 -04:00
import sys, os, json, glob
2024-10-03 15:31:51 -04:00
from pathlib import Path
#
# Some handy utility functions
#
2024-10-28 17:51:42 -04:00
def readfile(fn):
with open(fn) as f:
return f.read()
2024-10-03 15:31:51 -04:00
def writefile(fn, str):
with open(fn, "w") as f:
f.write(str)
#
# These are some directory paths that we will need.
#
INTEGRATION = os.path.dirname(os.path.abspath(sys.argv[0]))
UNREALENGINE = os.environ["HOME"] + "/UnrealEngine"
2024-10-14 14:28:42 -04:00
if not os.path.isdir(UNREALENGINE): error("No unreal installed in $HOME/UnrealEngine")
2024-10-03 15:31:51 -04:00
UNREALBUILDTOOL = f"{UNREALENGINE}/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll"
2024-10-09 18:10:08 -04:00
USER = os.environ["USER"]
2024-10-03 15:31:51 -04:00
#
# Change to the target directory.
# Remove any existing project files.
#
os.chdir(INTEGRATION)
Path("Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path("Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
Path("Integration.uproject").unlink(missing_ok=True)
Path("Integration.code-workspace").unlink(missing_ok=True)
Path("Makefile").unlink(missing_ok=True)
Path("Source/Integration/lpx-paths.hpp").unlink(missing_ok=True)
#
# Write BuildConfiguration.xml
#
2024-10-28 17:51:42 -04:00
BUILDCONFIG=readfile("EnginePatches/BuildConfigurationLinux.xml")
writefile("Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
#
2024-10-03 15:31:51 -04:00
# Write lpx-paths.hpp.
#
2024-10-03 15:31:51 -04:00
writefile("Source/Integration/lpx-paths.hpp", f"""
#define LUPREX_DLL_PATH "{INTEGRATION}/luprex/build/linux/luprexlib.so"
#define LUPREX_ROOT_PATH "{INTEGRATION}/luprex"
""")
#
# Write Integration.uproject.
#
2024-10-28 19:03:54 -04:00
UPROJECTTEMPLATE=readfile("EnginePatches/uproject")
UPROJECT=json.loads(UPROJECTTEMPLATE)
with open("Integration.uproject", "w") as rewritten:
json.dump(UPROJECT, rewritten, indent=4)
#
2024-10-28 19:03:54 -04:00
# Using the template in EnginePatches/code-workspace, generate a
# updated version of Integration.code-workspace
#
2024-10-28 19:03:54 -04:00
WORKSPACETEMPLATE=readfile("EnginePatches/code-workspace")
WORKSPACETEMPLATE=WORKSPACETEMPLATE.replace("ENGINEPATH", UNREALENGINE)
WORKSPACETEMPLATE=WORKSPACETEMPLATE.replace("INTEGRATIONPATH", INTEGRATION)
WORKSPACETEMPLATE=WORKSPACETEMPLATE.replace("USERNAME", USER)
WORKSPACE=json.loads(WORKSPACETEMPLATE)
with open("Integration.code-workspace", "w") as rewritten:
json.dump(WORKSPACE, rewritten, indent=4)
2024-10-03 15:31:51 -04:00
#
# Write the Makefile
#
writefile("Makefile", f"""
2024-10-09 17:16:09 -04:00
all:
2024-10-03 15:31:51 -04:00
(cd luprex ; make)
2024-10-14 14:28:42 -04:00
dotnet {UNREALBUILDTOOL} IntegrationEditor Linux DebugGame -project="{INTEGRATION}/Integration.uproject" -waitmutex
2024-10-03 15:31:51 -04:00
""")