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: with open(fn, "w") as f:
f.write(str) f.write(str)
def shell(cmd): def shell(dir, cmd):
print("Running:", 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.
# #
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"] USER = os.environ["USER"]
INTEGRATION = os.path.dirname(os.path.abspath(sys.argv[0])) REPOSITORY_PATH = [ os.environ["HOME"] ]
UNREALENGINE = os.environ["HOME"] + "/UnrealEngine" BUILD_BAT = "Linux/Build.sh"
if not os.path.isdir(f"{INTEGRATION}/Source/Integration"): UNWRITABLE_DIR = "/"
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.") # Find the two repositories.
os.chdir(INTEGRATION) #
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. # 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}/Saved/UnrealBuildTool").mkdir(parents=True, exist_ok=True)
Path(f"Integration.uproject").unlink(missing_ok=True) Path(f"{INTEGRATION}/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_ok=True)
Path(f"Integration.code-workspace").unlink(missing_ok=True) Path(f"{INTEGRATION}/Integration.uproject").unlink(missing_ok=True)
Path(f"Makefile").unlink(missing_ok=True) Path(f"{INTEGRATION}/Integration.code-workspace").unlink(missing_ok=True)
Path(f"Source/Integration/lpx-paths.hpp").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").mkdir(parents=True, exist_ok=True)
Path(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml").unlink(missing_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 # Write BuildConfiguration.xml
# #
BUILDCONFIG=readfile("EnginePatches/BuildConfigurationLinux.xml") BUILDCONFIG=readfile(f"{INTEGRATION}/EnginePatches/BuildConfiguration{OS}.xml")
writefile("Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG) writefile(f"{INTEGRATION}/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
writefile(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG) writefile(f"{UNREALENGINE}/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml", BUILDCONFIG)
# #
# Write lpx-paths.hpp. # Write lpx-paths.hpp.
# #
writefile("Source/Integration/lpx-paths.hpp", f""" writefile(f"{INTEGRATION}/Source/Integration/lpx-paths.hpp", f"""
#define LUPREX_DLL_PATH "{INTEGRATION}/luprex/build/linux/luprexlib.so" #define LUPREX_DLL_PATH "{INTEGRATION}/luprex/build/{OS}/luprexlib.{DLL}"
#define LUPREX_ROOT_PATH "{INTEGRATION}/luprex" #define LUPREX_ROOT_PATH "{INTEGRATION}/luprex"
""") """)
@@ -88,59 +135,55 @@ writefile("Source/Integration/lpx-paths.hpp", f"""
# Restore any affected sourcefiles before applying patch. # Restore any affected sourcefiles before applying patch.
# #
os.chdir(UNREALENGINE)
print("Applying patch to Unreal Engine...") print("Applying patch to Unreal Engine...")
for line in readfile(f"{INTEGRATION}/EnginePatches/EnginePatch").splitlines(): for line in readfile(f"{INTEGRATION}/EnginePatches/EnginePatch").splitlines():
if line.startswith("--- a/"): if line.startswith("--- a/"):
shell(f"git checkout HEAD {line[6:]}") shell(UNREALENGINE, f"git checkout HEAD {line[6:]}")
shell(f"git apply {INTEGRATION}/EnginePatches/EnginePatch") shell(UNREALENGINE, f"git apply {INTEGRATION}/EnginePatches/EnginePatch")
os.chdir(INTEGRATION)
# #
# Write Integration.uproject. # Write Integration.uproject.
# #
UPROJECTTEMPLATE=readfile("EnginePatches/uproject") UPROJECTTEMPLATE=readfile(f"{INTEGRATION}/EnginePatches/uproject")
UPROJECT=json.loads(UPROJECTTEMPLATE) 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) json.dump(UPROJECT, rewritten, indent=4)
# #
# Run Setup.sh in UNREALENGINE # Run Setup.sh in UNREALENGINE
# #
os.chdir(UNREALENGINE) shell(UNREALENGINE, f"{UNREALENGINE}/Setup.{BAT}")
shell("./Setup.sh")
os.chdir(INTEGRATION)
# #
# Use UnrealBuildTool to generate a rough draft of Integration.code-workspace. # 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. # 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) 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. # Configure the correct build task as the default task.
# #
for task in WORKSPACE["tasks"]["tasks"]: for task in WORKSPACE["tasks"]["tasks"]:
if task["label"] == "IntegrationEditor Linux DebugGame Build": if task["label"] == f"IntegrationEditor {OS} DebugGame Build":
task["group"] = { "kind": "build", "isDefault": "true" } task["group"] = { "kind": "build", "isDefault": True }
# #
# Delete all build tasks that aren't relevant. # Delete all build tasks that aren't relevant.
# #
def goodtask(task): 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)] 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. # 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) json.dump(WORKSPACE, rewritten, indent=4)
# #
# Do an initial build of Luprex # Do an initial build of Luprex
# #
os.chdir(f"{INTEGRATION}/luprex")
print("Building luprex...") print("Building luprex...")
shell("make") shell(f"{INTEGRATION}/luprex", "make")
os.chdir(INTEGRATION)
# #
# Build ShaderCompileWorker # Build ShaderCompileWorker
# #
os.chdir(UNREALENGINE)
print("Building ShaderCompileWorker...") print("Building ShaderCompileWorker...")
shell("Engine/Build/BatchFiles/Linux/Build.sh ShaderCompileWorker Linux Shipping -waitmutex") shell(UNREALENGINE, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} ShaderCompileWorker {OS} Shipping -waitmutex")
Path("Engine/Binaries/Linux/ShaderCompileWorker").unlink(missing_ok=True) Path(f"Engine/Binaries/{OS}/ShaderCompileWorker{DOT_EXE}").unlink(missing_ok=True)
shutil.copyfile("Engine/Binaries/Linux/ShaderCompileWorker-Linux-Shipping", "Engine/Binaries/Linux/ShaderCompileWorker") shutil.copyfile(f"{UNREALENGINE}/Engine/Binaries/{OS}/ShaderCompileWorker-{OS}-Shipping{DOT_EXE}", f"{UNREALENGINE}/Engine/Binaries/{OS}/ShaderCompileWorker{DOT_EXE}")
os.chdir(INTEGRATION)
# #
# Build Integration # Build Integration
# #
print("Building 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')

View File

@@ -5,11 +5,9 @@
####################################################################### #######################################################################
ifneq "" "$(findstring -linux-,$(MAKE_HOST))" ifneq "" "$(findstring -linux-,$(MAKE_HOST))"
OS=linux OS=Linux
else ifneq "" "$(VSINSTALLDIR)" else ifneq "" "$(VSINSTALLDIR)"
OS=visual OS=Windows
else ifneq "" "$(findstring cmd.exe,$(COMSPEC))"
OS=mingw
else else
OS="" OS=""
endif endif
@@ -110,7 +108,7 @@ OBJ_DRV=\
## ##
####################################################################### #######################################################################
ifeq "$(OS)" "linux" ifeq "$(OS)" "Linux"
OPT=-g -O0 OPT=-g -O0
LUPREX_EXE=luprex LUPREX_EXE=luprex
LUPREXLIB_DLL=luprexlib.so LUPREXLIB_DLL=luprexlib.so
@@ -124,35 +122,13 @@ ifeq "$(OS)" "linux"
LIBS=-L./ext/openssl-3.0.1/lib/linux -lssl -lcrypto -ldl LIBS=-L./ext/openssl-3.0.1/lib/linux -lssl -lcrypto -ldl
endif endif
#######################################################################
##
## Make rules for mingw
##
#######################################################################
ifeq "$(OS)" "mingw"
OPT=-g -O0
LUPREX_EXE=luprex.exe
LUPREXLIB_DLL=luprexlib.dll
LUPREXSTATIC_EXE=luprexstatic.exe
COMPILE=g++ -Wall $(OPT) -std=c++17 -fvisibility=hidden -c -MMD -fPIC -o
LINKDLL=g++ -Wall $(OPT) -std=c++17 -Wl,--no-allow-shlib-undefined -shared -o
LINKEXE=g++ -Wall $(OPT) -std=c++17 -o
MAKEDEPS=true
OPENSSL_INCLUDE=-I./ext/openssl-3.0.1/inc
LUA_FLAGS=-DLUA_USE_APICHECK -DLUA_COMPAT_ALL
LIBS=-L./ext/openssl-3.0.1/lib/mingw -lssl -lcrypto -lws2_32 -lcrypt32 -lcryptui
endif
####################################################################### #######################################################################
## ##
## Make rules for visual ## Make rules for visual
## ##
####################################################################### #######################################################################
ifeq "$(OS)" "visual" ifeq "$(OS)" "Windows"
ifeq "" "$(VSINSTALLDIR)" ifeq "" "$(VSINSTALLDIR)"
$(error You must use vcvars64.bat to set up the visual studio environment variables) $(error You must use vcvars64.bat to set up the visual studio environment variables)
endif endif