UEScripts/ue-build.ps1

180 lines
6.1 KiB
PowerShell
Raw Normal View History

2020-05-11 12:29:07 +01:00
[CmdletBinding()] # Fail on unknown args
param (
[string]$mode,
[string]$src,
[switch]$nocloseeditor = $false,
[switch]$dryrun = $false,
[switch]$help = $false
)
function Print-Usage {
2022-04-19 12:07:09 +01:00
Write-Output "Steve's Unreal Build Tool"
2020-05-11 12:29:07 +01:00
Write-Output " This is a WIP, only builds for dev right now"
Write-Output "Usage:"
Write-Output " ue-build.ps1 [[-mode:]<dev|test|prod>] [[-src:]sourcefolder] [Options]"
2020-05-11 12:29:07 +01:00
Write-Output " "
2020-05-12 14:11:01 +01:00
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"
Write-Output " : prod = build Shipping and package for production"
2020-05-11 12:29:07 +01:00
Write-Output " -src : Source folder (current folder if omitted)"
Write-Output " : (should be root of project)"
2022-04-19 12:07:09 +01:00
Write-Output " -nocloseeditor : Don't close Unreal editor (this will prevent DLL cleanup)"
2020-05-11 12:29:07 +01:00
Write-Output " -dryrun : Don't perform any actual actions, just report on what you would do"
Write-Output " -help : Print this help"
Write-Output " "
Write-Output "Environment Variables:"
2022-04-19 12:07:09 +01:00
Write-Output " UEINSTALL : Use a specific Unreal install."
Write-Output " : Default is to find one based on project version, under UEROOT"
Write-Output " UEROOT : Parent folder of all binary Unreal installs (detects version). "
Write-Output " : Default C:\Program Files\Epic Games"
Write-Output " "
2020-05-11 12:29:07 +01:00
}
$ErrorActionPreference = "Stop"
if ($help) {
Print-Usage
Exit 0
}
if (-not $mode) {
2020-05-12 14:11:01 +01:00
$mode = "dev"
2020-05-11 12:29:07 +01:00
}
if ($src.Length -eq 0) {
$src = "."
Write-Verbose "-src not specified, assuming current directory"
}
if (-not ($mode -in @('dev', 'cleandev', 'test', 'prod'))) {
2020-05-11 12:29:07 +01:00
Print-Usage
Write-Output "ERROR: Invalid mode argument: $mode"
Exit 3
}
. $PSScriptRoot\inc\buildtargets.ps1
2020-05-11 12:29:07 +01:00
$result = 0
try {
if ($src -ne ".") { Push-Location $src }
2021-02-18 16:03:05 +00:00
Write-Output "-- Build process starting --"
2022-04-19 12:07:09 +01:00
# Locate Unreal project file
2020-05-11 12:29:07 +01:00
$uprojfile = Get-ChildItem *.uproject | Select-Object -expand Name
if (-not $uprojfile) {
throw "No Unreal project file found in $(Get-Location)! Aborting."
}
if ($uprojfile -is [array]) {
throw "Multiple Unreal project files found in $(Get-Location)! Aborting."
}
# In PS 6.0+ we could use Split-Path -LeafBase but let's stick with built-in PS 5.1
$uprojname = [System.IO.Path]::GetFileNameWithoutExtension($uprojfile)
2020-05-12 11:39:42 +01:00
if ($dryrun) {
Write-Output "Would build $uprojname for $mode"
} else {
Write-Output "Building $uprojname for $mode"
}
2020-05-11 12:29:07 +01:00
2022-04-19 12:07:09 +01:00
# Check version number of Unreal project so we know which version to run
2020-05-11 12:29:07 +01:00
# We can read this from .uproject which is JSON
$uproject = Get-Content $uprojfile | ConvertFrom-Json
$uversion = $uproject.EngineAssociation
2020-05-12 16:05:46 +01:00
Write-Output "Engine version is $uversion"
2022-04-19 12:07:09 +01:00
# UEINSTALL env var should point at the root of the *specific version* of
# Unreal you want to use. This is mainly for use in source builds, default is
# to build it from version number and root of all UE binary installs
$uinstall = $Env:UEINSTALL
2020-05-11 12:29:07 +01:00
2022-04-19 12:07:09 +01:00
# Backwards compat with old env var
2020-05-11 12:29:07 +01:00
if (-not $uinstall) {
2022-04-19 12:07:09 +01:00
$uinstall = $Env:UE4INSTALL
}
if (-not $uinstall) {
# UEROOT should be the parent folder of all UE versions
$uroot = $Env:UEROOT
# Backwards compat with old env var
if (-not $uroot) {
$uroot = $Env:UE4ROOT
}
2020-05-11 12:29:07 +01:00
if (-not $uroot) {
$uroot = "C:\Program Files\Epic Games"
}
$uinstall = Join-Path $uroot "UE_$uversion"
}
# Test we can find Build.bat
$batchfolder = Join-Path "$uinstall" "Engine\Build\BatchFiles"
$buildbat = Join-Path "$batchfolder" "Build.bat"
if (-not (Test-Path $buildbat -PathType Leaf)) {
throw "Build.bat missing at $buildbat : Aborting"
2020-05-11 12:29:07 +01:00
}
$buildargs = ""
switch ($mode) {
'dev' {
# Stolen from the VS project settings because boy is this badly documented
# 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
$target = Find-DefaultTarget $src "Editor"
$buildargs = "$target Win64 Development -Project=`"${uprojfileabs}`" -WaitMutex -FromMsBuild"
}
'cleandev' {
$uprojfileabs = Join-Path "$(Get-Location)" $uprojfile
$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
# We probably want to use custom launch profiles for this
Write-Output "Mode '$mode' is not supported yet"
}
}
2020-05-11 12:29:07 +01:00
if ($dryrun) {
Write-Output "Would run: build.bat $buildargs"
} else {
Write-Verbose "Running $buildbat $buildargs"
2021-02-18 16:03:05 +00:00
$proc = Start-Process $buildbat $buildargs -Wait -PassThru -NoNewWindow
if ($proc.ExitCode -ne 0) {
$code = $proc.ExitCode
throw "*** Build exited with code $code, see above"
}
}
2020-05-11 12:29:07 +01:00
2020-05-12 11:39:42 +01:00
Write-Output "-- Build process finished OK --"
2020-05-11 12:29:07 +01:00
} catch {
Write-Output "ERROR: $($_.Exception.Message)"
$result = 9
} finally {
if ($src -ne ".") { Pop-Location }
}
Exit $result