Fix ue-build.ps1 when modules are named differently to uproject

This commit is contained in:
Steve Streeting 2023-06-26 10:45:48 +01:00
parent 42c3c5bffa
commit 40c0bc31bb
2 changed files with 49 additions and 5 deletions

27
inc/buildtargets.ps1 Normal file
View File

@ -0,0 +1,27 @@
function Find-DefaultTarget {
param (
[string]$srcfolder,
# Game, Editor, Server, Client
[string]$preferred = "Editor"
)
# Enumerate the Target.cs files in Source folder and use the default one
# This lets us not assume what the modules are called exactly
$targetFiles = Get-ChildItem (Join-Path $srcfolder "Source" "*.Target.cs")
foreach ($file in $targetfiles) {
if ($file.Name -like "*$preferred.Target.cs") {
return $file.Name.SubString(0, $file.Name.Length - 10)
}
}
# Fall back on Game if nothing else
foreach ($file in $targetfiles) {
if ($file.Name -like "*Game.Target.cs") {
return $file.Name.SubString(0, $file.Name.Length - 10)
}
}
throw "Unable to find default build target ending in $preferred"
}

View File

@ -16,8 +16,8 @@ function Print-Usage {
Write-Output " -mode : Build mode"
Write-Output " : dev = build Development Editor, dlls only (default)"
Write-Output " : cleandev = build Development Editor CLEANLY"
Write-Output " : test = build Development and pacakge for test (TODO)"
Write-Output " : prod = build Shipping and package for production (TODO)"
Write-Output " : test = build Development and pacakge for test"
Write-Output " : prod = build Shipping and package for production"
Write-Output " -src : Source folder (current folder if omitted)"
Write-Output " : (should be root of project)"
Write-Output " -nocloseeditor : Don't close Unreal editor (this will prevent DLL cleanup)"
@ -45,6 +45,11 @@ if (-not $mode) {
$mode = "dev"
}
if ($src.Length -eq 0) {
$src = "."
Write-Verbose "-src not specified, assuming current directory"
}
if (-not ($mode -in @('dev', 'cleandev', 'test', 'prod'))) {
Print-Usage
Write-Output "ERROR: Invalid mode argument: $mode"
@ -52,6 +57,7 @@ if (-not ($mode -in @('dev', 'cleandev', 'test', 'prod'))) {
}
. $PSScriptRoot\inc\buildtargets.ps1
$result = 0
@ -120,15 +126,26 @@ try {
switch ($mode) {
'dev' {
# Stolen from the VS project settings because boy is this badly documented
# Target needs "Editor" on the end to make this "Development Editor"
# The -Project seems to be needed, as is the -FromMsBuild
# -Project has to point at the ABSOLUTE PATH of the uproject
$uprojfileabs = Join-Path "$(Get-Location)" $uprojfile
$buildargs = "${uprojname}Editor Win64 Development -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild"
$target = Find-DefaultTarget $src "Editor"
$buildargs = "$target Win64 Development -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild"
}
'cleandev' {
$uprojfileabs = Join-Path "$(Get-Location)" $uprojfile
$buildargs = "${uprojname}Editor Win64 Development -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild -clean"
$target = Find-DefaultTarget $src "Editor"
$buildargs = "$target Win64 Development -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild -clean"
}
'test' {
$uprojfileabs = Join-Path "$(Get-Location)" $uprojfile
$target = Find-DefaultTarget $src "Game"
$buildargs = "$target Win64 Test -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild -clean"
}
'prod' {
$uprojfileabs = Join-Path "$(Get-Location)" $uprojfile
$target = Find-DefaultTarget $src "Game"
$buildargs = "$target Win64 Shipping -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild -clean"
}
default {
# TODO