diff --git a/doc/BuildPlugin.md b/doc/BuildPlugin.md new file mode 100644 index 0000000..7ed92ce --- /dev/null +++ b/doc/BuildPlugin.md @@ -0,0 +1,38 @@ +# Building Plugins + +If you want to build a plugin so that you can test it locally as if it was a +Marketplace plugin (before you [package it](PluginPackage.md)), the +`ue-build-plugin.ps1` script can help make it easier. + +The plugin will be built for the current platform only, using the engine version +specified in the .uplugin file. + + +``` +Usage: + ue-build-plugin.ps1 [[-src:]sourcefolder] [Options] + + -src : Source folder (current folder if omitted) + : (should be root of project) + -dryrun : Don't perform any actual actions, just report on what you would do + -help : Print this help + +Environment Variables: + UEINSTALL : Use a specific Unreal install. + : Default is to find one based on project version, under UEROOT + UEROOT : Parent folder of all binary Unreal installs (detects version). + : Default C:\Program Files\Epic Games +``` + +This script operates based on a `pluginconfig.json` file which must be present +in the root of your plugin, next to the .uplugin file. The options are: + +```json +{ + "PackageDir": "C:\\Users\\Steve\\Marketplace", + "BuildDir": "C:\\Users\\Steve\\Builds\\MyPlugin", + "PluginFile": "OptionalPluginFilenameWillDetectInDirOtherwise.uplugin", +} +``` + +Only `BuildDir` is required. \ No newline at end of file diff --git a/doc/PluginPackage.md b/doc/PluginPackage.md index 5db5d3f..b44a7e8 100644 --- a/doc/PluginPackage.md +++ b/doc/PluginPackage.md @@ -11,7 +11,7 @@ to make that job easier. > Unfortunately the first time, this will probably mess with indenting because > of a difference of opinion between JSON libraries. But it's harmless. -```sh +``` Usage: ue-plugin-package.ps1 [-src:sourcefolder] [-major|-minor|-patch|-hotfix] [options...] @@ -34,7 +34,7 @@ in the root of your plugin, next to the .uplugin file. The options are: ```json { - "OutputDir": "C:\\Users\\Steve\\MarketplaceBuilds", + "PackageDir": "C:\\Users\\Steve\\MarketplaceBuilds", "PluginFile": "OptionalPluginFilenameWillDetectInDirOtherwise.uplugin", "EngineVersions": [ @@ -45,7 +45,7 @@ in the root of your plugin, next to the .uplugin file. The options are: } ``` -`OutputDir` and `EngineVersions` are required. +`PackageDir` and `EngineVersions` are required. ## Engine Versions diff --git a/inc/platform.ps1 b/inc/platform.ps1 index 8f2e988..02e5b33 100644 --- a/inc/platform.ps1 +++ b/inc/platform.ps1 @@ -15,3 +15,14 @@ if ($IsWindows) { if ($IsWindows) { $batchSuffix = ".bat" } + + +function Get-Platform { + if ($IsWindows) { + return "Win64" + } elseif ($IsLinux) { + return "Linux" + } else { + return "Mac" + } +} diff --git a/inc/pluginconfig.ps1 b/inc/pluginconfig.ps1 index 56ceb34..ccc7b50 100644 --- a/inc/pluginconfig.ps1 +++ b/inc/pluginconfig.ps1 @@ -1,7 +1,8 @@ class PluginConfig { - [string]$OutputDir + [string]$PackageDir + [string]$BuildDir [string]$PluginFile [array]$EngineVersions diff --git a/inc/uproject.ps1 b/inc/uproject.ps1 index 97de23f..4a7086c 100644 --- a/inc/uproject.ps1 +++ b/inc/uproject.ps1 @@ -51,7 +51,12 @@ function Get-UE-Version { [psobject]$uproject ) - return $uproject.EngineAssociation + if ($uproject.EngineAssociation) { + return $uproject.EngineAssociation + } else { + # Plugin + return $uproject.EngineVersion + } } function Get-Is-UE5 { @@ -88,7 +93,13 @@ function Get-UE-Install { $uroot = "C:\Program Files\Epic Games" } - $uinstall = Join-Path $uroot "UE_$ueVersion" + # When using $ueVersion, strip off 3rd digit if any + $regex = "(\d+\.\d+)(\.\d+)?" + $match = $ueVersion | Select-String -Pattern $regex + + $ueVersionTrimmed = $match.Matches[0].Groups[1].Value + + $uinstall = Join-Path $uroot "UE_$ueVersionTrimmed" } # Test we can find RunUAT.bat diff --git a/ue-build-plugin.ps1 b/ue-build-plugin.ps1 new file mode 100644 index 0000000..5b52c14 --- /dev/null +++ b/ue-build-plugin.ps1 @@ -0,0 +1,110 @@ +[CmdletBinding()] # Fail on unknown args +param ( + [string]$mode, + [string]$src, + [switch]$nocloseeditor = $false, + [switch]$dryrun = $false, + [switch]$help = $false +) + +. $PSScriptRoot\inc\platform.ps1 +. $PSScriptRoot\inc\pluginconfig.ps1 +. $PSScriptRoot\inc\pluginversion.ps1 +. $PSScriptRoot\inc\uproject.ps1 +. $PSScriptRoot\inc\uplugin.ps1 +. $PSScriptRoot\inc\filetools.ps1 + +function Print-Usage { + Write-Output "Steve's Unreal Plugin Build Tool" + Write-Output "Usage:" + Write-Output " ue-build-plugin.ps1 [[-src:]sourcefolder] [Options]" + Write-Output " " + Write-Output " -src : Source folder (current folder if omitted)" + Write-Output " : (should be root of project)" + 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 " " + +} + +$ErrorActionPreference = "Stop" + +if ($src.Length -eq 0) { + $src = "." + Write-Verbose "-src not specified, assuming current directory" +} + +if ($help) { + Print-Usage + Exit 0 +} + + +$result = 0 + +try { + if ($src -ne ".") { Push-Location $src } + + Write-Output "-- Build plugin process starting --" + + $config = Read-Plugin-Config -srcfolder:$src + + # Locate Unreal project file + $pluginfile = Get-Uplugin-Filename -srcfolder:$src -config:$config + if (-not $pluginfile) { + throw "Not in a uplugin dir!" + } + + $proj = Read-Uproject $pluginfile + $ueVersion = Get-UE-Version $proj + $ueinstall = Get-UE-Install $ueVersion + + Write-Output "" + Write-Output "Project File : $projfile" + Write-Output "UE Version : $ueVersion" + Write-Output "UE Install : $ueinstall" + Write-Output "Output Folder : $($config.BuildDir)" + Write-Output "" + + $runUAT = Join-Path $ueinstall "Engine/Build/BatchFiles/RunUAT$batchSuffix" + + $targetPlatform = Get-Platform + + $argList = [System.Collections.ArrayList]@() + $argList.Add("BuildPlugin") > $null + $argList.Add("-Plugin=`"$pluginfile`"") > $null + $argList.Add("-Package=`"$($config.BuildDir)`"") > $null + $argList.Add("-Rocket") > $null + $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) { + throw "RunUAT failed!" + } + } + + + Write-Output "-- Build plugin process finished OK --" + +} catch { + Write-Output "ERROR: $($_.Exception.Message)" + $result = 9 +} finally { + if ($src -ne ".") { Pop-Location } +} + + +Exit $result diff --git a/ue-plugin-package.ps1 b/ue-plugin-package.ps1 index fa367de..b2c386f 100644 --- a/ue-plugin-package.ps1 +++ b/ue-plugin-package.ps1 @@ -134,7 +134,7 @@ try { Write-Output "" Write-Output "Plugin File : $pluginfile" - Write-Output "Output Folder : $($config.OutputDir)" + Write-Output "Output Folder : $($config.PackageDir)" Write-Output "Engine Versions : $($config.EngineVersions -join ", ")" Write-Output "" @@ -193,11 +193,11 @@ try { # Zip parent of the uplugin folder $zipsrc = (Get-Item $pluginfile).Directory.FullName - $zipdst = Join-Path $config.OutputDir "$($pluginName)_v$($versionNumber)_UE$($EngineVer).zip" + $zipdst = Join-Path $config.PackageDir "$($pluginName)_v$($versionNumber)_UE$($EngineVer).zip" $excludefilename = "packageexclusions.txt" $excludefile = Join-Path $zipsrc $excludefilename - New-Item -ItemType Directory -Path $config.OutputDir -Force > $null + New-Item -ItemType Directory -Path $config.PackageDir -Force > $null Write-Output "Compressing to $zipdst" $argList = [System.Collections.ArrayList]@() @@ -250,7 +250,7 @@ try { if ($browse -and -not $dryrun) { - Invoke-Item $config.OutputDir + Invoke-Item $config.PackageDir } }