-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathue-package.ps1
388 lines (336 loc) · 14.7 KB
/
ue-package.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# Packaging helper
# Bumps versions, builds, cooks, packages variants
# Put packageconfig.json in your project folder to configure
# See packageconfig_template.json
[CmdletBinding()] # Fail on unknown args
param (
[string]$src,
[string]$out,
[switch]$major = $false,
[switch]$minor = $false,
[switch]$patch = $false,
[switch]$hotfix = $false,
[switch]$nightly = $false,
# Don't increment version
[switch]$keepversion = $false,
# Name of variant to build (optional, uses DefaultVariants from packageconfig.json if unspecified)
[array]$variants,
# Testing mode; skips clean checks, tags
[switch]$test = $false,
# Browse the output directory in file explorer after packaging
[switch]$browse = $false,
# Dry-run; does nothing but report what *would* have happened
[switch]$dryrun = $false,
[switch]$help = $false
)
. $PSScriptRoot\inc\platform.ps1
. $PSScriptRoot\inc\packageconfig.ps1
. $PSScriptRoot\inc\projectversion.ps1
. $PSScriptRoot\inc\uproject.ps1
. $PSScriptRoot\inc\ueeditor.ps1
. $PSScriptRoot\inc\filetools.ps1
function Write-Usage {
Write-Output "Steve's Unreal packaging tool"
Write-Output "Usage:"
Write-Output " ue-package.ps1 [-src:sourcefolder] [-out:folder] [-major|-minor|-patch|-hotfix] [-keepversion] [-force] [-variant=VariantName] [-test] [-dryrun]"
Write-Output " "
Write-Output " -src : Source folder (current folder if omitted), must contain packageconfig.json"
Write-OUtput " -out : Overrides OutputDir in packageconfig.json"
Write-Output " -major : Increment major version i.e. [x++].0.0.0"
Write-Output " -minor : Increment minor version i.e. x.[x++].0.0"
Write-Output " -patch : Increment patch version i.e. x.x.[x++].0 (default)"
Write-Output " -hotfix : Increment hotfix version i.e. x.x.x.[x++]"
Write-Output " -keepversion : Keep current version number, doesn't tag unless -forcetag"
Write-Output " -nightly : Nightly build, doesn't tag, doesn't commit, re-uses same nightly folder, appends git rev version"
Write-Output " -variants Name1,Name2,Name3"
Write-Output " : Build only named variants instead of DefaultVariants from packageconfig.json"
Write-Output " -test : Testing mode, separate builds, allow dirty working copy"
Write-Output " -browse : After packaging, browse the output folder"
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:"
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 " "
}
if ($src.Length -eq 0) {
$src = "."
Write-Verbose "-src not specified, assuming current directory"
}
$ErrorActionPreference = "Stop"
if ($help) {
Write-Usage
Exit 0
}
Write-Output "~-~-~ Unreal Packaging Helper Start ~-~-~"
if ($test) {
Write-Output "TEST MODE: No tagging, version bumping"
}
if (([bool]$major + [bool]$minor + [bool]$patch + [bool]$hotfix) -gt 1) {
Write-Output "ERROR: Can't set more than one of major/minor/patch/hotfix at the same time!"
Print-Usage
Exit 5
}
if (($major -or $minor -or $patch -or $hotfix) -and $keepversion) {
Write-Output "ERROR: Can't set keepversion at the same time as major/minor/patch/hotfix!"
Print-Usage
Exit 5
}
# Detect Git
if ($src -ne ".") { Push-Location $src }
$isGit = Test-Path ".git"
if ($src -ne ".") { Pop-Location }
# Check working copy is clean (Git only)
if (-not $test -and $isGit) {
if ($src -ne ".") { Push-Location $src }
if (Test-Path ".git") {
git diff --no-patch --exit-code
if ($LASTEXITCODE -ne 0) {
Write-Output "Working copy is not clean (unstaged changes)"
if ($dryrun) {
Write-Output "dryrun: Continuing but this will fail without -dryrun"
} else {
Exit $LASTEXITCODE
}
}
git diff --no-patch --cached --exit-code
if ($LASTEXITCODE -ne 0) {
Write-Output "Working copy is not clean (staged changes)"
if ($dryrun) {
Write-Output "dryrun: Continuing but this will fail without -dryrun"
} else {
Exit $LASTEXITCODE
}
}
}
if ($src -ne ".") { Pop-Location }
}
try {
# Import config & project settings
$config = Read-Package-Config -srcfolder:$src
$projfile = Get-Uproject-Filename -srcfolder:$src -config:$config
$proj = Read-Uproject $projfile
$ueVersion = Get-UE-Version $proj
$ueinstall = Get-UE-Install $ueVersion
$chosenVariantNames = $config.DefaultVariants
if ($variants) {
$chosenVariantNames = $variants
}
# TODO support overriding default variants with args
$chosenVariants = $config.Variants | Where-Object { $chosenVariantNames -contains $_.Name }
if ($chosenVariants.Count -ne $chosenVariantNames.Count) {
$unmatchedVariants = $chosenVariantNames | Where-Object { $chosenVariants.Name -notcontains $_ }
Write-Warning "Unknown variant(s) ignored: $($unmatchedVariants -join ", ")"
}
$foundmaps = Find-Files -startDir:$(Join-Path $src "Content") -pattern:*.umap -includeByDefault:$config.CookAllMaps -includeBaseNames:$config.MapsIncluded -excludeBaseNames:$config.MapsExcluded
$maps = $foundmaps.BaseNames
$mapsdesc = $maps ? $maps -join ", " : "Default (Project Settings)"
Write-Output ""
Write-Output "Project File : $projfile"
Write-Output "UE Version : $ueVersion"
Write-Output "UE Install : $ueinstall"
if ($out.Length -eq 0) {
Write-Output "Output Folder : $($config.OutputDir)"
} else {
Write-Output "Output Folder : $out"
}
Write-Output "Zipped Folder : $($config.ZipDir)"
Write-Output ""
Write-Output "Chosen Variants : $chosenVariantNames"
Write-Output "Maps to Cook : $mapsdesc"
Write-Output ""
if (-not $dryrun)
{
$editorprojname = [System.IO.Path]::GetFileNameWithoutExtension($projfile)
Close-UE-Editor $editorprojname $dryrun
}
if (([bool]$major + [bool]$minor + [bool]$patch + [bool]$hotfix) -eq 0) {
$patch = $true
}
$versionNumber = $null
if ($nightly) {
$versionNumber = "nightly"
if ($isGit)
{
# Add the git ref to the version number in the project ONLY (not our folder)
$tempverobj = Get-ProjectVersionComponents $src
$gitref = $(git rev-parse --short HEAD)
$tempverobj.postfix = "-$gitref"
Write-Output "Packaging nightly-$gitref"
Write-ProjectVersionFromObject -srcfolder:$src -versionObj:$tempverobj -dryrun:$dryrun
}
} elseif ($keepversion) {
$versionNumber = Get-Project-Version $src
} else {
# Bump up version, passthrough options
try {
$versionNumber = Increment-Project-Version -srcfolder:$src -major:$major -minor:$minor -patch:$patch -hotfix:$hotfix -dryrun:$dryrun
if (-not $dryrun -and $isGit) {
if ($src -ne ".") { Push-Location $src }
$verIniFile = Get-Project-Version-Ini-Filename $src
git add "$($verIniFile)"
if ($LASTEXITCODE -ne 0) { Exit $LASTEXITCODE }
git commit -m "Version bump to $versionNumber"
if ($LASTEXITCODE -ne 0) { Exit $LASTEXITCODE }
if ($src -ne ".") { Pop-Location }
}
}
catch {
Write-Output $_.Exception.Message
Exit 6
}
}
# Keep test builds separate
if ($test) {
$versionNumber = "$versionNumber-test"
}
Write-Output "Next version will be: $versionNumber"
# For tagging release
# We only need to grab the main version once
if (-not $keepversion -and -not $nightly) {
if (-not $test -and -not $dryrun -and $isGit) {
if ($src -ne ".") { Push-Location $src }
git tag -a $versionNumber -m "Automated release tag"
if ($LASTEXITCODE -ne 0) { Exit $LASTEXITCODE }
if ($src -ne ".") { Pop-Location }
}
}
# We need to build the host Editor target explicitly first, which will be used
# to run the "Cook" stage. If we don't do this, then any source plugins will
# be missing in a clean checkout build and the cook stage will fail
Write-Output "Building Editor (for Cooking)"
$cmdargs = @()
$cmdargs += "-src:$src"
if ($dryrun) {
$cmdargs += "-dryrun"
}
Invoke-Expression "&'$PSScriptRoot/ue-build.ps1' -mode:dev $cmdargs"
$ueEditorCmd = Get-UEEditorCmd $ueVersion $ueinstall
$runUAT = Join-Path $ueinstall "Engine/Build/BatchFiles/RunUAT$batchSuffix"
foreach ($var in $chosenVariants) {
if ($out.Length -gt 0) {
$outDir = Join-Path $out "$($var.Name)-$($versionNumber)"
} else {
$outDir = Get-Package-Dir -config:$config -versionNumber:$versionNumber -variantName:$var.Name
}
# Delete previous
Remove-Item -Path $outDir -Recurse -Force -ErrorAction SilentlyContinue
$argList = [System.Collections.ArrayList]@()
$argList.Add("-ScriptsForProject=`"$projfile`"") > $null
$argList.Add("BuildCookRun") > $null
$argList.Add("-nocompileeditor") > $null
#$argList.Add("-installed") > $null # don't think we need this, seems to be detected
$argList.Add("-nop4") > $null
$argList.Add("-project=`"$projfile`"") > $null
$argList.Add("-cook") > $null
$argList.Add("-stage") > $null
$argList.Add("-archive") > $null
$argList.Add("-archivedirectory=`"$($outDir)`"") > $null
$argList.Add("-package") > $null
if ((Get-Is-UE5 $ueVersion)) {
$argList.Add("-unrealexe=`"$ueEditorCmd`"") > $null
} else {
$argList.Add("-ue4exe=`"$ueEditorCmd`"") > $null
}
if ($config.UsePak) {
$argList.Add("-pak") > $null
}
$argList.Add("-prereqs") > $null
$argList.Add("-build") > $null
$argList.Add("-target=$($config.Target)") > $null
$argList.Add("-clientconfig=$($var.Configuration)") > $null
$argList.Add("-targetplatform=$($var.Platform)") > $null
$argList.Add("-utf8output") > $null
if ($maps.Count) {
$argList.Add("-Map=$($maps -join "+")") > $null
}
if ($var.Cultures) {
$argList.Add("-cookcultures=$($var.Cultures -join "+")") > $null
}
$argList.Add($var.ExtraBuildArguments) > $null
Write-Output "Building variant: $($var.Name)"
if ($dryrun) {
Write-Output ""
Write-Output "Would have run:"
Write-Output "> $runUAT $($argList -join " ")"
Write-Output ""
} else {
$proc = Start-Process $runUAT $argList -Wait -PassThru -NoNewWindow
if ($proc.ExitCode -ne 0) {
throw "RunUAT failed!"
}
}
if ($config.RenameExe.Length -gt 0) {
if ($dryrun) {
Write-Output "Would have renamed EXE from $($config.Target) to $($config.RenameExe)"
} else {
# Rename the executable
$subdirs = @(Get-ChildItem $outdir)
$subdirs | ForEach-Object {
$renameExeSuffix = ""
if ($var.Platform -like "Win*") {
$renameExeSuffix = ".exe"
}
$exeSrcName = Join-Path $_.FullName "$($config.Target)$renameExeSuffix"
$exeDestName = Join-Path $_.FullName "$($config.RenameExe)$renameExeSuffix"
Move-Item $exeSrcName $exeDestName -Force
}
}
}
if ($var.Configuration -eq "Shipping")
{
# For shipping, move the PDBs aside but keep them for later use
$outDirPDB = "$($outDir)-ShippingPDB"
Remove-Item -Path $outDirPDB -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory $outDirPDB -Force > $null
$pdbs = @(Get-ChildItem -Path $outDir -Filter *.pdb -Recurse -ErrorAction SilentlyContinue -Force)
# Need to be in dir to calculate relative
Push-Location $outDir
$pdbs | ForEach-Object {
$pdbdir = Join-Path $outDirPDB $($_.DirectoryName | Resolve-Path -Relative)
New-Item -ItemType Directory $pdbdir -Force > $null
$pdbdest = Join-Path $outDirPDB $($_.FullName | Resolve-Path -Relative)
Move-Item $_.FullName $pdbdest -Force
}
Pop-Location
}
if ($var.Zip) {
if ($dryrun) {
Write-Output "Would have compressed $outdir to $(Join-Path $config.ZipDir "$($config.Target)_$($versionNumber)_$($var.Name).zip")"
} else {
# We zip all subfolders of the out dir separately
# Since there may be multiple build dirs in the case of server & client builds
# E.g. WindowsNoEditor vs WindowsServer
# BUT we omit the folder name in the zip if there's only one, for brevity
$subdirs = @(Get-ChildItem $outdir)
$multipleBuilds = ($subdirs.Count > 1)
$subdirs | ForEach-Object {
$zipsrc = "$($_.FullName)\*" # excludes folder name, compress contents
$subdirSuffix = ""
if ($multipleBuilds) {
# Only include "WindowsNoEditor" etc part if there's a need to disambiguate
$subdirSuffix = "_$($_.BaseName)"
}
$zipdst = Join-Path $config.ZipDir "$($config.Target)_$($versionNumber)_$($var.Name)$subdirSuffix.zip"
New-Item -ItemType Directory -Path $config.ZipDir -Force > $null
Write-Output "Compressing to $zipdst"
Compress-Archive -Path $zipsrc -DestinationPath $zipdst
}
}
}
}
if ($browse -and -not $dryrun) {
Invoke-Item $(Join-Path $config.OutputDir $versionNumber)
}
}
catch {
Write-Output $_.Exception.Message
Write-Output "~-~-~ Unreal Packaging Helper FAILED ~-~-~"
Exit 9
}
# Revert any remaining temp changes
git checkout .
Write-Output "~-~-~ Unreal Packaging Helper Completed OK ~-~-~"