More work on clean build

This commit is contained in:
2024-10-03 15:31:51 -04:00
parent 67dba0b353
commit f127322a11
2 changed files with 98 additions and 27 deletions

View File

@@ -1,2 +1,3 @@
#define LUPREX_DLL_PATH "/home/jyelon/integration/luprex/build/linux/luprexlib.so" #define LUPREX_DLL_PATH "/home/jyelon/integration/luprex/build/linux/luprexlib.so"
#define LUPREX_ROOT_PATH "/home/jyelon/integration/luprex" #define LUPREX_ROOT_PATH "/home/jyelon/integration/luprex"

View File

@@ -2,34 +2,58 @@
# #
# This script generates these config files: # This script generates these config files:
# #
# Saved/UnrealBuildTool/BuildConfiguration.xml
# Integration.uproject # Integration.uproject
# Integration.code-workspace # Integration.code-workspace
# Makefile
# Source/Integration/lpx-paths.hpp
#
# 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 # Unreal needs "Integration.uproject". This config file tells
# UnrealBuildTool what version of the unreal engine to link this game # UnrealBuildTool what version of the unreal engine to link this game
# with. It also specifies a couple of other game-specific configuration # with. It also specifies a couple of other game-specific configuration
# settings. It can't easily be checked into git because it contains # settings. It can't easily be checked into git because it contains
# a GUID which is specific to your local machine. # 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 # VSCode needs "Integration.code-workspace," it tells vscode how to
# compile this game and how to run it under the debugger. It can't # compile this game and how to run it under the debugger. It can't
# be checked into git because it contains many hardwired # be checked into git because it contains many hardwired
# paths. # paths.
# #
# We generate Integration.uproject from scratch. Later, the unreal
# editor will inject the engine GUID into the file.
#
# The UnrealBuildTool which is included with the UnrealEngine can # The UnrealBuildTool which is included with the UnrealEngine can
# generate a rough draft of Integration.code-workspace. However, the # generate a rough draft of Integration.code-workspace. However, the
# file it generates is not well-configured for our luprex-related # file it generates is not well-configured for our luprex-related
# needs. # needs. This python script uses UnrealBuildTool to generate the rough
# draft, then it loads Integration.code-workspace into RAM, edits it
# in RAM, and writes a new, improved version back out.
# #
# This python script uses UnrealBuildTool to generate a rough draft, # We don't really need a Makefile, since Unreal games are build using
# then it loads Integration.code-workspace into RAM, edits it in RAM, # UnrealBuildTool, not make. But, having a one-liner makefile can at
# and writes a new, improved version back out. # 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 import sys, os, json
from pathlib import Path
#
# Some handy utility functions
#
def writefile(fn, str):
with open(fn, "w") as f:
f.write(str)
# #
# These are some directory paths that we will need. # These are some directory paths that we will need.
@@ -37,12 +61,48 @@ import sys, os, json
INTEGRATION = os.path.dirname(os.path.abspath(sys.argv[0])) INTEGRATION = os.path.dirname(os.path.abspath(sys.argv[0]))
UNREALENGINE = os.environ["HOME"] + "/UnrealEngine" UNREALENGINE = os.environ["HOME"] + "/UnrealEngine"
UNREALBUILDTOOL = f"{UNREALENGINE}/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll"
# #
# This is the template from which Integration.uproject is generated. # Change to the target directory.
# Remove any existing project files.
# #
UPROJECT_TEMPLATE=""" 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
#
writefile("Saved/UnrealBuildTool/Integration.uproject", f"""
<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
<ProjectFileGenerator>
<Format>VisualStudioCode</Format>
</ProjectFileGenerator>
</Configuration>
""")
#
# 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.
#
writefile("Integration.uproject", """
{ {
"FileVersion": 3, "FileVersion": 3,
"EngineAssociation": "5.3", "EngineAssociation": "5.3",
@@ -69,35 +129,22 @@ UPROJECT_TEMPLATE="""
} }
] ]
} }
""" """)
#
# Convert the UPROJECT template into json in RAM.
#
UPROJECT = json.loads(UPROJECT_TEMPLATE)
#
# Write Integration.uproject
#
with open("Integration.uproject", "w") as uproj:
json.dump(UPROJECT, uproj, indent=4)
# #
# Use UnrealBuildTool to generate a rough draft of Integration.code-workspace. # Use UnrealBuildTool to generate a rough draft of Integration.code-workspace.
# #
BUILDPROJECTFILES = f'dotnet Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll -projectfiles -project="{INTEGRATION}/Integration.uproject" -game -vscode' BUILDPROJECTFILES = f'dotnet {UNREALBUILDTOOL} -projectfiles -project="{INTEGRATION}/Integration.uproject" -game'
os.chdir(UNREALENGINE)
print(BUILDPROJECTFILES) print(BUILDPROJECTFILES)
os.system(BUILDPROJECTFILES) os.system(BUILDPROJECTFILES)
# #
# Load the rough draft into RAM, then delete the rough draft. # Load the rough Integration.code-workspace into RAM, then delete the rough draft.
# #
os.chdir(INTEGRATION)
with open("Integration.code-workspace") as original: with open("Integration.code-workspace") as original:
WORKSPACE=json.load(original) WORKSPACE=json.load(original)
os.remove("Integration.code-workspace") os.remove("Integration.code-workspace")
@@ -119,6 +166,20 @@ def goodtask(task):
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)]
#
# 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. # Convert all launch configurations to lldb.
# #
@@ -141,9 +202,18 @@ def goodconf(config):
WORKSPACE["launch"]["configurations"] = [x for x in WORKSPACE["launch"]["configurations"] if goodconf(x)] WORKSPACE["launch"]["configurations"] = [x for x in WORKSPACE["launch"]["configurations"] if goodconf(x)]
# #
# Write it all back out. # Write Integration.code-workspace.
# #
with open("Integration.code-workspace", "w") as rewritten: with open("Integration.code-workspace", "w") as rewritten:
json.dump(WORKSPACE, rewritten, indent=4) json.dump(WORKSPACE, rewritten, indent=4)
#
# Write the Makefile
#
writefile("Makefile", f"""
all:
(cd luprex ; make)
dotnet {UNREALBUILDTOOL} Integration Linux DebugGame -project="{INTEGRATION}/Integration.uproject"
""")