Overhaul build-everything with goal of supporting Windows

This commit is contained in:
2024-11-07 19:33:22 -05:00
parent 7239d3d7f9
commit 3561b9c4c7
2 changed files with 90 additions and 75 deletions

View File

@@ -37,32 +37,79 @@ def writefile(fn, str):
with open(fn, "w") as f:
f.write(str)
def shell(cmd):
def shell(dir, cmd):
print("Running:", cmd)
subprocess.run(cmd, shell=True, check=True)
subprocess.run(cmd, shell=True, check=True, cwd=dir)
#
# These are some directory paths that we will need.
# These things are operating system specific.
#
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)
if sys.platform == "windows":
OS = "Windows"
DLL = "dll"
BAT = "bat"
DOT_EXE = ".exe"
USER = "Unknown"
REPOSITORY_PATH = [ "d:", "e:", "f:" ]
BUILD_BAT = "Build.bat"
UNWRITABLE_DIR = "c:/Windows"
else:
OS = "Linux"
DLL = "so"
BAT = "sh"
DOT_EXE = ""
USER = os.environ["USER"]
REPOSITORY_PATH = [ os.environ["HOME"] ]
BUILD_BAT = "Linux/Build.sh"
UNWRITABLE_DIR = "/"
#
# Find the two repositories.
#
def find_repository(name, path):
result = None
for place in path:
d = place + "/" + name
if os.path.isdir(d):
print("Found repository:",d)
if result is not None:
sys.exit("Found two repositories. Please remove duplicate.")
result = d
if result is None:
sys.exit(f"Could not find repository: {name}")
return result
UNREALENGINE=find_repository("UnrealEngine", REPOSITORY_PATH)
INTEGRATION=find_repository("integration", REPOSITORY_PATH)
#
# Make sure this script is running out of the expected repository.
#
if os.path.abspath(os.path.dirname(sys.argv[0])) != INTEGRATION:
print(sys.argv[0])
sys.exit(f"You must run this script out of {INTEGRATION}")
#
# Change directory to an unwritable unrelated directory.
# This will force us to use explicit paths everywhere.
#
os.chdir(UNWRITABLE_DIR)
#
# 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"{INTEGRATION}/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
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)
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
@@ -70,16 +117,16 @@ Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml").unli
# Write BuildConfiguration.xml
#
BUILDCONFIG=readfile("EnginePatches/BuildConfigurationLinux.xml")
writefile("Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
BUILDCONFIG=readfile(f"{INTEGRATION}/EnginePatches/BuildConfiguration{OS}.xml")
writefile(f"{INTEGRATION}/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"
writefile(f"{INTEGRATION}/Source/Integration/lpx-paths.hpp", f"""
#define LUPREX_DLL_PATH "{INTEGRATION}/luprex/build/{OS}/luprexlib.{DLL}"
#define LUPREX_ROOT_PATH "{INTEGRATION}/luprex"
""")
@@ -88,59 +135,55 @@ writefile("Source/Integration/lpx-paths.hpp", f"""
# Restore any affected sourcefiles before applying patch.
#
os.chdir(UNREALENGINE)
print("Applying patch to Unreal Engine...")
for line in readfile(f"{INTEGRATION}/EnginePatches/EnginePatch").splitlines():
if line.startswith("--- a/"):
shell(f"git checkout HEAD {line[6:]}")
shell(f"git apply {INTEGRATION}/EnginePatches/EnginePatch")
os.chdir(INTEGRATION)
shell(UNREALENGINE, f"git checkout HEAD {line[6:]}")
shell(UNREALENGINE, f"git apply {INTEGRATION}/EnginePatches/EnginePatch")
#
# Write Integration.uproject.
#
UPROJECTTEMPLATE=readfile("EnginePatches/uproject")
UPROJECTTEMPLATE=readfile(f"{INTEGRATION}/EnginePatches/uproject")
UPROJECT=json.loads(UPROJECTTEMPLATE)
with open("Integration.uproject", "w") as rewritten:
with open(f"{INTEGRATION}/Integration.uproject", "w") as rewritten:
json.dump(UPROJECT, rewritten, indent=4)
#
# Run Setup.sh in UNREALENGINE
#
os.chdir(UNREALENGINE)
shell("./Setup.sh")
os.chdir(INTEGRATION)
shell(UNREALENGINE, f"{UNREALENGINE}/Setup.{BAT}")
#
# Use UnrealBuildTool to generate a rough draft of Integration.code-workspace.
#
shell(f'{UNREALENGINE}/GenerateProjectFiles.sh -projectfiles -project="{INTEGRATION}/Integration.uproject" -game')
shell(INTEGRATION, f'{UNREALENGINE}/GenerateProjectFiles.{BAT} -projectfiles -project="{INTEGRATION}/Integration.uproject" -game')
#
# Load the rough Integration.code-workspace into RAM, then delete the rough draft.
#
with open("Integration.code-workspace") as original:
with open(f"{INTEGRATION}/Integration.code-workspace") as original:
WORKSPACE=json.load(original)
Path("Integration.code-workspace").unlink()
Path(f"{INTEGRATION}/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" }
if task["label"] == f"IntegrationEditor {OS} 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")
return task["label"].startswith(f"IntegrationEditor {OS} DebugGame")
WORKSPACE["tasks"]["tasks"] = [x for x in WORKSPACE["tasks"]["tasks"] if goodtask(x)]
@@ -208,33 +251,29 @@ WORKSPACE["settings"]["files.watcherExclude"] = {
# Write Integration.code-workspace.
#
with open("Integration.code-workspace", "w") as rewritten:
with open(f"{INTEGRATION}/Integration.code-workspace", "w") as rewritten:
json.dump(WORKSPACE, rewritten, indent=4)
#
# Do an initial build of Luprex
#
os.chdir(f"{INTEGRATION}/luprex")
print("Building luprex...")
shell("make")
os.chdir(INTEGRATION)
shell(f"{INTEGRATION}/luprex", "make")
#
# Build ShaderCompileWorker
#
os.chdir(UNREALENGINE)
print("Building ShaderCompileWorker...")
shell("Engine/Build/BatchFiles/Linux/Build.sh ShaderCompileWorker Linux Shipping -waitmutex")
Path("Engine/Binaries/Linux/ShaderCompileWorker").unlink(missing_ok=True)
shutil.copyfile("Engine/Binaries/Linux/ShaderCompileWorker-Linux-Shipping", "Engine/Binaries/Linux/ShaderCompileWorker")
os.chdir(INTEGRATION)
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...")
os.system(f'dotnet {UNREALENGINE}/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll IntegrationEditor Linux DebugGame -project="{INTEGRATION}/Integration.uproject" -waitmutex')
shell(INTEGRATION, f'{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} IntegrationEditor {OS} DebugGame -project="{INTEGRATION}/Integration.uproject" -waitmutex')