Added patch-both-repositories.py

This commit is contained in:
2024-11-04 15:46:54 -05:00
parent bfa07e71ab
commit c3a5cbe3c5
4 changed files with 184 additions and 327 deletions

View File

@@ -1,120 +0,0 @@
{
"folders": [
{
"name": "Integration",
"path": "."
},
{
"name": "UE5",
"path": "ENGINEPATH"
}
],
"settings": {
"typescript.tsc.autoDetect": "off",
"npm.autoDetect": "off"
},
"extensions": {
"recommendations": [
"ms-vscode.cpptools",
"ms-dotnettools.csharp",
"ms-python.python",
"vadimcn.vscode-lldb",
"ms-vscode.mono-debug",
"dfarley1.file-picker"
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "IntegrationEditor Linux DebugGame Build",
"group": {
"kind": "build",
"isDefault": true
},
"command": "Engine/Build/BatchFiles/Linux/Build.sh",
"args": [
"IntegrationEditor",
"Linux",
"DebugGame",
"INTEGRATIONPATH/Integration.uproject",
"-waitmutex"
],
"problemMatcher": "$msCompile",
"type": "shell",
"options": {
"cwd": "ENGINEPATH"
}
},
{
"label": "IntegrationEditor Linux DebugGame Rebuild",
"group": "build",
"command": "Engine/Build/BatchFiles/Linux/Build.sh",
"args": [
"IntegrationEditor",
"Linux",
"DebugGame",
"INTEGRATIONPATH/Integration.uproject",
"-waitmutex"
],
"problemMatcher": "$msCompile",
"dependsOn": [
"IntegrationEditor Linux DebugGame Clean"
],
"type": "shell",
"options": {
"cwd": "ENGINEPATH"
}
},
{
"label": "IntegrationEditor Linux DebugGame Clean",
"group": "build",
"command": "Engine/Build/BatchFiles/Linux/Build.sh",
"args": [
"IntegrationEditor",
"Linux",
"DebugGame",
"INTEGRATIONPATH/Integration.uproject",
"-waitmutex",
"-clean"
],
"problemMatcher": "$msCompile",
"type": "shell",
"options": {
"cwd": "ENGINEPATH"
}
},
{
"label": "Build Luprex",
"group": "build",
"command": "make",
"problemMatcher": "$msCompile",
"type": "shell",
"options": {
"cwd": "INTEGRATIONPATH/luprex"
}
}
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Launch IntegrationEditor (DebugGame)",
"request": "launch",
"program": "ENGINEPATH/Engine/Binaries/Linux/UnrealEditor-Linux-DebugGame",
"preLaunchTask": "IntegrationEditor Linux DebugGame Build",
"args": [
"INTEGRATIONPATH/Integration.uproject",
"-userdir=User/USERNAME"
],
"cwd": "ENGINEPATH",
"type": "lldb",
"initCommands": [
"command script import ENGINEPATH/Engine/Extras/LLDBDataFormatters/UEDataFormatters_2ByteChars.py",
"target stop-hook add --one-liner \"p ::UngrabAllInputImpl()\""
]
}
]
}
}

184
patch-both-repositories.py Executable file
View File

@@ -0,0 +1,184 @@
#!/usr/bin/python3
#
# This python script patches both the UnrealEngine and the
# integration repositories. It is necessary to do this before
# trying to build integration or UnrealEngine. If something
# generated by this script gets overwritten, it is perfectly safe
# to run this script again.
#
# Files generated:
#
# INTEGRATION/Saved/UnrealBuildTool/BuildConfiguration.xml
# INTEGRATION/Integration.uproject
# INTEGRATION/Integration.code-workspace
# INTEGRATION/Makefile
# INTEGRATION/Source/Integration/lpx-paths.hpp
#
# UNREALENGINE/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml
# UNREALENGINE/Engine/Source/Runtime/Core/Private/Logging/LogMacros.cpp
#
import sys, os, json
from pathlib import Path
#
# Some handy utility functions
#
def readfile(fn):
with open(fn) as f:
return f.read()
def writefile(fn, str):
with open(fn, "w") as f:
f.write(str)
#
# These are some directory paths that we will need.
#
USER = os.environ["USER"]
INTEGRATION = os.path.dirname(os.path.abspath(sys.argv[0]))
UNREALENGINE = os.environ["HOME"] + "/UnrealEngine"
if not os.path.isdir(f"{INTEGRATION}/Source/Integration"):
error("Could not figure out the correct path for the INTEGRATION repository.")
if not os.path.isdir(f"{UNREALENGINE}/Engine/Source"):
error("Could not figure out the correct path for the UNREALENGINE repository.")
os.chdir(INTEGRATION)
#
# Remove previously-generated files.
#
Path(f"Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path(f"Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
Path(f"Integration.uproject").unlink(missing_ok=True)
Path(f"Integration.code-workspace").unlink(missing_ok=True)
Path(f"Makefile").unlink(missing_ok=True)
Path(f"Source/Integration/lpx-paths.hpp").unlink(missing_ok=True)
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
Path(f"{UNREALENGINE}/Engine/Source/Runtime/Core/Private/Logging/LogMacros.cpp").unlink(missing_ok=True)
#
# Write BuildConfiguration.xml
#
BUILDCONFIG=readfile("EnginePatches/BuildConfigurationLinux.xml")
writefile("Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
writefile(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
#
# Write lpx-paths.hpp.
#
writefile("Source/Integration/lpx-paths.hpp", f"""
#define LUPREX_DLL_PATH "{INTEGRATION}/luprex/build/linux/luprexlib.so"
#define LUPREX_ROOT_PATH "{INTEGRATION}/luprex"
""")
#
# Write LogMacros.cpp
#
LOGMACROS=readfile("EnginePatches/LogMacros.cpp")
writefile(f"{UNREALENGINE}/Engine/Source/Runtime/Core/Private/Logging/LogMacros.cpp", LOGMACROS)
#
# Write Integration.uproject.
#
UPROJECTTEMPLATE=readfile("EnginePatches/uproject")
UPROJECT=json.loads(UPROJECTTEMPLATE)
with open("Integration.uproject", "w") as rewritten:
json.dump(UPROJECT, rewritten, indent=4)
#
# Write the Makefile
#
writefile("Makefile", f"""
all:
(cd luprex ; make)
dotnet {UNREALENGINE}/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll IntegrationEditor Linux DebugGame -project="{INTEGRATION}/Integration.uproject" -waitmutex
""")
#
# Use UnrealBuildTool to generate a rough draft of Integration.code-workspace.
#
BUILDPROJECTFILES = f'{UNREALENGINE}/GenerateProjectFiles.sh -projectfiles -project="{INTEGRATION}/Integration.uproject" -game'
print(BUILDPROJECTFILES)
os.system(BUILDPROJECTFILES)
#
# Load the rough Integration.code-workspace into RAM, then delete the rough draft.
#
with open("Integration.code-workspace") as original:
WORKSPACE=json.load(original)
Path("Integration.code-workspace").unlink()
#
# Configure the correct build task as the default task.
#
for task in WORKSPACE["tasks"]["tasks"]:
if task["label"] == "IntegrationEditor Linux DebugGame Build":
task["group"] = { "kind": "build", "isDefault": "true" }
#
# Delete all build tasks that aren't relevant.
#
def goodtask(task):
return task["label"].startswith("IntegrationEditor Linux DebugGame")
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",
'target stop-hook add --one-liner "p ::UngrabAllInputImpl()"',
"breakpoint set --name UBreakPoint::OnLogError"
]
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)]
#
# Write Integration.code-workspace.
#
with open("Integration.code-workspace", "w") as rewritten:
json.dump(WORKSPACE, rewritten, indent=4)

View File

@@ -1,139 +0,0 @@
#!/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:
#
# 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
# 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.
#
# 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.
#
# 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.
#
#-------------------------------------------------------------
import sys, os, json, glob
from pathlib import Path
#
# Some handy utility functions
#
def readfile(fn):
with open(fn) as f:
return f.read()
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"
if not os.path.isdir(UNREALENGINE): error("No unreal installed in $HOME/UnrealEngine")
UNREALBUILDTOOL = f"{UNREALENGINE}/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll"
USER = os.environ["USER"]
#
# 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
#
BUILDCONFIG=readfile("EnginePatches/BuildConfigurationLinux.xml")
writefile("Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
#
# Write lpx-paths.hpp.
#
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.
#
UPROJECTTEMPLATE=readfile("EnginePatches/uproject")
UPROJECT=json.loads(UPROJECTTEMPLATE)
with open("Integration.uproject", "w") as rewritten:
json.dump(UPROJECT, rewritten, indent=4)
#
# Using the template in EnginePatches/code-workspace, generate a
# updated version of Integration.code-workspace
#
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)
#
# Write the Makefile
#
writefile("Makefile", f"""
all:
(cd luprex ; make)
dotnet {UNREALBUILDTOOL} IntegrationEditor Linux DebugGame -project="{INTEGRATION}/Integration.uproject" -waitmutex
""")

View File

@@ -1,68 +0,0 @@
#!/usr/bin/python3
#
# This script applies patches to the UnrealEngine repository.
#
# We don't keep our own unreal engine repository because that
# would be overkill. Instead, you must check out the standard
# copy of Unreal engine, then we apply a few simple patches.
# The files patched are:
#
# UnrealEngine/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml
# UnrealEngine/Engine/Source/Runtime/Core/Private/Logging/LogMacros.cpp
#
# 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.
#
#--------------------------------------------------------------
import sys, os, json, glob
from pathlib import Path
#
# Some handy utility functions
#
def readfile(fn):
with open(fn) as f:
return f.read()
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"
if not os.path.isdir(UNREALENGINE): error("No unreal installed in $HOME/UnrealEngine")
#
# Change to the target directory.
# Remove any existing project files.
#
os.chdir(UNREALENGINE)
Path("Engine/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path("Engine/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
Path("Engine/Source/Runtime/Core/Private/Logging/LogMacros.cpp").unlink(missing_ok=True)
#
# Write BuildConfiguration.xml
#
BUILDCONFIG=readfile(f"{INTEGRATION}/EnginePatches/BuildConfigurationLinux.xml")
writefile("Engine/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
#
# Write LogMacros.cpp
#
LOGMACROS=readfile(f"{INTEGRATION}/EnginePatches/LogMacros.cpp")
writefile(f"{UNREALENGINE}/Engine/Source/Runtime/Core/Private/Logging/LogMacros.cpp", LOGMACROS)