Created
September 13, 2019 19:19
-
-
Save andrewgrant/b117afd918e1cc5cfa236145829b0ab0 to your computer and use it in GitHub Desktop.
Example of using Gauntlet in Unreal to deploy builds to devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AutomationTool; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using UnrealBuildTool; | |
namespace Gauntlet.Examples | |
{ | |
[Help("An example of using Gauntlet classes to install a build on one or more devices ")] | |
[Help("platform=<plat>", "Platform for these builds and devices")] | |
[Help("path=<path>", "Path to a folder with a build, or a folder that contains platform folders with builds in (e.g. /Saved/StagedBuilds)")] | |
[Help("devices=<device1,device2>", "Devices to install on. If empty uses the default device for this machine")] | |
[Help("configuration=<config>", "Configuration to install/launch. Defaults to development")] | |
[Help("run", "Launch the build after installing")] | |
public class GauntletInstall : BuildCommand | |
{ | |
public override ExitCode Execute() | |
{ | |
string DeviceArg = ParseParamValue("devices", ""); | |
string Project = ParseParamValue("project", ""); | |
string Path = ParseParamValue("path", null); | |
string PlatformArg = ParseParamValue("platform", null); | |
string ConfigArg = ParseParamValue("configuration", "Development"); | |
bool Run = ParseParam("run"); | |
if (string.IsNullOrEmpty(Path) || !Directory.Exists(Path)) | |
{ | |
throw new AutomationException("-path not specified or not found"); | |
} | |
UnrealTargetPlatform Platform = UnrealTargetPlatform.Parse(PlatformArg); | |
UnrealTargetConfiguration Configuration = (UnrealTargetConfiguration)Enum.Parse(typeof(UnrealTargetConfiguration), ConfigArg, true); | |
string[] DeviceList = DeviceArg.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); | |
if (DeviceList.Length == 0) | |
{ | |
DeviceList = new string[] { "" }; | |
} | |
// Create a device factory for this platform | |
IDeviceFactory Factory = Gauntlet.Utils.InterfaceHelpers.FindImplementations<IDeviceFactory>().Where(F => F.CanSupportPlatform(Platform)).FirstOrDefault(); | |
if (Factory == null) | |
{ | |
throw new AutomationException("No factory implemented for platform {0}", Platform); | |
} | |
// Find sources for this platform (note some platforms have multiple sources for staged builds, packaged builds etc | |
IEnumerable<IFolderBuildSource> BuildSources = Gauntlet.Utils.InterfaceHelpers.FindImplementations<IFolderBuildSource>().Where(S => S.CanSupportPlatform(Platform)); | |
// Find all builds at the specified path | |
IBuild Build = BuildSources.SelectMany(S => S.GetBuildsAtPath(Project, Path)).FirstOrDefault(); | |
if (Build == null) | |
{ | |
throw new AutomationException("No builds for platform {0} found at {1}", Platform, Path); | |
} | |
UnrealAppConfig Config = new UnrealAppConfig(); | |
Config.Build = Build; | |
Config.ProjectName = Project; | |
Config.Configuration = Configuration; | |
// now create the devices and ask them to install the build above | |
foreach ( string DeviceName in DeviceList) | |
{ | |
ITargetDevice Device = Factory.CreateDevice(DeviceName, ""); | |
if (Device == null) | |
{ | |
throw new AutomationException("Failed to create device for platform {0} with reference {1}", Platform, DeviceName); | |
} | |
// This will throw() and errors | |
IAppInstall Install = Device.InstallApplication(Config); | |
if (Run) | |
{ | |
Device.Run(Install); | |
} | |
} | |
return ExitCode.Success; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment