diff --git a/inc/buildtargets.ps1 b/inc/buildtargets.ps1 new file mode 100644 index 0000000..31a7c5c --- /dev/null +++ b/inc/buildtargets.ps1 @@ -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" + +} diff --git a/ue-build.ps1 b/ue-build.ps1 index adac5b0..924818f 100644 --- a/ue-build.ps1 +++ b/ue-build.ps1 @@ -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