Files
integration/build-everything.py

269 lines
8.0 KiB
Python
Raw Normal View History

2024-11-04 15:46:54 -05:00
#!/usr/bin/python3
#
# This python script builds integration from scratch. That includes:
#
# - Generating BuildConfiguration.xml in integration repository
# - Generating BuildConfiguration.xml in UnrealEngine repository
# - Hardwiring paths into Source/Integration/lpx-paths.hpp
# - Generating Integration.uproject
# - Generating Integration.code-workspace
# - Applies patch to Unreal Engine source.
# - Running Setup.sh in the UnrealEngine repository
# - Building luprex
# - Building ShaderCompileWorker
# - Building integration
#
# Once this is all done, everything is ready to go. It is now possible to
# start up the IDE and run luprex in the debugger.
#
# This script is mainly intended for the *initial* build.
# If you want to edit the code and recompile, it is okay to use
# this script a second time, but it's unnecessarily slow.
# It's much faster to edit and recompile using the IDE.
2024-11-04 15:46:54 -05:00
#
import sys, os, json, shutil, subprocess
2024-11-04 15:46:54 -05:00
from pathlib import Path
#
# These things are operating system specific.
2024-11-04 15:46:54 -05:00
#
if sys.platform == "windows":
OS = "Windows"
DLL = "dll"
BAT = "bat"
DOT_EXE = ".exe"
USER = "Unknown"
BUILD_BAT = "Build.bat"
else:
OS = "Linux"
DLL = "so"
BAT = "sh"
DOT_EXE = ""
USER = os.environ["USER"]
BUILD_BAT = "Linux/Build.sh"
#
2024-11-11 14:14:52 -05:00
# Some handy utility functions
#
2024-11-11 14:14:52 -05:00
def readfile(fn):
with open(fn) as f:
return f.read()
2024-11-11 14:14:52 -05:00
def writefile(fn, str):
with open(fn, "w") as f:
f.write(str)
2024-11-11 14:14:52 -05:00
def shell(dir, cmd):
print("Running:", cmd)
subprocess.run(cmd, shell=True, check=True, cwd=dir)
#
2024-11-11 14:14:52 -05:00
# Find the two repositories and verify them.
#
2024-11-11 14:14:52 -05:00
INTEGRATION=os.path.dirname(os.path.abspath(sys.argv[0]))
UNREALENGINE=os.path.join(os.path.dirname(INTEGRATION), "UnrealEngine")
2024-11-11 14:14:52 -05:00
if not os.path.isdir(f"{INTEGRATION}/Source/Integration"):
sys.exit(f"Integration repository is not valid: {INTEGRATION}")
if not os.path.isdir(f"{UNREALENGINE}/Engine/Source/Editor"):
sys.exit(f"Integration repository is not valid: {UNREALENGINE}")
#
# Create the Saved/UnrealBuildTool directories. These will hold
# the file BuildConfiguration.xml
#
2024-11-11 14:14:52 -05:00
# Change directory to one of these in order to force ourselves
# to specify all paths explicitly.
#
2024-11-11 14:14:52 -05:00
Path(f"{INTEGRATION}/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
os.chdir(f"{INTEGRATION}/Saved/UnrealBuildTool")
2024-11-04 15:46:54 -05:00
#
# Remove previously-generated files.
#
Path(f"{INTEGRATION}/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
Path(f"{INTEGRATION}/Integration.uproject").unlink(missing_ok=True)
Path(f"{INTEGRATION}/Integration.code-workspace").unlink(missing_ok=True)
Path(f"{INTEGRATION}/Makefile").unlink(missing_ok=True)
Path(f"{INTEGRATION}/Source/Integration/lpx-paths.hpp").unlink(missing_ok=True)
2024-11-04 15:46:54 -05:00
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
#
# Write BuildConfiguration.xml
#
BUILDCONFIG=readfile(f"{INTEGRATION}/EnginePatches/BuildConfiguration{OS}.xml")
writefile(f"{INTEGRATION}/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
2024-11-04 15:46:54 -05:00
writefile(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
#
# Write lpx-paths.hpp.
#
writefile(f"{INTEGRATION}/Source/Integration/lpx-paths.hpp", f"""
#define LUPREX_DLL_PATH "{INTEGRATION}/luprex/build/{OS}/luprexlib.{DLL}"
2024-11-04 15:46:54 -05:00
#define LUPREX_ROOT_PATH "{INTEGRATION}/luprex"
""")
#
# Apply patch to the unreal engine source.
# Restore any affected sourcefiles before applying patch.
2024-11-04 15:46:54 -05:00
#
print("Applying patch to Unreal Engine...")
2024-11-07 17:53:05 -05:00
for line in readfile(f"{INTEGRATION}/EnginePatches/EnginePatch").splitlines():
if line.startswith("--- a/"):
shell(UNREALENGINE, f"git checkout HEAD {line[6:]}")
shell(UNREALENGINE, f"git apply {INTEGRATION}/EnginePatches/EnginePatch")
2024-11-04 15:46:54 -05:00
#
# Write Integration.uproject.
#
UPROJECTTEMPLATE=readfile(f"{INTEGRATION}/EnginePatches/uproject")
2024-11-04 15:46:54 -05:00
UPROJECT=json.loads(UPROJECTTEMPLATE)
with open(f"{INTEGRATION}/Integration.uproject", "w") as rewritten:
2024-11-04 15:46:54 -05:00
json.dump(UPROJECT, rewritten, indent=4)
#
# Run Setup.sh in UNREALENGINE
2024-11-04 15:46:54 -05:00
#
shell(UNREALENGINE, f"{UNREALENGINE}/Setup.{BAT}")
2024-11-04 15:46:54 -05:00
#
# Use UnrealBuildTool to generate a rough draft of Integration.code-workspace.
#
shell(INTEGRATION, f'{UNREALENGINE}/GenerateProjectFiles.{BAT} -projectfiles -project="{INTEGRATION}/Integration.uproject" -game')
2024-11-04 15:46:54 -05:00
#
# Load the rough Integration.code-workspace into RAM, then delete the rough draft.
#
with open(f"{INTEGRATION}/Integration.code-workspace") as original:
2024-11-04 15:46:54 -05:00
WORKSPACE=json.load(original)
Path(f"{INTEGRATION}/Integration.code-workspace").unlink()
2024-11-04 15:46:54 -05:00
#
# Configure the correct build task as the default task.
#
for task in WORKSPACE["tasks"]["tasks"]:
if task["label"] == f"IntegrationEditor {OS} DebugGame Build":
task["group"] = { "kind": "build", "isDefault": True }
2024-11-04 15:46:54 -05:00
#
# Delete all build tasks that aren't relevant.
#
def goodtask(task):
return task["label"].startswith(f"IntegrationEditor {OS} DebugGame")
2024-11-04 15:46:54 -05:00
WORKSPACE["tasks"]["tasks"] = [x for x in WORKSPACE["tasks"]["tasks"] if goodtask(x)]
#
# Add a build task for Luprex
#
LUPREXBUILDTASK={}
WORKSPACE["tasks"]["tasks"].append(LUPREXBUILDTASK)
LUPREXBUILDTASK["label"] = "Build Luprex"
LUPREXBUILDTASK["group"] = "build"
LUPREXBUILDTASK["command"] = "make"
LUPREXBUILDTASK["problemMatcher"] = "$msCompile"
LUPREXBUILDTASK["type"] = "shell"
LUPREXBUILDTASK["options"] = {}
LUPREXBUILDTASK["options"]["cwd"] = f"{INTEGRATION}/luprex"
#
# Convert all launch configurations to lldb.
#
LLDBINIT=[
f'command script import {UNREALENGINE}/Engine/Extras/LLDBDataFormatters/UEDataFormatters_2ByteChars.py',
f'settings set target.inline-breakpoint-strategy always',
f'target stop-hook add --one-liner "p ::UngrabAllInputImpl()"',
2024-11-04 15:46:54 -05:00
]
for config in WORKSPACE["launch"]["configurations"]:
config["type"] = "lldb"
config["initCommands"] = LLDBINIT
config["args"] = [ f"{INTEGRATION}/Integration.uproject", f"-userdir=User/{USER}" ]
config.pop("visualizerFile", None)
config.pop("showDisplayString", None)
#
# Delete all but the relevant launch configuration.
#
def goodconf(config):
return config["name"] == "Launch IntegrationEditor (DebugGame)"
WORKSPACE["launch"]["configurations"] = [x for x in WORKSPACE["launch"]["configurations"] if goodconf(x)]
2024-11-07 17:53:05 -05:00
#
# Add some recommended extensions.
#
EXTENSIONS=set(WORKSPACE["extensions"]["recommendations"])
EXTENSIONS.add("ms-python.python")
EXTENSIONS.add("vadimcn.vscode-lldb")
WORKSPACE["extensions"]["recommendations"] = list(EXTENSIONS)
#
# Tell vscode not to try watching all the UnrealEngine source code for modifications.
# Attempting this overruns a Linux hardwired limit on file watches.
#
WORKSPACE["settings"]["files.watcherExclude"] = {
f'{UNREALENGINE}/Engine/**' : True,
f'{UNREALENGINE}/Samples/**' : True,
f'{UNREALENGINE}/Templates/**' : True
}
#
# Tell the LLDB plugin not to dereference pointers. This is dumb behavior,
# it dereferences "char *" and shows only the first character. Not dereferencing
# the pointer shows the whole string.
#
2024-11-25 15:22:04 -05:00
WORKSPACE["settings"]["lldb.dereferencePointers"] = False
2024-11-04 15:46:54 -05:00
#
# Write Integration.code-workspace.
#
with open(f"{INTEGRATION}/Integration.code-workspace", "w") as rewritten:
2024-11-04 15:46:54 -05:00
json.dump(WORKSPACE, rewritten, indent=4)
#
# Do an initial build of Luprex
#
print("Building luprex...")
shell(f"{INTEGRATION}/luprex", "make")
#
# Build ShaderCompileWorker
#
print("Building ShaderCompileWorker...")
shell(UNREALENGINE, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} ShaderCompileWorker {OS} Shipping -waitmutex")
Path(f"Engine/Binaries/{OS}/ShaderCompileWorker{DOT_EXE}").unlink(missing_ok=True)
shutil.copyfile(f"{UNREALENGINE}/Engine/Binaries/{OS}/ShaderCompileWorker-{OS}-Shipping{DOT_EXE}", f"{UNREALENGINE}/Engine/Binaries/{OS}/ShaderCompileWorker{DOT_EXE}")
#
# Build Integration
#
print("Building integration...")
shell(INTEGRATION, f'{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} IntegrationEditor {OS} DebugGame -project="{INTEGRATION}/Integration.uproject" -waitmutex')