From d764bb32be060bc7cacf9b14090252b50828cde1 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Thu, 29 Jun 2023 14:40:36 +0100 Subject: [PATCH] Add option to build plugins against different versions of UE --- doc/BuildPlugin.md | 23 ++++++++++++- inc/uplugin.ps1 | 12 +++++++ ue-build-plugin.ps1 | 79 +++++++++++++++++++++++++++++++-------------- 3 files changed, 89 insertions(+), 25 deletions(-) diff --git a/doc/BuildPlugin.md b/doc/BuildPlugin.md index 3bb5e07..c79d3fe 100644 --- a/doc/BuildPlugin.md +++ b/doc/BuildPlugin.md @@ -15,6 +15,9 @@ Usage: -src : Source folder (current folder if omitted) : (should be root of project) -allplatforms : Build for all platforms, not just the current one + -allversions : Build for all supported UE versions, not just the current one" + : (specified in pluginconfig.json, only works with lancher-installed UE)" + -uever:5.x.x : Build for a specific UE version, not the current one (launcher only)" -dryrun : Don't perform any actual actions, just report on what you would do -help : Print this help @@ -33,7 +36,25 @@ in the root of your plugin, next to the .uplugin file. The options are: "PackageDir": "C:\\Users\\Steve\\Marketplace", "BuildDir": "C:\\Users\\Steve\\Builds\\MyPlugin", "PluginFile": "OptionalPluginFilenameWillDetectInDirOtherwise.uplugin", + + "EngineVersions": + [ + "5.1.0", + "5.2.0" + ] + + } ``` -Only `BuildDir` is required. \ No newline at end of file +Only `BuildDir` is required. + +The `-allversions` option only works with Launcher installed engines, +since the path is derived from UEROOT. If using non-Launcher engines, or you +need to change some other environmental options per version (e.g. setting +`LINUX_MULTIARCH_ROOT` environment var), then you're recommended to instead +use the `-uever:` option to build one version at a time, and set the environment +(including `UEINSTALL`) specifically for each version. + +This script will, however, handle changing the EngineVersion in the .uplugin +during the build, and resetting it afterwards. \ No newline at end of file diff --git a/inc/uplugin.ps1 b/inc/uplugin.ps1 index 5d33f3d..d235525 100644 --- a/inc/uplugin.ps1 +++ b/inc/uplugin.ps1 @@ -32,3 +32,15 @@ function Get-Uplugin-Filename { return $projfile } } + +function Update-UpluginUeVersion { + [string]$srcfolder, + [PluginConfig]$config, + [string]$version + + $pluginfile = Get-Uplugin-Filename $srcfolder $config + $plugincontents = (Get-Content $pluginfile) | ConvertFrom-Json + $proj.EngineVersion = $version + $newjson = ($plugincontents | ConvertTo-Json -depth 100) + $newjson | Out-File $pluginfile +} \ No newline at end of file diff --git a/ue-build-plugin.ps1 b/ue-build-plugin.ps1 index 492d53c..590fc3d 100644 --- a/ue-build-plugin.ps1 +++ b/ue-build-plugin.ps1 @@ -3,6 +3,8 @@ param ( [string]$mode, [string]$src, [switch]$allplatforms = $false, + [switch]$allversions = $false, + [string]$uever = "", [switch]$nocloseeditor = $false, [switch]$dryrun = $false, [switch]$help = $false @@ -23,6 +25,9 @@ function Print-Usage { Write-Output " -src : Source folder (current folder if omitted)" Write-Output " : (should be root of project)" Write-Output " -allplatforms : Build for all platforms, not just the current one" + Write-Output " -allversions : Build for all supported UE versions, not just the current one" + Write-Output " : (specified in pluginconfig.json, only works with lancher-installed UE)" + Write-Output " -uever:5.x.x : Build for a specific UE version, not the current one (launcher only)" Write-Output " -dryrun : Don't perform any actual actions, just report on what you would do" Write-Output " -help : Print this help" Write-Output " " @@ -64,43 +69,69 @@ try { } $proj = Read-Uproject $pluginfile - $ueVersion = Get-UE-Version $proj - $ueinstall = Get-UE-Install $ueVersion + $origUeVersion = Get-UE-Version $proj + if ($allversions) { + $ueVersions = $config.EngineVersions + } elseif ($uever.Length -gt 0) { + $ueVersions = @($uever) + } else { + $ueVersions = @($origUeVersion) + } + Write-Output "" - Write-Output "Project File : $projfile" - Write-Output "UE Version : $ueVersion" - Write-Output "UE Install : $ueinstall" + Write-Output "Project File : $pluginfile" + Write-Output "UE Version(s) : $($ueVersions -join `", `")" Write-Output "Output Folder : $($config.BuildDir)" Write-Output "" - $runUAT = Join-Path $ueinstall "Engine/Build/BatchFiles/RunUAT$batchSuffix" + foreach ($ver in $ueVersions) { + Write-Output "Building for UE Version $ver" + $ueinstall = Get-UE-Install $ver + $outputDir = Join-Path $config.BuildDir $ver - $argList = [System.Collections.ArrayList]@() - $argList.Add("BuildPlugin") > $null - $argList.Add("-Plugin=`"$pluginfile`"") > $null - $argList.Add("-Package=`"$($config.BuildDir)`"") > $null - $argList.Add("-Rocket") > $null + # Need to change the version in the plugin while we build + if (-not $dryrun -and ($allversions -or $ueVer.Length -gt 0)) { + Update-UpluginUeVersion $src $config $ver + } - if (-not $allplatforms) { - $targetPlatform = Get-Platform - $argList.Add("-TargetPlatforms=$targetPlatform") > $null - } + $runUAT = Join-Path $ueinstall "Engine/Build/BatchFiles/RunUAT$batchSuffix" - if ($dryrun) { - Write-Output "" - Write-Output "Would have run:" - Write-Output "> $runUAT $($argList -join " ")" - Write-Output "" + $argList = [System.Collections.ArrayList]@() + $argList.Add("BuildPlugin") > $null + $argList.Add("-Plugin=`"$pluginfile`"") > $null + $argList.Add("-Package=`"$outputDir`"") > $null + $argList.Add("-Rocket") > $null - } else { - $proc = Start-Process $runUAT $argList -Wait -PassThru -NoNewWindow - if ($proc.ExitCode -ne 0) { - throw "RunUAT failed!" + if (-not $allplatforms) { + $targetPlatform = Get-Platform + $argList.Add("-TargetPlatforms=$targetPlatform") > $null + } + + 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) { + # Reset the plugin back to the original UE version + if ($allversions -and -not $dryrun) { + Update-UpluginUeVersion $src $config $origUeVersion + } + + throw "RunUAT failed!" + } } } + # Reset the plugin back to the original UE version + if ($allversions -and -not $dryrun) { + Update-UpluginUeVersion $src $config $origUeVersion + } Write-Output "-- Build plugin process finished OK --"